mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-21 18:38:08 +01:00
emacs/notmuch-wash.el: Add `notmuch-wash-convert-inline-patch-to-part'.
Detect inline patches and convert them to fake attachments, in order that `diff-mode' highlighting can be applied to the patch. This can be enabled by customising `notmuch-show-insert-text/plain-hook'.
This commit is contained in:
parent
08561d8ae1
commit
43423e9c88
2 changed files with 40 additions and 1 deletions
|
@ -71,7 +71,8 @@ any given message."
|
||||||
"Functions used to improve the display of text/plain parts."
|
"Functions used to improve the display of text/plain parts."
|
||||||
:group 'notmuch
|
:group 'notmuch
|
||||||
:type 'hook
|
:type 'hook
|
||||||
:options '(notmuch-wash-wrap-long-lines
|
:options '(notmuch-wash-convert-inline-patch-to-part
|
||||||
|
notmuch-wash-wrap-long-lines
|
||||||
notmuch-wash-tidy-citations
|
notmuch-wash-tidy-citations
|
||||||
notmuch-wash-elide-blank-lines
|
notmuch-wash-elide-blank-lines
|
||||||
notmuch-wash-excerpt-citations))
|
notmuch-wash-excerpt-citations))
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
|
|
||||||
(require 'coolj)
|
(require 'coolj)
|
||||||
|
|
||||||
|
(declare-function notmuch-show-insert-bodypart "notmuch-show" (msg part depth)
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(defvar notmuch-wash-signature-regexp
|
(defvar notmuch-wash-signature-regexp
|
||||||
|
@ -231,4 +233,40 @@ When doing so, maintaining citation leaders in the wrapped text."
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
(require 'diff-mode)
|
||||||
|
|
||||||
|
(defvar diff-file-header-re) ; From `diff-mode.el'.
|
||||||
|
|
||||||
|
(defun notmuch-wash-convert-inline-patch-to-part (depth)
|
||||||
|
"Convert an inline patch into a fake 'text/x-diff' attachment.
|
||||||
|
|
||||||
|
Given that this function guesses whether a buffer includes a
|
||||||
|
patch and then guesses the extent of the patch, there is scope
|
||||||
|
for error."
|
||||||
|
|
||||||
|
(goto-char (point-min))
|
||||||
|
(if (re-search-forward diff-file-header-re nil t)
|
||||||
|
(progn
|
||||||
|
(beginning-of-line -1)
|
||||||
|
(let ((patch-start (point))
|
||||||
|
(patch-end (point-max))
|
||||||
|
part)
|
||||||
|
(goto-char patch-start)
|
||||||
|
(if (or
|
||||||
|
;; Patch ends with signature.
|
||||||
|
(re-search-forward notmuch-wash-signature-regexp nil t)
|
||||||
|
;; Patch ends with bugtraq comment.
|
||||||
|
(re-search-forward "^\\*\\*\\* " nil t))
|
||||||
|
(setq patch-end (match-beginning 0)))
|
||||||
|
(save-restriction
|
||||||
|
(narrow-to-region patch-start patch-end)
|
||||||
|
(setq part (plist-put part :content-type "text/x-diff"))
|
||||||
|
(setq part (plist-put part :content (buffer-string)))
|
||||||
|
(setq part (plist-put part :id -1))
|
||||||
|
(setq part (plist-put part :filename "inline patch"))
|
||||||
|
(delete-region (point-min) (point-max))
|
||||||
|
(notmuch-show-insert-bodypart nil part depth))))))
|
||||||
|
|
||||||
|
;;
|
||||||
|
|
||||||
(provide 'notmuch-wash)
|
(provide 'notmuch-wash)
|
||||||
|
|
Loading…
Reference in a new issue