1 Return-Path: <bremner@pivot.cs.unb.ca>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 8BB52431FBC
\r
6 for <notmuch@notmuchmail.org>; Sat, 16 Jan 2010 05:47:22 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.548 tagged_above=-999 required=5
\r
12 tests=[AWL=-0.705, BAYES_50=0.001, SUBJECT_FUZZY_TION=0.156]
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id j-j+GvP5UOhp for <notmuch@notmuchmail.org>;
\r
17 Sat, 16 Jan 2010 05:47:21 -0800 (PST)
\r
18 Received: from pivot.cs.unb.ca (pivot.cs.unb.ca [131.202.240.57])
\r
19 by olra.theworths.org (Postfix) with ESMTP id 7300A431FAE
\r
20 for <notmuch@notmuchmail.org>; Sat, 16 Jan 2010 05:47:21 -0800 (PST)
\r
22 fctnnbsc30w-142167190143.pppoe-dynamic.high-speed.nb.bellaliant.net
\r
23 ([142.167.190.143] helo=rocinante.cs.unb.ca)
\r
24 by pivot.cs.unb.ca with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32)
\r
25 (Exim 4.69) (envelope-from <bremner@pivot.cs.unb.ca>)
\r
26 id 1NW8zo-0001K1-7F; Sat, 16 Jan 2010 09:47:20 -0400
\r
27 Received: from bremner by rocinante.cs.unb.ca with local (Exim 4.71)
\r
28 (envelope-from <bremner@rocinante.cs.unb.ca>)
\r
29 id 1NW8xc-00088m-MG; Sat, 16 Jan 2010 09:45:04 -0400
\r
30 From: david@tethera.net
\r
31 To: notmuch@notmuchmail.org
\r
32 Date: Sat, 16 Jan 2010 09:44:53 -0400
\r
33 Message-Id: <1263649493-31177-1-git-send-email-david@tethera.net>
\r
34 X-Mailer: git-send-email 1.6.5
\r
35 In-Reply-To: <id:1261771748-23687-1-git-send-email-david@tethera.net>
\r
36 References: <id:1261771748-23687-1-git-send-email-david@tethera.net>
\r
37 X-Sender-Verified: bremner@pivot.cs.unb.ca
\r
38 Cc: David Bremner <bremner@unb.ca>
\r
39 Subject: [notmuch] [PATCH v3] notmuch.el: Refactor citation markup.
\r
40 Variables for minimum size, button text.
\r
41 X-BeenThere: notmuch@notmuchmail.org
\r
42 X-Mailman-Version: 2.1.13
\r
44 List-Id: "Use and development of the notmuch mail system."
\r
45 <notmuch.notmuchmail.org>
\r
46 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
47 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
48 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
49 List-Post: <mailto:notmuch@notmuchmail.org>
\r
50 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
51 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
52 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
53 X-List-Received-Date: Sat, 16 Jan 2010 13:47:22 -0000
\r
55 From: David Bremner <bremner@unb.ca>
\r
57 This is a fairly intrusive rewrite.
\r
59 - I pulled the common code for the signature and citation case out
\r
60 into a separate function. This is not so much shorter, but I think it
\r
61 will be easier to maintain.
\r
63 - I treated top posted copies essentially like signatures, except that I didn't
\r
64 sanity check their length, since neither do their senders. I don't know if
\r
65 people would find it useful to see the first few lines in a top posted copy;
\r
66 I left it off in this version.
\r
68 - I replaced the sequence of (looking-at blah) (forward-line) with a single
\r
69 re-search-forward per citation.
\r
71 New user-visible variables
\r
73 - notmuch-show-signature-button-format, notmuch-show-citation-button-format,
\r
74 notmuch-show-original-button-format
\r
75 Allow customization of button text.
\r
77 - notmuch-show-citation-lines-prefix
\r
78 Show this much of the citation before hiding
\r
81 This is the third rewrite of this patch. For some reason I squashed
\r
82 the series this time, but I still have the other branch if that would be helpful.
\r
83 Essentially after using the patches for a while, I no longer thought that people would like
\r
84 one patch without the others.
\r
86 notmuch.el | 177 +++++++++++++++++++++++++++++++++++++++++++-----------------
\r
87 1 files changed, 127 insertions(+), 50 deletions(-)
\r
89 diff --git a/notmuch.el b/notmuch.el
\r
90 index 97914f2..4b84b55 100644
\r
94 The regexp can (and should) include $ to match the end of the
\r
95 line, but should not include ^ to match the beginning of the
\r
96 line. This is because notmuch may have inserted additional space
\r
97 -for indentation at the beginning of the line. But notmuch will
\r
98 -move past the indentation when testing this pattern, (so that the
\r
99 -pattern can still test against the entire line).")
\r
100 +for indentation at the beginning of the line.")
\r
102 +(defvar notmuch-show-original-regexp "\\(--+\s?[oO]riginal [mM]essage\s?--+\\)$"
\r
103 + "Pattern to match a line that separates original message from reply in top-posted message.
\r
105 +The regexp can (and should) include $ to match the end of the
\r
106 +line, but should not include ^ to match the beginning of the
\r
107 +line. This is because notmuch may have inserted additional space
\r
108 +for indentation at the beginning of the line.")
\r
110 +(defvar notmuch-show-signature-button-format
\r
111 + "[ %d-line hidden signature. Click/Enter to show ]"
\r
112 + "String used to construct button text for hidden signatures
\r
114 +Can use up to one integer format parameter, i.e. %d")
\r
116 +(defvar notmuch-show-citation-button-format
\r
117 + "[ %d more citation lines. Click/Enter to toggle visibility. ]"
\r
118 + "String used to construct button text for hidden citations.
\r
120 +Can use up to one integer format parameter, i.e. %d")
\r
122 +(defvar notmuch-show-original-button-format
\r
123 + "[ %d-line hidden original message. Click/Enter to show ]"
\r
124 + "String used to construct button text for hidden copies of messages
\r
126 +Can use up to one integer format parameter, i.e. %d")
\r
129 (defvar notmuch-show-signature-lines-max 12
\r
130 "Maximum length of signature that will be hidden by default.")
\r
132 +(defvar notmuch-show-citation-lines-prefix 4
\r
133 + "Always show at least this many lines of a citation.
\r
135 +If there is one more line, show that, otherwise collapse
\r
136 +remaining lines into a button.")
\r
138 (defvar notmuch-command "notmuch"
\r
139 "Command to run the notmuch binary.")
\r
141 @@ -586,6 +617,9 @@ which this thread was originally shown."
\r
142 :supertype 'notmuch-button-invisibility-toggle-type)
\r
143 (define-button-type 'notmuch-button-signature-toggle-type 'help-echo "mouse-1, RET: Show signature"
\r
144 :supertype 'notmuch-button-invisibility-toggle-type)
\r
145 +(define-button-type 'notmuch-button-original-toggle-type 'help-echo "mouse-1, RET: Show original message"
\r
146 + :supertype 'notmuch-button-invisibility-toggle-type)
\r
148 (define-button-type 'notmuch-button-headers-toggle-type 'help-echo "mouse-1, RET: Show headers"
\r
149 :supertype 'notmuch-button-invisibility-toggle-type)
\r
150 (define-button-type 'notmuch-button-body-toggle-type
\r
151 @@ -593,54 +627,97 @@ which this thread was originally shown."
\r
152 'face 'notmuch-message-summary-face
\r
153 :supertype 'notmuch-button-invisibility-toggle-type)
\r
155 +(defun notmuch-show-citation-regexp (depth)
\r
156 + "Build a regexp for matching citations at a given DEPTH (indent)"
\r
157 + (let ((line-regexp (format "[[:space:]]\\{%d\\}>.*\n" depth)))
\r
158 + (concat "\\(?:^" line-regexp
\r
159 + "\\(?:[[:space:]]*\n" line-regexp
\r
162 +(defun notmuch-show-region-to-button (beg end type prefix button-text)
\r
163 + "Auxilary function to do the actual making of overlays and buttons
\r
165 +BEG and END are buffer locations. TYPE should a string, either
\r
166 +\"citation\" or \"signature\". PREFIX is some arbitrary text to
\r
167 +insert before the button, probably for indentation. BUTTON-TEXT
\r
168 +is what to put on the button."
\r
170 +;; This uses some slightly tricky conversions between strings and
\r
171 +;; symbols because of the way the button code works. Note that
\r
172 +;; replacing intern-soft with make-symbol will cause this to fail,
\r
173 +;; since the newly created symbol has no plist.
\r
175 + (let ((overlay (make-overlay beg end))
\r
176 + (invis-spec (make-symbol (concat "notmuch-" type "-region")))
\r
177 + (button-type (intern-soft (concat "notmuch-button-"
\r
178 + type "-toggle-type"))))
\r
179 + (add-to-invisibility-spec invis-spec)
\r
180 + (overlay-put overlay 'invisible invis-spec)
\r
181 + (goto-char (1+ end))
\r
183 + (goto-char (1- beg))
\r
185 + (insert-button button-text
\r
186 + 'invisibility-spec invis-spec
\r
187 + :type button-type)
\r
191 (defun notmuch-show-markup-citations-region (beg end depth)
\r
193 - (beginning-of-line)
\r
194 - (while (< (point) end)
\r
195 - (let ((beg-sub (point-marker))
\r
196 - (indent (make-string depth ? ))
\r
198 - (move-to-column depth)
\r
199 - (if (looking-at citation)
\r
201 - (while (looking-at citation)
\r
203 - (move-to-column depth))
\r
204 - (let ((overlay (make-overlay beg-sub (point)))
\r
205 - (invis-spec (make-symbol "notmuch-citation-region")))
\r
206 - (add-to-invisibility-spec invis-spec)
\r
207 - (overlay-put overlay 'invisible invis-spec)
\r
208 - (let ((p (point-marker))
\r
209 - (cite-button-text
\r
210 - (concat "[" (number-to-string (count-lines beg-sub (point)))
\r
211 - "-line citation. Click/Enter to show.]")))
\r
212 - (goto-char (- beg-sub 1))
\r
213 - (insert (concat "\n" indent))
\r
214 - (insert-button cite-button-text
\r
215 - 'invisibility-spec invis-spec
\r
216 - :type 'notmuch-button-citation-toggle-type)
\r
219 - (move-to-column depth)
\r
220 - (if (looking-at notmuch-show-signature-regexp)
\r
221 - (let ((sig-lines (- (count-lines beg-sub end) 1)))
\r
222 - (if (<= sig-lines notmuch-show-signature-lines-max)
\r
224 - (let ((invis-spec (make-symbol "notmuch-signature-region")))
\r
225 - (add-to-invisibility-spec invis-spec)
\r
226 - (overlay-put (make-overlay beg-sub end)
\r
227 - 'invisible invis-spec)
\r
229 - (goto-char (- beg-sub 1))
\r
230 - (insert (concat "\n" indent))
\r
231 - (let ((sig-button-text (concat "[" (number-to-string sig-lines)
\r
232 - "-line signature. Click/Enter to show.]")))
\r
233 - (insert-button sig-button-text 'invisibility-spec invis-spec
\r
234 - :type 'notmuch-button-signature-toggle-type)
\r
237 - (goto-char end))))))
\r
238 - (forward-line))))
\r
239 + "Markup citations, and up to one signature in the given region"
\r
240 + ;; it would be nice if the untabify was not required, but
\r
241 + ;; that would require notmuch to indent with spaces.
\r
242 + (untabify beg end)
\r
243 + (let ((citation-regexp (notmuch-show-citation-regexp depth))
\r
244 + (signature-regexp (concat (format "^[[:space:]]\\{%d\\}" depth)
\r
245 + notmuch-show-signature-regexp))
\r
246 + (original-regexp (concat (format "^[[:space:]]\\{%d\\}" depth)
\r
247 + notmuch-show-original-regexp))
\r
249 + (indent (concat "\n" (make-string depth ? ))))
\r
251 + (beginning-of-line)
\r
253 + (if (and (< (point) end)
\r
254 + (re-search-forward original-regexp end t))
\r
255 + (let* ((msg-start (match-beginning 0))
\r
256 + (msg-lines (1- (count-lines msg-start end))))
\r
257 + (notmuch-show-region-to-button
\r
262 + (format notmuch-show-original-button-format msg-lines)
\r
265 + (while (and (< (point) end)
\r
266 + (re-search-forward citation-regexp end t))
\r
267 + (let* ((cite-start (match-beginning 0))
\r
268 + (cite-end (match-end 0))
\r
269 + (cite-lines (count-lines cite-start cite-end)))
\r
270 + (when (> cite-lines (1+ notmuch-show-citation-lines-prefix))
\r
271 + (goto-char cite-start)
\r
272 + (forward-line notmuch-show-citation-lines-prefix)
\r
273 + (notmuch-show-region-to-button
\r
277 + (format notmuch-show-citation-button-format
\r
278 + (- cite-lines notmuch-show-citation-lines-prefix))
\r
281 + (if (and (< (point) end)
\r
282 + (re-search-forward signature-regexp end t))
\r
283 + (let* ((sig-start (match-beginning 0))
\r
284 + (sig-lines (1- (count-lines sig-start end))))
\r
285 + (if (<= sig-lines notmuch-show-signature-lines-max)
\r
286 + (notmuch-show-region-to-button
\r
291 + (format notmuch-show-signature-button-format sig-lines)
\r
294 (defun notmuch-show-markup-part (beg end depth)
\r
295 (if (re-search-forward notmuch-show-part-begin-regexp nil t)
\r