Using Directory Local Variables

I’ve written before about directory local variables (1, 2) and how they can be useful for setting variables or actions with a directory-wide scope. Over at the Emacs reddit, fearbedragons has a nice tip that leverages them to slightly reduce his workflow friction.

Fearbedragons has a project in which he needs to make a lot of small compiles as he goes about his testing. To help with that he set up a small .dir-locals.el file in the project directory that automatically compiles the whole directory when any file is saved. You may or may not want to do that for your own projects but the same idea works for any action that you want to take on a file event. As fearbedragons says, “You don’t always need it, but it’s sure handy when you do.”

This post is already longer than fearbedragons’ whole tip so stop reading here and go on over to reddit to take a look at the tip. It’s also worthwhile to follow his link to the dir-locals documentation to see how things work. The syntax can be a bit confusing but, as usual, Emacs can help you out by writing the entries for you. Just call add-dir-local-variable and follow the prompts. This is a useful facility that I, at least, do not use nearly enough.

This entry was posted in General and tagged . Bookmark the permalink.