9

Possible Duplicate:
How can I move php-mode settings from .emacs to .dir-locals.el?

In Emacs, one can set up a file to eval arbitrary code when it is opened (after prompting the user, of course) by putting something like the following in the local variables section at the end of the file:

;; Local Variables:
;; eval: (message "This is evaluated when the file is opened in emacs.")
;; End:

Emacs also has a feature for putting variables in a file called .dir-locals.el, and having those variables apply to any file in the directory. However, this file does not seem to support evaluation of arbitrary code. Is there a way to do this at the directory level?

Community
  • 1
  • 1
Ryan C. Thompson
  • 40,856
  • 28
  • 97
  • 159
  • 1
    In a way, this is a better question for that answer; but that answer certainly does resolve this. I'm a bit confused that you've marked this as a duplicate yourself; is the intention just to close this as a duplicate, and have it act as a pointer to the other Q&A? – phils Feb 23 '12 at 21:03
  • I only found the duplicate after asking the question, since the duplicate question is not obviously a dupe just by the title alone. – Ryan C. Thompson Feb 23 '12 at 23:18
  • 1
    I think this is a case where a closed post should act as a signpost. The other question is very similar, but merging would not really be appropriate. – pmr Feb 25 '12 at 00:05

1 Answers1

5

For the record, the answer is that you do the same thing as in file-local variables: assign to the fake variable eval. For example, to add my example as a dir-local eval, just do the following from the directory in question: (add-dir-local-variable nil 'eval '(message "This is evaluated when any file in this directory is opened in emacs."))

Ryan C. Thompson
  • 40,856
  • 28
  • 97
  • 159