7

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

Malabarba
  • 22,878
  • 6
  • 78
  • 163
Sean Allred
  • 6,861
  • 16
  • 85

2 Answers2

7

This seems to work:

(defadvice hack-dir-local-variables (around second-dir-locals-file activate)
  ad-do-it
  (let ((dir-locals-file ".alt-dir-locals.el"))
    ad-do-it))
Sean
  • 929
  • 4
  • 13
4

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.

ebpa
  • 7,319
  • 26
  • 53
  • Changing the accepted answer since this should be the recommendation going forward. Thanks for adding it here! – Sean Allred Jun 04 '19 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 01 '19 at 19:46