From: David Bremner <[email protected]>

This enables fast navigation between hunks and better highlighting.

The use of notmuch-get-bodypart-internal could be improved; hard
coding to 1 seems to work for the output of git-format-patch. It also
not so nice to call (insert (notmuch-get-bodypart-internal ...)) since the
last thing n-g-b-i does is call buffer-string.
---

The main thing that worries me is the use of
notmuch-get-bodypart-internal.  Do we have a canonical way to get the
message body?  It would also be nice to have "q" actually kill the
buffer, but I didn't find a clean way to do that.

 emacs/notmuch-show.el |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 20f8997..442e6ce 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1694,6 +1694,22 @@ to show, nil otherwise."
     (set-buffer-modified-p nil)
     (view-buffer buf 'kill-buffer-if-not-modified)))

+(defun notmuch-show-view-as-patch ()
+  "View the the current message as a patch."
+  (interactive)
+  (let* ((id (notmuch-show-get-message-id))
+        (subject (concat "Subject: " (notmuch-show-get-subject) "\n"))
+        (diff-default-read-only t)
+        (buf (get-buffer-create (concat "*notmuch-patch-" id "*"))))
+    (switch-to-buffer buf)
+    (let ((inhibit-read-only t))
+      (erase-buffer)
+      (insert subject)
+      (insert (notmuch-get-bodypart-internal id 1 nil)))
+    (set-buffer-modified-p nil)
+    (diff-mode)
+    (goto-char (point-min))))
+
 (defun notmuch-show-pipe-message (entire-thread command)
   "Pipe the contents of the current message (or thread) to the given command.

-- 
1.7.10.4

Reply via email to