Rudy’s OBTF Rudolf Adamkovič

Home / Emacs


.dir-locals file

A file that sets Emacs variables when editing the files in the containing directory or any of its subdirectories recursively.

The file contains a list of pairs in the form

(PAIR...)

where each PAIR either customizes a given major mode in any subdirectory

(MAJOR-MODE . ((VARIABLE-NAME . VARIABLE-VALUE)...))

or it customizes a given major mode in a specific subdirectory

(SUBDIRECTORY . ((MAJOR-MODE . ((VARIABLE-NAME . VARIABLE-VALUE)...))...))

Two common special cases exist:

  • If the MAJOR-MODE key equals nil, then the PAIR applies to all major modes.
  • If the VARIABLE-NAME key equals eval, then the VARIABLE-VALUE evaluates as executable code.

Explore!

Write a .dir-locals file that makes the project-compile command execute Make in the core subdirectory for all files in that subdirectory.

(("core" . ((nil . ((compile-command . "make -C core "))))))

© 2025 Rudolf Adamkovič under GNU General Public License version 3.
Made with Emacs and secret alien technologies of yesteryear.