purcell / envrc

Emacs support for direnv which operates buffer-locally
377 stars 35 forks source link

Question about other buffer local variables #55

Open dschrempf opened 1 year ago

dschrempf commented 1 year ago

Hi!

I wanted to ask if it is also (easily?) possible to set other variables in Emacs depending on the local environment with envrc. For example, when using different versions of the jdtls language server in Java, the corresponding minor mode lsp-java needs to know about the installation directories via lsp-java-server-install-dir, which differ for different versions of the language server.

At the moment, I use directory-local environment variables and a "set the variable in the major mode hook", e.g.,

   (after! cc-mode
     (defun my-set-lsp-path ()
       (setq lsp-java-server-install-dir (getenv "JDTLS_PATH")))
     (add-hook 'java-mode-hook #'my-set-lsp-path))

That leads to problems when the environment changes. Of course, it would be much easier to tell envrc to set lsp-java-server-install-dir along with the exec-path. Then, I could just use envrc-reload to update the environment, like I usually to with exec-path.

Thanks!

purcell commented 1 year ago

Hmmm, this would perhaps be a good case for adding a buffer-local hook like "envrc-post-update-hook", then you could use it to sync changes from updated env vars into emacs variables, as in your example.