如何将 php-mode 设置从 .emacs 移动到 .dir-locals.el? [英] How can I move php-mode settings from .emacs to .dir-locals.el?

查看:13
本文介绍了如何将 php-mode 设置从 .emacs 移动到 .dir-locals.el?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的 .emacs 文件中的内容.

Here is the content from my .emacs file.

(add-hook 'php-mode-hook
        (lambda ()
        (c-set-style "bsd")
        (setq indent-tabs-mode t)
        (setq c-basic-offset 4)
        (setq tab-width 4)
        (c-set-offset 'arglist-close 'c-lineup-arglist-operators)
        (c-set-offset 'arglist-intro '+)
        (c-set-offset 'arglist-cont-nonempty 'c-lineup-math)
        (c-set-offset 'case-label '+)       
        ))

我想将这些格式设置移动到项目特定的目录中.虽然我可以轻松地为 setq 语句(例如 (setq indent-tabs-mode t))做到这一点,但我无法为如下函数调用做到这一点:(c-set-offset 'arglist-intro '+).

I want to move these formatting settings to the project specific directory. Although I can do it easily for setq statements (e.g. (setq indent-tabs-mode t)), I am not able to do it for function calls like: (c-set-offset 'arglist-intro '+).

这是我放入 .dir-locals.el 的内容:

Here is what I have put into my .dir-locals.el:

;;; Directory Local Variables
;;; See Info node `(emacs) Directory Variables' for more information.

    ((php-mode
        (c-set-style "bsd")
        (indent-tabs-mode . t)
        (c-basic-offset . 4)
        (tab-width . 4)
        (c-set-offset 'arglist-close 'c-lineup-arglist-operators)
        (c-set-offset 'arglist-intro 'c-basic-offset)
        (c-set-offset 'arglist-cont-nonempty 'c-lineup-math)
        (c-set-offset 'case-label '+)       
      ))

这里出了什么问题?

推荐答案

目录局部变量就是——变量;不是要评估的 elisp 表格.幸运的是,这是通过 eval 伪变量提供的:

Directory local variables are just that -- variables; not elisp forms to be evaluated. Fortunately, that is provided for via the eval pseudo-variable:

((php-mode
  (indent-tabs-mode . t)
  (c-basic-offset . 4)
  (tab-width . 4)
  (eval . (progn
            (c-set-style "bsd")
            (c-set-offset 'arglist-close 'c-lineup-arglist-operators)
            (c-set-offset 'arglist-intro 'c-basic-offset)
            (c-set-offset 'arglist-cont-nonempty 'c-lineup-math)
            (c-set-offset 'case-label '+)))))

Emacs 遇到时会要求你确认代码是否安全,并将其保存到 custom-set-variables 中的 safe-local-variable-values 列表中 init 文件的部分(如果您愿意).

Emacs will ask you to confirm that the code is safe when it encounters it, and will save it to the safe-local-variable-values list in the custom-set-variables sections of your init file if you wish.

这篇关于如何将 php-mode 设置从 .emacs 移动到 .dir-locals.el?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