在Emacs中,如何将目录本地变量用于远程项目?

| 我正在使用TRAMP连接到远程服务器,我想使用一些目录局部变量。我有什么选择?我应该使用emacs-server并以这种方式进行操作,还是应该将目录本地变量添加到我的.emacs文件中?有没有办法强制TRAMP查找.dir-locals.el文件?     
已邀请:
对于Emacs 24.3或更高版本,请参见legoscia的答案。 对于早期版本,可以使用EmacsWiki中的以下解决方法:   如果您有任何问题,我们可以建议
‘hack-dir-local-variables’
解决此问题   愿意承担相关的性能成本(可以是   在某些情况下相对较小)。      
;; 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)
如果使用目录类而不是
.dir-locals.el
文件,则应使用常规的流水线路径设置类。例如。:
 (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)
    
如果您使用的是Emacs 24.3或更高版本,请将
enable-remote-dir-locals
设置为t。     

要回复问题请先登录注册