[PATCH v1 3/3] emacs: Add `notmuch-show-save-message' to save messages

David Edmondson dme at dme.org
Fri May 9 01:22:23 PDT 2014


Following `notmuch-show-pipe-message', add a binding 'S' to save
either the current or all open messages, depending on prefix argument.
---
 emacs/notmuch-show.el | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 62c0be6..851e968 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1285,6 +1285,7 @@ reset based on the original query."
     (define-key map "f" 'notmuch-show-forward-message)
     (define-key map "r" 'notmuch-show-reply-sender)
     (define-key map "R" 'notmuch-show-reply)
+    (define-key map "S" 'notmuch-show-save-message)
     (define-key map "|" 'notmuch-show-pipe-message)
     (define-key map "w" 'notmuch-show-save-attachments)
     (define-key map "V" 'notmuch-show-view-raw-message)
@@ -1769,6 +1770,24 @@ to show, nil otherwise."
     (set-buffer-modified-p nil)
     (view-buffer buf 'kill-buffer-if-not-modified)))
 
+(put 'notmuch-show-save-message 'notmuch-doc
+     "Save the contents of the current message to a file.")
+(put 'notmuch-show-save-message 'notmuch-prefix-doc
+     "Save the thread as an mbox to a file.")
+(defun notmuch-show-save-message (entire-thread file)
+  "Save the contents of the current message (or thread) to FILE.
+
+If ENTIRE-THREAD is non-nil (or when invoked with a prefix
+argument), FILE will contain all open messages in the current
+thread (formatted as an mbox) rather than only the current
+message."
+  (interactive (let ((prompt (if current-prefix-arg
+				 "Save all open messages to file: "
+			       "Save message to command: ")))
+		 (list current-prefix-arg (read-file-name prompt))))
+
+  (notmuch-show-pipe-message-internal entire-thread (concat " > " file)))
+
 (put 'notmuch-show-pipe-message 'notmuch-doc
      "Pipe the contents of the current message to a command.")
 (put 'notmuch-show-pipe-message 'notmuch-prefix-doc
@@ -1789,6 +1808,9 @@ message."
 			       "Pipe message to command: ")))
 		 (list current-prefix-arg (read-string prompt))))
 
+  (notmuch-show-pipe-message-internal entire-thread (concat " | " command)))
+
+(defun notmuch-show-pipe-message-internal (entire-thread command-tail)
   (let ((shell-command
 	 (concat notmuch-command " show"
 		 (if entire-thread
@@ -1796,7 +1818,7 @@ message."
 			     (mapconcat #'shell-quote-argument (notmuch-show-get-message-ids-for-open-messages) " OR "))
 		   (concat " --format=raw "
 			   (shell-quote-argument (notmuch-show-get-message-id))))
-		 " | " command))
+		 command-tail))
 	(cwd default-directory)
 	(buf (get-buffer-create (concat "*notmuch-pipe*"))))
     (with-current-buffer buf
-- 
2.0.0.rc0



More information about the notmuch mailing list