From d29a601b655ce52f30d5146b283a6512468f023e Mon Sep 17 00:00:00 2001 From: Ade Attwood Date: Tue, 15 Feb 2022 20:47:31 +0000 Subject: [PATCH] feat(emacs): add command for extracting a patch from emails --- site-modules/core/files/emacs/src/notmuch.el | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/site-modules/core/files/emacs/src/notmuch.el b/site-modules/core/files/emacs/src/notmuch.el index 34da5a9..bbaf1b3 100644 --- a/site-modules/core/files/emacs/src/notmuch.el +++ b/site-modules/core/files/emacs/src/notmuch.el @@ -120,3 +120,27 @@ :type "notmuch" :link link :description description))))) + +;; https://notmuchmail.org/emacstips +;; Viewing diffs in notmuch +(defun aa/notmuch-show-view-as-patch () + "View the the current message as a patch." + (interactive) + (let* ((id (notmuch-show-get-message-id)) + (msg (notmuch-show-get-message-properties)) + (part (notmuch-show-get-part-properties)) + (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-bury-or-kill-this-buffer) + (switch-to-buffer buf) + (let ((inhibit-read-only t)) + (erase-buffer) + (insert subject) + (insert (notmuch-get-bodypart-text msg part 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))))