Re: [PATCH] emacs/show: add command to view a patch using diff mode

Subject: Re: [PATCH] emacs/show: add command to view a patch using diff mode

Date: Sun, 22 Jun 2014 07:51:09 -0300

To: Mark Walters, notmuch@notmuchmail.org

Cc:

From: David Bremner


Mark Walters <markwalters1009@gmail.com> writes:

> From: markwalters1009@gmail.com
>
> 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.
>
> Author: David Bremner <bremner@debian.org>

Recently I had cause to update this function to produce more
"git-format-patch" like output. I didn't yet merge with Mark's proposed
changes. Here it is in case anyone else finds this useful (I used it to
de-quoted-printable a patch).

(defun notmuch-show-view-as-patch ()
  "View the the current message as a patch."
  (interactive)
  (let* ((id (notmuch-show-get-message-id t))
	 (date (notmuch-show-get-date))
	 (from_ (concat "From " id " " date "\n"))
	 (from: (concat "From: " (notmuch-show-get-from) "\n"))
	 (date: (concat "Date: " date "\n"))
	 (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 from_)
      (insert from:)
      (insert date:)
      (insert subject)
      (insert "\n")
      (insert (notmuch-get-bodypart-internal (concat "id:" id) 1 nil)))
    (set-buffer-modified-p nil)
    (diff-mode)
    (goto-char (point-min))))

Thread: