]> git.notmuchmail.org Git - notmuch/commitdiff
emacs: Access raw messages via cat subcommand
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 22 Oct 2010 09:28:04 +0000 (11:28 +0200)
committerCarl Worth <cworth@cworth.org>
Sat, 6 Nov 2010 00:51:18 +0000 (17:51 -0700)
This patch modifies the following commands to access the messages via
cat subcommand:
- view/save attachments ('v', 'w'),
- view a raw message ('V') and
- pipe a message to a command ('|').

With this patch, it is straightforward to use notmuch emacs interface
with a remote database accessed over SSH. To do this, it is sufficient
to redefine notmuch-command variable to contain the name of a script
containing:

    ssh user@host notmuch "$@"

If the ssh client has enabled connection sharing (ControlMaster option
in OpenSSH), the emacs interface is almost as responsive as when
notmuch is invoked locally.

emacs/notmuch-show.el

index 7ec6aa50ce483c7c21ce43a3db0fcfe66278867a..9b3841fffbbbf21233190950b9c11104d762e28a 100644 (file)
@@ -85,10 +85,10 @@ any given message."
 (defmacro with-current-notmuch-show-message (&rest body)
   "Evaluate body with current buffer set to the text of current message"
   `(save-excursion
 (defmacro with-current-notmuch-show-message (&rest body)
   "Evaluate body with current buffer set to the text of current message"
   `(save-excursion
-     (let ((filename (notmuch-show-get-filename)))
-       (let ((buf (generate-new-buffer (concat "*notmuch-msg-" filename "*"))))
+     (let ((id (notmuch-show-get-message-id)))
+       (let ((buf (generate-new-buffer (concat "*notmuch-msg-" id "*"))))
          (with-current-buffer buf
          (with-current-buffer buf
-           (insert-file-contents filename nil nil nil t)
+           (call-process notmuch-command nil t nil "cat" id)
            ,@body)
         (kill-buffer buf)))))
 
            ,@body)
         (kill-buffer buf)))))
 
@@ -917,7 +917,11 @@ any effects from previous calls to
 (defun notmuch-show-view-raw-message ()
   "View the file holding the current message."
   (interactive)
 (defun notmuch-show-view-raw-message ()
   "View the file holding the current message."
   (interactive)
-  (view-file (notmuch-show-get-filename)))
+  (let ((id (notmuch-show-get-message-id)))
+    (let ((buf (get-buffer-create (concat "*notmuch-raw-" id "*"))))
+      (switch-to-buffer buf)
+      (save-excursion
+       (call-process notmuch-command nil t nil "cat" id)))))
 
 (defun notmuch-show-pipe-message (entire-thread command)
   "Pipe the contents of the current message (or thread) to the given command.
 
 (defun notmuch-show-pipe-message (entire-thread command)
   "Pipe the contents of the current message (or thread) to the given command.
@@ -938,7 +942,7 @@ than only the current message."
                       (mapconcat 'identity (notmuch-show-get-message-ids-for-open-messages) " OR "))
                      " | " command))
       (setq shell-command
                       (mapconcat 'identity (notmuch-show-get-message-ids-for-open-messages) " OR "))
                      " | " command))
       (setq shell-command
-           (concat command " < " (shell-quote-argument (notmuch-show-get-filename)))))
+           (concat "notmuch cat " (shell-quote-argument (notmuch-show-get-message-id)) " | " command)))
     (start-process-shell-command "notmuch-pipe-command" "*notmuch-pipe*" shell-command)))
 
 (defun notmuch-show-add-tags-worker (current-tags add-tags)
     (start-process-shell-command "notmuch-pipe-command" "*notmuch-pipe*" shell-command)))
 
 (defun notmuch-show-add-tags-worker (current-tags add-tags)