unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] emacs/notmuch-wash.el: Add `notmuch-wash-convert-inline-patch-to-part'.
@ 2010-04-27 10:20 dme
  2010-04-27 15:22 ` Carl Worth
  0 siblings, 1 reply; 2+ messages in thread
From: dme @ 2010-04-27 10:20 UTC (permalink / raw)
  To: notmuch

From: David Edmondson <dme@dme.org>

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'.
---
 emacs/notmuch-show.el |    3 ++-
 emacs/notmuch-wash.el |   38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 1 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index eb5335f..4b1baf3 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -71,7 +71,8 @@ any given message."
   "Functions used to improve the display of text/plain parts."
   :group 'notmuch
   :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-elide-blank-lines
 	     notmuch-wash-excerpt-citations))
diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
index 57f0cc5..bf0a354 100644
--- a/emacs/notmuch-wash.el
+++ b/emacs/notmuch-wash.el
@@ -23,6 +23,8 @@
 
 (require 'coolj)
 
+(declare-function notmuch-show-insert-bodypart "notmuch-show" (msg part depth)
+
 ;;
 
 (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)
-- 
1.7.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] emacs/notmuch-wash.el: Add `notmuch-wash-convert-inline-patch-to-part'.
  2010-04-27 10:20 [PATCH] emacs/notmuch-wash.el: Add `notmuch-wash-convert-inline-patch-to-part' dme
@ 2010-04-27 15:22 ` Carl Worth
  0 siblings, 0 replies; 2+ messages in thread
From: Carl Worth @ 2010-04-27 15:22 UTC (permalink / raw)
  To: dme, notmuch

[-- Attachment #1: Type: text/plain, Size: 346 bytes --]

On Tue, 27 Apr 2010 11:20:58 +0100, dme@dme.org wrote:
> From: David Edmondson <dme@dme.org>
> 
> 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'.

Thanks. This is merged.

-Carl

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-04-27 15:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-27 10:20 [PATCH] emacs/notmuch-wash.el: Add `notmuch-wash-convert-inline-patch-to-part' dme
2010-04-27 15:22 ` Carl Worth

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).