[notmuch] [PATCH] notmuch.el: hide original message in top posted replies.

david at tethera.net david at tethera.net
Wed Feb 24 10:30:06 PST 2010


From: David Bremner <bremner at unb.ca>

This code treats top posted copies essentially like signatures, except
that it doesn't sanity check their length, since neither do their
senders.

In an unrelated cleanup, remove the let definition of sig-end, since
it was unused.

New user-visible variable:

  notmuch-show-original-button-format:   Allow customization of button text.
---

This is the unsquashed version of what was new in the v3 of the
citation patch, rebased against current master.

 notmuch.el |   40 ++++++++++++++++++++++++++++++++++++----
 1 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/notmuch.el b/notmuch.el
index 6482170..b1a590f 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -107,9 +107,15 @@
 The regexp can (and should) include $ to match the end of the
 line, but should not include ^ to match the beginning of the
 line. This is because notmuch may have inserted additional space
-for indentation at the beginning of the line. But notmuch will
-move past the indentation when testing this pattern, (so that the
-pattern can still test against the entire line).")
+for indentation at the beginning of the line.")
+
+(defvar notmuch-show-original-regexp "\\(--+\s?[oO]riginal [mM]essage\s?--+\\)$"
+  "Pattern to match a line that separates original message from reply in top-posted message.
+
+The regexp can (and should) include $ to match the end of the
+line, but should not include ^ to match the beginning of the
+line. This is because notmuch may have inserted additional space
+for indentation at the beginning of the line.")
 
 (defvar notmuch-show-signature-button-format
   "[ %d-line signature. Click/Enter to toggle visibility. ]"
@@ -123,6 +129,13 @@ Can use up to one integer format parameter, i.e. %d")
 
 Can use up to one integer format parameter, i.e. %d")
 
+(defvar notmuch-show-original-button-format 
+  "[ %d-line hidden original message. Click/Enter to show ]"
+  "String used to construct button text for hidden copies of messages
+
+Can use up to one integer format parameter, i.e. %d")
+
+
 (defvar notmuch-show-signature-lines-max 12
   "Maximum length of signature that will be hidden by default.")
 
@@ -717,6 +730,9 @@ which this thread was originally shown."
   :supertype 'notmuch-button-invisibility-toggle-type)
 (define-button-type 'notmuch-button-signature-toggle-type 'help-echo "mouse-1, RET: Show signature"
   :supertype 'notmuch-button-invisibility-toggle-type)
+(define-button-type 'notmuch-button-original-toggle-type 'help-echo "mouse-1, RET: Show original message"
+  :supertype 'notmuch-button-invisibility-toggle-type)
+
 (define-button-type 'notmuch-button-headers-toggle-type 'help-echo "mouse-1, RET: Show headers"
   :supertype 'notmuch-button-invisibility-toggle-type)
 (define-button-type 'notmuch-button-body-toggle-type
@@ -768,9 +784,25 @@ is what to put on the button."
   (let ((citation-regexp (notmuch-show-citation-regexp depth))
 	(signature-regexp (concat (format "^[[:space:]]\\{%d\\}" depth)
 				  notmuch-show-signature-regexp))
+	(original-regexp (concat (format "^[[:space:]]\\{%d\\}" depth) 
+				  notmuch-show-original-regexp))
+
 	(indent (concat "\n" (make-string depth ? ))))
     (goto-char beg)
     (beginning-of-line)
+
+    (if (and (< (point) end) 
+	     (re-search-forward original-regexp end t))
+	(let* ((msg-start (match-beginning 0))
+	       (msg-lines (1- (count-lines msg-start end))))
+	  (notmuch-show-region-to-button 
+	   msg-start
+	   end
+	   "original"
+	   indent
+	   (format notmuch-show-original-button-format msg-lines)
+	   )))
+
     (while (and (< (point) end)
 		(re-search-forward citation-regexp end t))
       (let* ((cite-start (match-beginning 0))
@@ -786,10 +818,10 @@ is what to put on the button."
 	   (format notmuch-show-citation-button-format
 		   (- cite-lines notmuch-show-citation-lines-prefix))
 	   ))))
+
     (if (and (< (point) end)
 	     (re-search-forward signature-regexp end t))
 	(let* ((sig-start (match-beginning 0))
-	       (sig-end (match-end 0))
 	       (sig-lines (1- (count-lines sig-start end))))
 	  (if (<= sig-lines notmuch-show-signature-lines-max)
 	      (notmuch-show-region-to-button
-- 
1.6.6



More information about the notmuch mailing list