@@ -88,6 +88,11 @@ Experienced users can set this to a nil value and then include the
8888 :group 'envrc
8989 :type 'boolean )
9090
91+ (defcustom envrc-async-prompt-before-kill t
92+ " Whether or not to prompt the user before killing running envrc processes."
93+ :group 'envrc
94+ :type 'boolean )
95+
9196(defcustom envrc-status-frames '(" = " " == " " ===" " ==" " =" " " )
9297 " List of frames for the spinner."
9398 :group 'envrc
@@ -509,7 +514,11 @@ CALLBACK the function which will get the return value."
509514 (goto-char (point-max ))
510515 (add-face-text-property initial-pos (point ) (if (eq 0 exit-code) 'success 'error )))
511516 (insert " \n\n " )
512- (when (and (numberp exit-code) (/= 0 exit-code))
517+ ; ; Since the async processing interface allows the user to
518+ ; ; interactively kill the process, do not popup the buffer
519+ ; ; when `envrc-async-processing' is true.
520+ (when (and (numberp exit-code) (and (/= 0 exit-code)
521+ (/= 9 exit-code)))
513522 (display-buffer (current-buffer )))))
514523 (kill-buffer stdout)
515524 (kill-buffer stderr)
@@ -719,10 +728,21 @@ SENTINEL, OUT-BUF, ERR-BUF and ARGS are the respective keywords of
719728 (when envrc-add-to-mode-line-misc-info
720729 (envrc-status-start))))))
721730
731+ (defun envrc--kill-running-prompt (env-dir )
732+ " Prompt user to kill any process loading the environment of ENV-DIR."
733+ (when-let* ((proc (alist-get 'process (gethash env-dir envrc--processes)))
734+ (kill (if envrc-async-prompt-before-kill
735+ (yes-or-no-p (format " Process %s is loading the environment, kill it? " proc))
736+ t )))
737+ (kill-process proc)
738+ (while (alist-get 'process (gethash env-dir envrc--processes))
739+ (sleep-for 0.1 ))))
740+
722741(defun envrc-reload ()
723742 " Reload the current env."
724743 (interactive )
725744 (envrc--with-required-current-env env-dir
745+ (envrc--kill-running-prompt env-dir)
726746 (let* ((default-directory env-dir)
727747 (exit-code (envrc--call-process-with-global-env envrc-direnv-executable nil (get-buffer-create " *envrc-reload*" ) nil " reload" )))
728748 (if (zerop exit-code)
@@ -743,6 +763,7 @@ Display MSG in debug buffer if `envrc-debug' is non-nil."
743763 " Run \" direnv allow\" in the current env."
744764 (interactive )
745765 (envrc--with-required-current-env env-dir
766+ (envrc--kill-running-prompt env-dir)
746767 (let* ((default-directory env-dir)
747768 (exit-code (envrc--call-process-with-global-env envrc-direnv-executable nil (get-buffer-create " *envrc-allow*" ) nil " allow" )))
748769 (if (zerop exit-code)
@@ -754,8 +775,7 @@ Display MSG in debug buffer if `envrc-debug' is non-nil."
754775 " Run \" direnv deny\" in the current env."
755776 (interactive )
756777 (envrc--with-required-current-env env-dir
757- (when-let ((proc (alist-get 'process (gethash env-dir envrc--processes))))
758- (kill-process proc)) ; Kill running async load process.
778+ (envrc--kill-running-prompt env-dir)
759779 (let* ((default-directory env-dir)
760780 (exit-code (envrc--call-process-with-global-env envrc-direnv-executable nil (get-buffer-create " *envrc-deny*" ) nil " deny" )))
761781 (if (zerop exit-code)
0 commit comments