We can specify modes :

(c-mode . ((c-file-style . "BSD")
            (subdirs . nil)))

Or directories :

       . ((nil . ((change-log-default-name . "ChangeLog.local")))))

Is there a way to specify a regexp matching files (or even directories) ? i.e:

(".*_test.go" . . ((nil . ((change-log-default-name . "ChangeLog.local")))))
  • 3
    Maybe consider filing an Emacs enhancement request: M-x report-emacs-bug.
    – Drew
    Jan 17 '20 at 16:58
  • 1
    Not quite a duplicate, but cross-referencing with emacs.stackexchange.com/q/62136/454
    – phils
    Dec 6 '20 at 9:27

The capabilities are documented at C-hig (emacs)Directory Variables

What you've asked for isn't supported; so no, you can't have regexps matching files or directories.


Is there any reason you can't simply do the regexp yourself in a .dir-locals assignment? eg just pasted from another exercise the assignment of fname could be based on a regexp matching the buffer-file-name

((nil . ((eval . (progn
                   (setq boilerplate (with-temp-buffer
                                        (insert-file-contents ".boilerplate")
                   (setq fname (buffer-file-name)) ; <--- do something with a regexp here to match the filename for type eg *.c etc.
  • Be careful using setq (as opposed to setq-local) in a dir-local eval form. If the variable in question isn't buffer-local then you're setting its global value.
    – phils
    Feb 17 '20 at 0:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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