可能重复:
How can I move php-mode settings from .emacs to .dir-locals.el?
在Emacs中,可以设置一个文件,以便在打开任意代码时(当然在提示用户之后)通过在文件末尾的局部变量部分中添加以下内容来评估任意代码:
;; Local Variables:
;; eval: (message "This is evaluated when the file is opened in emacs.")
;; End:
Emacs还具有将变量放入名为.dir-locals.el
的文件中的功能,并将这些变量应用于目录中的任何文件。但是,此文件似乎不支持任意代码的评估。有没有办法在目录级别执行此操作?
答案 0 :(得分:5)
对于记录,答案是您执行与文件局部变量相同的操作:分配给伪变量eval
。例如,要将我的示例添加为dir-local eval,只需从相关目录中执行以下操作:(add-dir-local-variable nil 'eval '(message "This is evaluated when any file in this directory is opened in emacs."))