How can I move php-mode settings from .emacs to .dir-locals.el?
Asked Answered
R

1

8

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

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

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

What is wrong here?

Radicalism answered 7/9, 2011 at 13:22 Comment(0)
I
15

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 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.

Incipit answered 7/9, 2011 at 21:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.