In Emacs, how do I use directory local variables for remote projects?

和自甴很熟 提交于 2019-12-09 18:03:05

问题


I'm using TRAMP to connect to a remote server and I wanted to use some directory local variables. What are my options? Should I use emacs-server and do it that way, or should I add the directory local variables to my .emacs file? Is there a way to force TRAMP to look for the .dir-locals.el file?


回答1:


For Emacs 24.3 or later, see legoscia's answer.

For earlier versions, you can use the following workaround from EmacsWiki:

We can advise ‘hack-dir-local-variables’ to work around this, if you are willing to incur the associated performance cost (which can be relatively minimal in some situations).

;; Enable directory local variables with remote files. This facilitates both
;; the (dir-locals-set-class-variables ...)(dir-locals-set-directory-class ...)
;; and the .dir-locals.el approaches.
(defadvice hack-dir-local-variables (around my-remote-dir-local-variables)
  "Allow directory local variables with remote files, by temporarily redefining
`file-remote-p' to return nil unconditionally."
  (flet ((file-remote-p (&rest) nil))
  ad-do-it))
(ad-activate 'hack-dir-local-variables)

If using directory classes instead of a .dir-locals.el file, you would set the class using a normal tramp path. e.g.:

 (dir-locals-set-class-variables
  'read-only
  '((nil . ((buffer-read-only . t)))))

 (dir-locals-set-directory-class
  "/ssh:(user)@(host):/path/to/dir" 'read-only)



回答2:


If you're using Emacs 24.3 or later, set enable-remote-dir-locals to t.



来源:https://stackoverflow.com/questions/5654456/in-emacs-how-do-i-use-directory-local-variables-for-remote-projects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!