2011-09-07 16 views
7

以下是我的.emacs文件中的内容。如何将.php模式设置从.emacs移动到.dir-locals.el?

(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:

;;; 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 '+)  
    )) 

这里有什么问题?

回答

10

目录局部变量就是 - 变量;不是要评估的elisp表单。幸运的是,通过eval伪变量提供:

((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会要求您确认该代码是安全的,当它遇到它,将它保存到safe-local-variable-values列表中的custom-set-variables部分的init文件,如果你愿意。