tools/direnv: consult direnv less frequently

By checking on doom-switch-{buffer,window}-hook and focus-in-hook, which
fires a lot less often than post-command-hook.
This commit is contained in:
Henrik Lissner 2019-07-08 21:23:49 +02:00
parent c5cd29ef74
commit 17bd6e43c6
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -3,5 +3,15 @@
(def-package! direnv
:after-call (after-find-file dired-initial-position-hook)
:config
(defun +direnv|init ()
"Instead of checking for direnv on `post-command-hook', check on
buffer/window/frame switch, which is less expensive."
(direnv--disable)
(when direnv-mode
(add-hook 'doom-switch-buffer-hook #'direnv--maybe-update-environment)
(add-hook 'doom-switch-window-hook #'direnv--maybe-update-environment)
(add-hook 'focus-in-hook #'direnv--maybe-update-environment)))
(add-hook 'direnv-mode-hook #'+direnv|init)
(when (executable-find "direnv")
(direnv-mode +1)))