From d0d4d3e3b42273bf6ea37577fdd430e06e147f6d Mon Sep 17 00:00:00 2001 From: Andrew Stribblehill Date: Fri, 3 May 2019 11:02:26 +0200 Subject: [PATCH 1/3] Only parse the stdout from direnv export json (#41) Then, put stderr into *direnv*. Side effect: exit code now only affects the warning message. --- direnv.el | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/direnv.el b/direnv.el index 87f8d2b..410fd6b 100644 --- a/direnv.el +++ b/direnv.el @@ -92,27 +92,26 @@ In these modes, direnv will use `default-directory' instead of (let ((environment process-environment) ;; call-process can only output stderr to file (stderr-tempfile (make-temp-file "direnv-stderr"))) - (unwind-protect (with-current-buffer (get-buffer-create direnv--output-buffer-name) (erase-buffer) (let* ((default-directory directory) (process-environment environment) (exit-code (call-process "direnv" nil `(t ,stderr-tempfile) nil "export" "json"))) - (unless (zerop exit-code) - ; write the stderr messages to the end of our output buffer - (insert-file-contents stderr-tempfile) - ; then fill a temp buffer with the message and display in status bar + (prog1 (unless (zerop (buffer-size)) + (goto-char (point-max)) + (re-search-backward "^{") + (let ((json-key-type 'string)) + (json-read-object))) + (unless (zerop (file-attribute-size (file-attributes stderr-tempfile))) + (unless (zerop (buffer-size)) (insert "\n")) + ;; write the stderr messages to the end of our output buffer + (insert-file-contents stderr-tempfile)) (with-temp-buffer (insert-file-contents stderr-tempfile) - (message "direnv exited %s:\n%s\nOpen hidden buffer \"%s\" for full output" - exit-code (buffer-string) direnv--output-buffer-name))) - (unless (zerop (buffer-size)) - (goto-char (point-max)) - (re-search-backward "^{") - (let ((json-key-type 'string)) - (json-read-object))))) - + (unless (zerop exit-code) + (message "direnv exited %s:\n%s\nOpen buffer \"%s\" for full output" + exit-code (buffer-string) direnv--output-buffer-name)))))) (delete-file stderr-tempfile)))) (defun direnv--enable () From 59576d1aa2e0a94ba98df40e3946a8c2da4238b2 Mon Sep 17 00:00:00 2001 From: wouter bolsterlee Date: Sat, 11 May 2019 18:14:50 +0200 Subject: [PATCH 2/3] emit warnings for direnv errors a normal message will not be visible when switching from a functional direnv directory to another broken one (e.g. unapproved .envrc), since the unloading of the first directory will be shown as a summary instead, causing the problem to go unnoticed. instead, use (warn ...) which will pop up a window instead. --- direnv.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/direnv.el b/direnv.el index 410fd6b..1c96743 100644 --- a/direnv.el +++ b/direnv.el @@ -108,10 +108,10 @@ In these modes, direnv will use `default-directory' instead of ;; write the stderr messages to the end of our output buffer (insert-file-contents stderr-tempfile)) (with-temp-buffer - (insert-file-contents stderr-tempfile) (unless (zerop exit-code) - (message "direnv exited %s:\n%s\nOpen buffer \"%s\" for full output" - exit-code (buffer-string) direnv--output-buffer-name)))))) + (insert-file-contents stderr-tempfile) + (warn "Error running direnv (exit code %d):\n%s\nOpen buffer ā€˜%sā€™ for full output." + exit-code (buffer-string) direnv--output-buffer-name)))))) (delete-file stderr-tempfile)))) (defun direnv--enable () From a32eaaf957ac50a89d05e809ed6efbc8e98b792b Mon Sep 17 00:00:00 2001 From: wouter bolsterlee Date: Sat, 11 May 2019 18:24:50 +0200 Subject: [PATCH 3/3] minor cleanups --- direnv.el | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/direnv.el b/direnv.el index 1c96743..9cd458c 100644 --- a/direnv.el +++ b/direnv.el @@ -90,22 +90,23 @@ In these modes, direnv will use `default-directory' instead of (unless direnv--installed (user-error "Could not find the direnv executable. Is exec-path correct?")) (let ((environment process-environment) - ;; call-process can only output stderr to file - (stderr-tempfile (make-temp-file "direnv-stderr"))) + (stderr-tempfile (make-temp-file "direnv-stderr"))) ;; call-process needs a file for stderr output (unwind-protect (with-current-buffer (get-buffer-create direnv--output-buffer-name) (erase-buffer) (let* ((default-directory directory) (process-environment environment) - (exit-code (call-process "direnv" nil `(t ,stderr-tempfile) nil "export" "json"))) - (prog1 (unless (zerop (buffer-size)) - (goto-char (point-max)) - (re-search-backward "^{") - (let ((json-key-type 'string)) - (json-read-object))) + (exit-code (call-process "direnv" nil `(t ,stderr-tempfile) nil "export" "json")) + (json-key-type 'string)) + (prog1 + (unless (zerop (buffer-size)) + (goto-char (point-max)) + (re-search-backward "^{") + (json-read-object)) (unless (zerop (file-attribute-size (file-attributes stderr-tempfile))) - (unless (zerop (buffer-size)) (insert "\n")) - ;; write the stderr messages to the end of our output buffer + (goto-char (point-max)) + (unless (zerop (buffer-size)) + (insert "\n\n")) (insert-file-contents stderr-tempfile)) (with-temp-buffer (unless (zerop exit-code)