0

I have a custom config for a project which I would like to load whenever emacs is started from project's root directory. The custom config lies in path/to/project/emacs.d/custom-init.el. I have also added the following code to .dir-locals.el so the the loading is automatically added to the users init.el.

((nil . ((eval . ((lambda ()
                          (let ((init-file-path (expand-file-name "emacs.d/custom-init.el" default-directory)))
                            (when (file-exists-p init-file-path)
                              (load init-file-path)
                              (require 'project-name)))))))))

The problem is the custom config only gets loaded when I enter for example dired in a subfolder of the project and not just when I start emacs from the root directory of the project.

  • 1
    Dir-local vars are generally applied only to file-visiting buffers. Other buffer types must be handled specially. dired-mode calls hack-dir-local-variables-non-file-buffer, for instance. – phils Apr 6 at 11:26

Your Answer

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

Browse other questions tagged or ask your own question.