I have some customizations for emacs that I'd like to use for a single project, but not affect emacs globally. Is there any way I can have emacs load a specific init file when launched from a certain directory or automatically load all init files in the directory its launched from?

up vote 15 down vote accepted

You might want to take a look at Directory variables. Basically you will need to create a .dir-locals.el file in your project root with all the project specific setting in it. Now whenever you open a file in the directory or any of its subdirectories emacs will apply the settings in the .dir-locals.el file.

So for example suppose you want to use the make package install as compile command only in project A, you will need to create a file named .dir-locals.el in root directory of the project and add something like the following

((nil . ((compile-command . "make package install"))))

Henceforth whenever you run compile command from any file under the directory A, the default compile-command will be the one specified above, however the compile command for files outside the directory A will stay untouched.

A less-featured alternative to .dir-locals.el is the EditorConfig standard, which has an emacs-package. It doesn't support nearly as many options, however, it allows a team of people to standardize on some settings and use them across different editors.

It behaves much the same way, with a project-specific .editorconfig file at the top-level.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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