unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] emacs: View the output of pipe command when it fails
@ 2011-01-23 10:45 Michal Sojka
  2011-01-26 12:43 ` Carl Worth
  0 siblings, 1 reply; 2+ messages in thread
From: Michal Sojka @ 2011-01-23 10:45 UTC (permalink / raw)
  To: notmuch

Previously, the user didn't know whether the pipe command succeeded or
not. It was only possible to find it out by manually inspecting
the work done (or not done) by the command or by manually switching to
*notmuch-pipe* buffer and determine it from command output. For this
the user had to first find the text corresponding to the last run of
pipe command as the buffer accumulated the output from all pipe commands.

This patch changes the following. The *notmuch-pipe* buffer is erased
before every pipe command so it contains only the output from the last
command. Additionally, when the command failed, the *notmuch-pipe* buffer
is shown and an error message is displayed.
with the output of pipe command.
---
 emacs/notmuch-show.el |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 3a60d43..f3150af 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -948,7 +948,7 @@ any effects from previous calls to
 
 The given command will be executed with the raw contents of the
 current email message as stdin. Anything printed by the command
-to stdout or stderr will appear in the *Messages* buffer.
+to stdout or stderr will appear in the *notmuch-pipe* buffer.
 
 When invoked with a prefix argument, the command will receive all
 open messages in the current thread (formatted as an mbox) rather
@@ -964,7 +964,18 @@ than only the current message."
       (setq shell-command
 	    (concat notmuch-command " show --format=raw "
 		    (shell-quote-argument (notmuch-show-get-message-id)) " | " command)))
-    (start-process-shell-command "notmuch-pipe-command" "*notmuch-pipe*" shell-command)))
+    (let ((buf (get-buffer-create (concat "*notmuch-pipe*"))))
+      (with-current-buffer buf
+	(setq buffer-read-only nil)
+	(erase-buffer)
+	(let ((exit-code (call-process-shell-command shell-command nil buf)))
+	  (goto-char (point-max))
+	  (set-buffer-modified-p nil)
+	  (setq buffer-read-only t)
+	  (unless (zerop exit-code)
+	    (switch-to-buffer-other-window buf)
+	    (message (format "Command '%s' exited abnormally with code %d"
+			     shell-command exit-code))))))))
 
 (defun notmuch-show-add-tags-worker (current-tags add-tags)
   "Add to `current-tags' with any tags from `add-tags' not
-- 
1.7.2.3

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] emacs: View the output of pipe command when it fails
  2011-01-23 10:45 [PATCH] emacs: View the output of pipe command when it fails Michal Sojka
@ 2011-01-26 12:43 ` Carl Worth
  0 siblings, 0 replies; 2+ messages in thread
From: Carl Worth @ 2011-01-26 12:43 UTC (permalink / raw)
  To: Michal Sojka, notmuch

[-- Attachment #1: Type: text/plain, Size: 592 bytes --]

On Sun, 23 Jan 2011 11:45:50 +0100, Michal Sojka <sojkam1@fel.cvut.cz> wrote:
> This patch changes the following. The *notmuch-pipe* buffer is erased
> before every pipe command so it contains only the output from the last
> command. Additionally, when the command failed, the *notmuch-pipe* buffer
> is shown and an error message is displayed.
> with the output of pipe command.

Hurrah, hurrah! I've wanted this for such a long time. And it's
especially handy for the patch-merging binge I'm on right now.

Thanks so much. This is pushed.

-Carl

-- 
carl.d.worth@intel.com

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-01-26 12:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-23 10:45 [PATCH] emacs: View the output of pipe command when it fails Michal Sojka
2011-01-26 12:43 ` Carl Worth

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).