1 Return-Path: <m.walters@qmul.ac.uk>
\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 9AB20431FBC
\r
6 for <notmuch@notmuchmail.org>; Sat, 14 Jul 2012 14:15:24 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5
\r
12 tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,
\r
13 NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled
\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 Ns0iuNwK1DTI for <notmuch@notmuchmail.org>;
\r
17 Sat, 14 Jul 2012 14:15:20 -0700 (PDT)
\r
18 Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])
\r
19 (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id 3EF82431FBD
\r
22 for <notmuch@notmuchmail.org>; Sat, 14 Jul 2012 14:15:20 -0700 (PDT)
\r
23 Received: from smtp.qmul.ac.uk ([138.37.6.40])
\r
24 by mail2.qmul.ac.uk with esmtp (Exim 4.71)
\r
25 (envelope-from <m.walters@qmul.ac.uk>)
\r
26 id 1Sq9gJ-0000nk-4d; Sat, 14 Jul 2012 22:15:15 +0100
\r
27 Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223]
\r
29 by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)
\r
30 (envelope-from <m.walters@qmul.ac.uk>)
\r
31 id 1Sq9gI-0004CH-Jg; Sat, 14 Jul 2012 22:15:14 +0100
\r
32 From: Mark Walters <markwalters1009@gmail.com>
\r
33 To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org
\r
34 Subject: Re: [PATCH v2 4/7] emacs: Use result text properties for search
\r
36 In-Reply-To: <1342237406-32507-5-git-send-email-amdragon@mit.edu>
\r
37 References: <1342140319-19859-1-git-send-email-amdragon@mit.edu>
\r
38 <1342237406-32507-1-git-send-email-amdragon@mit.edu>
\r
39 <1342237406-32507-5-git-send-email-amdragon@mit.edu>
\r
40 User-Agent: Notmuch/0.13.2+90~g84fa1ef (http://notmuchmail.org) Emacs/23.4.1
\r
41 (x86_64-pc-linux-gnu)
\r
42 Date: Sat, 14 Jul 2012 22:15:12 +0100
\r
43 Message-ID: <871ukexcwv.fsf@qmul.ac.uk>
\r
45 Content-Type: text/plain; charset=us-ascii
\r
46 X-Sender-Host-Address: 94.192.233.223
\r
47 X-QM-SPAM-Info: Sender has good ham record. :)
\r
48 X-QM-Body-MD5: 2309eaf59de0d436422e359abb5adb3a (of first 20000 bytes)
\r
49 X-SpamAssassin-Score: -1.8
\r
50 X-SpamAssassin-SpamBar: -
\r
51 X-SpamAssassin-Report: The QM spam filters have analysed this message to
\r
53 spam. We require at least 5.0 points to mark a message as spam.
\r
54 This message scored -1.8 points.
\r
55 Summary of the scoring:
\r
56 * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,
\r
58 * [138.37.6.40 listed in list.dnswl.org]
\r
59 * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail
\r
60 provider * (markwalters1009[at]gmail.com)
\r
61 * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay
\r
63 * 0.5 AWL AWL: From: address is in the auto white-list
\r
64 X-QM-Scan-Virus: ClamAV says the message is clean
\r
65 X-BeenThere: notmuch@notmuchmail.org
\r
66 X-Mailman-Version: 2.1.13
\r
68 List-Id: "Use and development of the notmuch mail system."
\r
69 <notmuch.notmuchmail.org>
\r
70 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
71 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
72 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
73 List-Post: <mailto:notmuch@notmuchmail.org>
\r
74 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
75 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
76 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
77 X-List-Received-Date: Sat, 14 Jul 2012 21:15:24 -0000
\r
80 On Sat, 14 Jul 2012, Austin Clements <amdragon@MIT.EDU> wrote:
\r
81 > This simplifies the traversal of regions of results and eliminates the
\r
82 > need for save-excursions (which tend to get in the way of maintaining
\r
83 > point when we make changes to the buffer). It also fixes some strange
\r
84 > corner cases in the old line-based code where results that bordered
\r
85 > the region but were not included in it could be affected by region
\r
86 > commands. Coincidentally, this also essentially enables multi-line
\r
87 > search result formats; the only remaining non-multi-line-capable
\r
88 > functions are notmuch-search-{next,previous}-thread, which are only
\r
89 > used interactively.
\r
91 Having understood how macros work (thanks to Austin's patient
\r
92 explanations on irc) this looks fine. So +1 for the whole series.
\r
98 > emacs/notmuch.el | 61 ++++++++++++++++++++++++++++++------------------------
\r
99 > 1 file changed, 34 insertions(+), 27 deletions(-)
\r
101 > diff --git a/emacs/notmuch.el b/emacs/notmuch.el
\r
102 > index 8e1a769..92ba2c1 100644
\r
103 > --- a/emacs/notmuch.el
\r
104 > +++ b/emacs/notmuch.el
\r
105 > @@ -427,17 +427,33 @@ returns nil"
\r
106 > (next-single-property-change (or pos (point)) 'notmuch-search-result
\r
107 > nil (point-max))))
\r
109 > +(defmacro notmuch-search-do-results (beg end pos-sym &rest body)
\r
110 > + "Invoke BODY for each result between BEG and END.
\r
112 > +POS-SYM will be bound to the point at the beginning of the
\r
113 > +current result."
\r
114 > + (declare (indent 3))
\r
115 > + (let ((end-sym (make-symbol "end"))
\r
116 > + (first-sym (make-symbol "first")))
\r
117 > + `(let ((,pos-sym (notmuch-search-result-beginning ,beg))
\r
118 > + ;; End must be a marker in case body changes the text
\r
119 > + (,end-sym (copy-marker ,end))
\r
120 > + ;; Make sure we examine one result, even if (= beg end)
\r
121 > + (,first-sym t))
\r
122 > + ;; We have to be careful if the region extends beyond the
\r
123 > + ;; results. In this case, pos could be null or there could be
\r
124 > + ;; no result at pos.
\r
125 > + (while (and ,pos-sym (or (< ,pos-sym ,end-sym) ,first-sym))
\r
126 > + (when (notmuch-search-get-result ,pos-sym)
\r
128 > + (setq ,pos-sym (notmuch-search-result-end ,pos-sym)
\r
129 > + ,first-sym nil)))))
\r
131 > (defun notmuch-search-properties-in-region (property beg end)
\r
132 > - (save-excursion
\r
133 > - (let ((output nil)
\r
134 > - (last-line (line-number-at-pos end))
\r
135 > - (max-line (- (line-number-at-pos (point-max)) 2)))
\r
136 > - (goto-char beg)
\r
137 > - (beginning-of-line)
\r
138 > - (while (<= (line-number-at-pos) (min last-line max-line))
\r
139 > - (setq output (cons (get-text-property (point) property) output))
\r
140 > - (forward-line 1))
\r
143 > + (notmuch-search-do-results beg end pos
\r
144 > + (push (get-text-property pos property) output))
\r
147 > (defun notmuch-search-find-thread-id ()
\r
148 > "Return the thread for the current thread"
\r
149 > @@ -517,28 +533,19 @@ and will also appear in a buffer named \"*Notmuch errors*\"."
\r
150 > (plist-get (notmuch-search-get-result pos) :tags))
\r
152 > (defun notmuch-search-get-tags-region (beg end)
\r
153 > - (save-excursion
\r
154 > - (let ((output nil)
\r
155 > - (last-line (line-number-at-pos end))
\r
156 > - (max-line (- (line-number-at-pos (point-max)) 2)))
\r
157 > - (goto-char beg)
\r
158 > - (while (<= (line-number-at-pos) (min last-line max-line))
\r
159 > - (setq output (append output (notmuch-search-get-tags)))
\r
160 > - (forward-line 1))
\r
163 > + (notmuch-search-do-results beg end pos
\r
164 > + (setq output (append output (notmuch-search-get-tags pos))))
\r
167 > (defun notmuch-search-tag-region (beg end &optional tag-changes)
\r
168 > "Change tags for threads in the given region."
\r
169 > (let ((search-string (notmuch-search-find-thread-id-region-search beg end)))
\r
170 > (setq tag-changes (funcall 'notmuch-tag search-string tag-changes))
\r
171 > - (save-excursion
\r
172 > - (let ((last-line (line-number-at-pos end))
\r
173 > - (max-line (- (line-number-at-pos (point-max)) 2)))
\r
174 > - (goto-char beg)
\r
175 > - (while (<= (line-number-at-pos) (min last-line max-line))
\r
176 > - (notmuch-search-set-tags
\r
177 > - (notmuch-update-tags (notmuch-search-get-tags) tag-changes))
\r
178 > - (forward-line))))))
\r
179 > + (notmuch-search-do-results beg end pos
\r
180 > + (notmuch-search-set-tags
\r
181 > + (notmuch-update-tags (notmuch-search-get-tags pos) tag-changes)
\r
184 > (defun notmuch-search-tag (&optional tag-changes)
\r
185 > "Change tags for the currently selected thread or region.
\r