这是我的.emacs文件中的内容.
@H_403_1@(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’).
这是我放入.dir-locals.el的内容:
@H_403_1@;;; 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伪变量提供的:
@H_403_1@((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会要求您确认代码是否安全,如果您愿意,它会将其保存到init文件的custom-set-variables部分的safe-local-variable-values列表中.