From 7e6d8fec2dcc8fffcd0df731ab57670127e13361 Mon Sep 17 00:00:00 2001 From: wouter bolsterlee Date: Thu, 21 May 2020 21:34:08 +0200 Subject: [PATCH] use both post-command-hook and before-hack-local-variables-hook (#54) ...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. --- direnv.el | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/direnv.el b/direnv.el index 908e31c..039565c 100644 --- a/direnv.el +++ b/direnv.el @@ -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. @@ -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."