2

I'm currently attempting to call the function company-org-roam--init-hook from org-mode-hook in order to enable the company-org-roam backend in org-roam buffers. In some of the files in which this hook is called, I've used a .dir-locals.el file to set org-roam-directory to a non-default value. However, when company-org-roam--init-hook is called while loading the file, it appears that org-roam-directory isn't set to its dir-local value, causing the hook not to enable the Company backend.

Is it expected that dir-local variables are applied only after major-mode hooks are run? If so, is there a way to work around this (besides a run-at-time)?

2

Is it expected that dir-local variables are applied only after major-mode hooks are run?

Yes. The local variables are normally processed in run-mode-hooks, after running the mode hooks and before running after-change-major-mode-hook.

You could use the latter to deal with your problem. Alternatively you can use hack-local-variables-hook which runs after the local variables have been processed -- refer to How can I access directory-local variables in my major mode hooks?

n.b. How and when file- and dir-local variables are processed changed in Emacs 26.1, and the linked S.O. Q&A pre-dates that change. I don't believe it affects your question, but the implementation details were different.

| improve this answer | |
  • In retrospect, the after-change-major-mode-hook approach wouldn't work in old Emacs versions; that hook is only an option (for the purposes of this question) from 26.1 onwards. Using hack-local-variables-hook will work for all versions. – phils Apr 24 at 8:15

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.