unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH v3] notmuch.el: Refactor citation markup. Variables for minimum size, button text.
       [not found] <id:1261771748-23687-1-git-send-email-david@tethera.net>
@ 2010-01-16 13:44 ` david
  2010-02-24 18:06   ` Carl Worth
  0 siblings, 1 reply; 4+ messages in thread
From: david @ 2010-01-16 13:44 UTC (permalink / raw)
  To: notmuch; +Cc: David Bremner

From: David Bremner <bremner@unb.ca>

This is a fairly intrusive rewrite.

- I pulled the common code for the signature and citation case out
  into a separate function. This is not so much shorter, but I think it
  will be easier to maintain.

- I treated top posted copies essentially like signatures, except that I didn't
  sanity check their length, since neither do their senders.  I don't know if
  people would find it useful to see the first few lines in a top posted copy;
  I left it off in this version.

- I replaced the sequence of (looking-at blah) (forward-line)  with a single
  re-search-forward per citation.

New user-visible variables

- notmuch-show-signature-button-format, notmuch-show-citation-button-format,
  notmuch-show-original-button-format
  Allow customization of button text.

- notmuch-show-citation-lines-prefix
  Show this much of the citation before hiding
---

This is the third rewrite of this patch. For some reason I squashed
the series this time, but I still have the other branch if that would be helpful.
Essentially after using the patches for a while, I no longer thought that people would like 
one patch without the others.

 notmuch.el |  177 +++++++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 127 insertions(+), 50 deletions(-)

diff --git a/notmuch.el b/notmuch.el
index 97914f2..4b84b55 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -88,13 +88,44 @@
 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 hidden signature. Click/Enter to show ]"
