Skip to content

Commit

Permalink
use both post-command-hook and before-hack-local-variables-hook (#54)
Browse files Browse the repository at this point in the history
...when direnv-mode is used. this should cause direnv to load earlier
which can avoid certain issues when opening a file in a direnv
controlled directory for the first time. see #17.
  • Loading branch information
wbolster authored May 21, 2020
1 parent 1daf479 commit 7e6d8fe
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions direnv.el
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
(defvar direnv--active-directory nil
"Name of the directory for which direnv has most recently ran.")

(defvar direnv--hooks '(post-command-hook before-hack-local-variables-hook)
"Hooks that ‘direnv-mode’ should hook into.")

(defcustom direnv-always-show-summary t
"Whether to show a summary message of environment changes on every change.
Expand Down Expand Up @@ -128,12 +131,14 @@ instead of

(defun direnv--enable ()
"Enable direnv mode."
(add-hook 'post-command-hook #'direnv--maybe-update-environment)
(--each direnv--hooks
(add-hook it #'direnv--maybe-update-environment))
(direnv--maybe-update-environment))

(defun direnv--disable ()
"Disable direnv mode."
(remove-hook 'post-command-hook #'direnv--maybe-update-environment))
(--each direnv--hooks
(remove-hook it #'direnv--maybe-update-environment)))

(defun direnv--maybe-update-environment ()
"Maybe update the environment."
Expand Down

0 comments on commit 7e6d8fe

Please sign in to comment.