From: Mark Walters Date: Sun, 4 May 2014 08:39:35 +0000 (+0100) Subject: emacstips: add sample code for viewing patches in diff-mode X-Git-Url: https://git.cworth.org/git?p=notmuch-wiki;a=commitdiff_plain;h=ac053aadb3be86f206612b19868eaa08350bb8dd emacstips: add sample code for viewing patches in diff-mode --- diff --git a/emacstips.mdwn b/emacstips.mdwn index a90911c..3a1a3dd 100644 --- a/emacstips.mdwn +++ b/emacstips.mdwn @@ -765,3 +765,33 @@ Then In general it is nice to have a key for org-links (not just for notmuch). For example (define-key global-map "\C-cl" 'org-store-link) + +## Viewing diffs in notmuch + +The following code allows you to view an inline patch in diff-mode +directly from notmuch. This means that normal diff-mode commands like +refine, next hunk etc all work. + + (defun my-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 "*"))) + (map (make-sparse-keymap))) + (define-key map "q" 'notmuch-kill-this-buffer) + (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) + (lexical-let ((new-ro-bind (cons 'buffer-read-only map))) + (add-to-list 'minor-mode-overriding-map-alist new-ro-bind)) + (goto-char (point-min)))) + +and then this function needs to bound into the keymap with something like + + (define-key 'notmuch-show-mode-map "D" 'my-notmuch-show-view-as-patch)