+  "String used to construct button text for hidden signatures
+
+Can use up to one integer format parameter, i.e. %d")
+
+(defvar notmuch-show-citation-button-format 
+  "[ %d more citation lines. Click/Enter to toggle visibility. ]"
+  "String used to construct button text for hidden citations.
+
+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.")
 
+(defvar notmuch-show-citation-lines-prefix 4
+  "Always show at least this many lines of a citation.
+
+If there is one more line, show that, otherwise collapse
+remaining lines into a button.")
+
 (defvar notmuch-command "notmuch"
   "Command to run the notmuch binary.")
 
@@ -586,6 +617,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
@@ -593,54 +627,97 @@ which this thread was originally shown."
   'face 'notmuch-message-summary-face
   :supertype 'notmuch-button-invisibility-toggle-type)
 
+(defun notmuch-show-citation-regexp (depth)
+  "Build a regexp for matching citations at a given DEPTH (indent)"
+  (let ((line-regexp (format "[[:space:]]\\{%d\\}>.*\n" depth)))
+    (concat "\\(?:^" line-regexp 
+	    "\\(?:[[:space:]]*\n" line-regexp
+	    "\\)?\\)+")))
+
+(defun notmuch-show-region-to-button (beg end type prefix button-text)
+  "Auxilary function to do the actual making of overlays and buttons
+
+BEG and END are buffer locations. TYPE should a string, either
+\"citation\" or \"signature\". PREFIX is some arbitrary text to
+insert before the button, probably for indentation.  BUTTON-TEXT
+is what to put on the button."
+
+;; This uses some slightly tricky conversions between strings and
+;; symbols because of the way the button code works. Note that
+;; replacing intern-soft with make-symbol will cause this to fail, 
+;; since the newly created symbol has no plist.
+
+  (let ((overlay (make-overlay beg end))
+	(invis-spec (make-symbol (concat "notmuch-" type "-region")))
+	(button-type (intern-soft (concat "notmuch-button-" 
+					  type "-toggle-type"))))
+    (add-to-invisibility-spec invis-spec)
+    (overlay-put overlay 'invisible invis-spec)
+    (goto-char (1+ end))
+    (save-excursion 
+      (goto-char (1- beg))
+      (insert prefix)
+      (insert-button button-text
+		     'invisibility-spec invis-spec
+		     :type button-type)
+      )))
+
+						 
 (defun notmuch-show-markup-citations-region (beg end depth)
-  (goto-char beg)
-  (beginning-of-line)
-  (while (< (point) end)
-    (let ((beg-sub (point-marker))
-	  (indent (make-string depth ? ))
-	  (citation ">"))
-      (move-to-column depth)
-      (if (looking-at citation)
-	  (progn
-	    (while (looking-at citation)
-	      (forward-line)
-	      (move-to-column depth))
-	    (let ((overlay (make-overlay beg-sub (point)))
-                  (invis-spec (make-symbol "notmuch-citation-region")))
-              (add-to-invisibility-spec invis-spec)
-	      (overlay-put overlay 'invisible invis-spec)
-              (let ((p (point-marker))
-                    (cite-button-text
-                     (concat "["  (number-to-string (count-lines beg-sub (point)))
-                             "-line citation. Click/Enter to show.]")))
-                (goto-char (- beg-sub 1))
-                (insert (concat "\n" indent))
-                (insert-button cite-button-text
-                               'invisibility-spec invis-spec
-                               :type 'notmuch-button-citation-toggle-type)
-                (forward-line)
-              ))))
-      (move-to-column depth)
-      (if (looking-at notmuch-show-signature-regexp)
-	  (let ((sig-lines (- (count-lines beg-sub end) 1)))
-	    (if (<= sig-lines notmuch-show-signature-lines-max)
-		(progn
-                  (let ((invis-spec (make-symbol "notmuch-signature-region")))
-                    (add-to-invisibility-spec invis-spec)
-                    (overlay-put (make-overlay beg-sub end)
-                                 'invisible invis-spec)
-                  
-                    (goto-char (- beg-sub 1))
-                    (insert (concat "\n" indent))
-                    (let ((sig-button-text (concat "[" (number-to-string sig-lines)
-                                                   "-line signature. Click/Enter to show.]")))
-                      (insert-button sig-button-text 'invisibility-spec invis-spec
-                                     :type 'notmuch-button-signature-toggle-type)
-                     )
-                    (insert "\n")
-                    (goto-char end))))))
-      (forward-line))))
+  "Markup citations, and up to one signature in the given region"
+  ;; it would be nice if the untabify was not required, but 
+  ;; that would require notmuch to indent with spaces.
+  (untabify beg end)
+  (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))
+	     (cite-end 	(match-end 0))
+	     (cite-lines (count-lines cite-start cite-end)))
+	(when (>  cite-lines (1+ notmuch-show-citation-lines-prefix))
+	    (goto-char cite-start)
+	    (forward-line notmuch-show-citation-lines-prefix)
+	    (notmuch-show-region-to-button 
+	     (point) cite-end
+	     "citation"
+	     indent
+	     (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-lines (1- (count-lines sig-start end))))
+	  (if (<= sig-lines notmuch-show-signature-lines-max)
+	      (notmuch-show-region-to-button 
+	       sig-start
+	       end
+	       "signature"
+	       indent
+	       (format notmuch-show-signature-button-format sig-lines)
+	       ))))))
 
 (defun notmuch-show-markup-part (beg end depth)
   (if (re-search-forward notmuch-show-part-begin-regexp nil t)
-- 
1.6.5

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

* Re: [PATCH v3] notmuch.el: Refactor citation markup. Variables for minimum size, button text.
  2010-01-16 13:44 ` [PATCH v3] notmuch.el: Refactor citation markup. Variables for minimum size, button text david
@ 2010-02-24 18:06   ` Carl Worth
  2010-02-24 18:30     ` [PATCH] notmuch.el: hide original message in top posted replies david
  0 siblings, 1 reply; 4+ messages in thread
From: Carl Worth @ 2010-02-24 18:06 UTC (permalink / raw)
  To: david, notmuch; +Cc: David Bremner

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

On Sat, 16 Jan 2010 09:44:53 -0400, david@tethera.net wrote:
> This is the third rewrite of this patch. For some reason I squashed
> the series this time, but I still have the other branch if that would be helpful.
> Essentially after using the patches for a while, I no longer thought that people would like 
> one patch without the others.

Hmm...

Looks like I managed to merge in an earlier version of this, (but before
you added support for hiding top-posted messages). Do you have another
patch for that on top of master now?

(Or perhaps I'll find it already submitted as I work through the
backlog...)

As always, thanks for all your great work, David!

-Carl

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

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

* [PATCH] notmuch.el: hide original message in top posted replies.
  2010-02-24 18:06   ` Carl Worth
@ 2010-02-24 18:30     ` david
  2011-06-10 23:32       ` Carl Worth
  0 siblings, 1 reply; 4+ messages in thread
From: david @ 2010-02-24 18:30 UTC (permalink / raw)
  To: notmuch; +Cc: David Bremner

From: David Bremner <bremner@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

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

* Re: [PATCH] notmuch.el: hide original message in top posted replies.
  2010-02-24 18:30     ` [PATCH] notmuch.el: hide original message in top posted replies david
@ 2011-06-10 23:32       ` Carl Worth
  0 siblings, 0 replies; 4+ messages in thread
From: Carl Worth @ 2011-06-10 23:32 UTC (permalink / raw)
  To: david, notmuch; +Cc: David Bremner

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

On Wed, 24 Feb 2010 14:30:06 -0400, david@tethera.net wrote:
> This code treats top posted copies essentially like signatures, except
> that it doesn't sanity check their length, since neither do their
> senders.

Hi David,

I'm sorry I dropped this patch so long ago!

I just picked it up, rebased it against current master, added a test for
it, and pushed it out.

It's great to have these top-posted citations hidden now, so thanks!

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

For what it's worth, I didn't include this unrelated cleanup.

-Carl

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

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

end of thread, other threads:[~2011-06-10 23:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <id:1261771748-23687-1-git-send-email-david@tethera.net>
2010-01-16 13:44 ` [PATCH v3] notmuch.el: Refactor citation markup. Variables for minimum size, button text david
2010-02-24 18:06   ` Carl Worth
2010-02-24 18:30     ` [PATCH] notmuch.el: hide original message in top posted replies david
2011-06-10 23:32       ` 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).