When collaborating on a project, certain editing variables are set to make sure everyone is producing a similar style of code. In Emacs, these are usually implemented as either file-local variables or directory-local variables.

File-local variables are best when you want to keep the variable's value attached to the file itself, but they get cumbersome when it is the same variable over and over again for every file in the project.

Using a directory-local variable would be the obvious choice, but I'm personally using this to set the email I use in the project (as opposed to my work email, etc.) to make sure I'm never inconsistent with my commit data.

Is there a way around this problem? Can I have two files holding directory-local variables in the same directory (one personal file and one version-controlled file)?

Refer: sx.el@3a5afcc

2 Answers 2


As of I think version 26.1, Emacs does support a second additional .dir-locals.el file (aptly named .dir-locals-2.el).

From the Emacs Manual: "Per-Directory Local Variables":

You can also use .dir-locals-2.el; if found, Emacs loads it in addition to .dir-locals.el. This is useful when .dir-locals.el is under version control in a shared repository and can't be used for personal customizations.

  • Changing the accepted answer since this should be the recommendation going forward. Thanks for adding it here! Jun 4, 2019 at 13:58
  • Interesting note: The documentation states that Emacs loads .dir-locals-2.el in addition to .dir-locals.el, but it seems the actual behavior is to load it instead of .dir-locals.el (at least on Emacs 26.2).
    – 0x5453
    Jul 1, 2019 at 19:46

This seems to work:

(defadvice hack-dir-local-variables (around second-dir-locals-file activate)
  (let ((dir-locals-file ".alt-dir-locals.el"))
  • Will this apply both .dir-locals.el and .alt-dir-locals.el in that order? Dec 10, 2014 at 21:21
  • It does, according to my simple testing.
    – Sean
    Dec 10, 2014 at 21:35
  • Sweet! I'll try this out tomorrow :) Dec 11, 2014 at 0:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.