1 Return-Path: <amdragon@mit.edu>
\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 73E18429E34
\r
6 for <notmuch@notmuchmail.org>; Sun, 29 Jan 2012 20:49:09 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id EmA5AgOtOpBj for <notmuch@notmuchmail.org>;
\r
16 Sun, 29 Jan 2012 20:49:02 -0800 (PST)
\r
17 Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id 02587431FBC
\r
20 for <notmuch@notmuchmail.org>; Sun, 29 Jan 2012 20:49:01 -0800 (PST)
\r
21 X-AuditID: 12074422-b7fd66d0000008f9-5c-4f2621396f83
\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])
\r
23 by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id 59.98.02297.931262F4; Sun, 29 Jan 2012 23:48:57 -0500 (EST)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q0U4munF017066;
\r
27 Sun, 29 Jan 2012 23:48:57 -0500
\r
28 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])
\r
29 (authenticated bits=0)
\r
30 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
31 by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0U4mt7L028524
\r
32 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
33 Sun, 29 Jan 2012 23:48:56 -0500 (EST)
\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)
\r
35 (envelope-from <amdragon@mit.edu>)
\r
36 id 1Rrj9y-0000VZ-PP; Sun, 29 Jan 2012 23:48:06 -0500
\r
37 Date: Sun, 29 Jan 2012 23:48:06 -0500
\r
38 From: Austin Clements <amdragon@MIT.EDU>
\r
39 To: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>
\r
40 Subject: Re: [PATCH v2 03/13] emacs: make "+" and "-" tagging operations in
\r
41 notmuch-search more robust
\r
42 Message-ID: <20120130044806.GM17991@mit.edu>
\r
43 References: <1327725684-5887-1-git-send-email-dmitry.kurochkin@gmail.com>
\r
44 <1327890382-548-1-git-send-email-dmitry.kurochkin@gmail.com>
\r
45 <1327890382-548-4-git-send-email-dmitry.kurochkin@gmail.com>
\r
47 Content-Type: text/plain; charset=us-ascii
\r
48 Content-Disposition: inline
\r
49 In-Reply-To: <1327890382-548-4-git-send-email-dmitry.kurochkin@gmail.com>
\r
50 User-Agent: Mutt/1.5.21 (2010-09-15)
\r
51 X-Brightmail-Tracker:
\r
52 H4sIAAAAAAAAA+NgFlrEKsWRmVeSWpSXmKPExsUixG6nrmujqOZvsGK1tMXVrf3sFtdvzmR2
\r
53 YPLYOesuu8ezVbeYA5iiuGxSUnMyy1KL9O0SuDL+XXnPUnA1pKJ/91XGBsYZLl2MnBwSAiYS
\r
54 F19eY4SwxSQu3FvP1sXIxSEksI9RomvZG0YIZwOjxI4pB1ggnJNMEpv/rWGHcJYwSnRO+8kM
\r
55 0s8ioCpxee55dhCbTUBDYtv+5WBzRQQMJW5dfAVWwywgLfHtdzMTiC0skCHR2LYNyObg4BXQ
\r
56 kXh0EWrbcUaJYysfgNXzCghKnJz5hAWiV0vixr+XYPUgc5b/4wAJcwp4Suy4spYVxBYVUJGY
\r
57 cnIb2wRGoVlIumch6Z6F0L2AkXkVo2xKbpVubmJmTnFqsm5xcmJeXmqRrqlebmaJXmpK6SZG
\r
58 cGC7KO1g/HlQ6RCjAAejEg9v0D9VfyHWxLLiytxDjJIcTEqivEkKav5CfEn5KZUZicUZ8UWl
\r
59 OanFhxglOJiVRHgf/QQq501JrKxKLcqHSUlzsCiJ86prvfMTEkhPLEnNTk0tSC2CyWpwcAhc
\r
60 OXhkNqMUS15+XqqSBG8RyALBotT01Iq0zJwShFImDk6QRTxAi0pAaniLCxJzizPTIfKnGI05
\r
61 2t/uPs/I8Xb+/vOMQmDjpMR5Y0FKBUBKM0rz4KbBktYrRnGgR4V5z4NU8QATHty8V0CrmIBW
\r
62 PWcA+am4JBEhJdXAuFzzitYWIa4fMYeORfYpcy0+u+63GcvGJ5ciSs7+1hDZpZ+o/+23l8+p
\r
63 AvW2vcpH505VTm+zqf/5Sd+sTjAxJlNjxf6P8aEWytOTKyJ63J00zmZ96Uri+aN35cNtu/ef
\r
64 NI/5+62/ZWb99fLFKLPUWwrXqrvunT1avpCpQ22D3Hb3q0tFN3THKrEUZyQaajEXFScCALwa
\r
66 Cc: notmuch@notmuchmail.org
\r
67 X-BeenThere: notmuch@notmuchmail.org
\r
68 X-Mailman-Version: 2.1.13
\r
70 List-Id: "Use and development of the notmuch mail system."
\r
71 <notmuch.notmuchmail.org>
\r
72 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
73 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
74 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
75 List-Post: <mailto:notmuch@notmuchmail.org>
\r
76 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
77 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
78 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
79 X-List-Received-Date: Mon, 30 Jan 2012 04:49:09 -0000
\r
81 Looking good. Just a few small points below.
\r
83 Quoth Dmitry Kurochkin on Jan 30 at 6:26 am:
\r
84 > Before the change, "+" and "-" tagging operations in notmuch-search
\r
85 > view accepted only a single tag. The patch makes them use the
\r
86 > recently added `notmuch-read-tag-changes' function (renamed
\r
87 > `notmuch-select-tags-with-completion'), which allows to enter multiple
\r
88 > tags with "+" and "-" prefixes. So after the change, "+" and "-"
\r
89 > bindings in notmuch-search view allow to both add and remove multiple
\r
90 > tags. The only difference between "+" and "-" is the minibuffer
\r
91 > initial input ("+" and "-" respectively).
\r
93 > emacs/notmuch.el | 164 +++++++++++++++++++++++++++---------------------------
\r
94 > 1 files changed, 82 insertions(+), 82 deletions(-)
\r
96 > diff --git a/emacs/notmuch.el b/emacs/notmuch.el
\r
97 > index ff46617..90b594c 100644
\r
98 > --- a/emacs/notmuch.el
\r
99 > +++ b/emacs/notmuch.el
\r
100 > @@ -76,38 +76,57 @@ For example:
\r
101 > (defvar notmuch-query-history nil
\r
102 > "Variable to store minibuffer history for notmuch queries")
\r
104 > -(defun notmuch-tag-completions (&optional prefixes search-terms)
\r
105 > - (let ((tag-list
\r
107 > - (with-output-to-string
\r
108 > - (with-current-buffer standard-output
\r
109 > - (apply 'call-process notmuch-command nil t
\r
110 > - nil "search-tags" search-terms)))
\r
112 > - (if (null prefixes)
\r
114 > - (apply #'append
\r
115 > - (mapcar (lambda (tag)
\r
116 > - (mapcar (lambda (prefix)
\r
117 > - (concat prefix tag)) prefixes))
\r
119 > +(defun notmuch-tag-completions (&optional search-terms)
\r
121 > + (with-output-to-string
\r
122 > + (with-current-buffer standard-output
\r
123 > + (apply 'call-process notmuch-command nil t
\r
124 > + nil "search-tags" search-terms)))
\r
127 > (defun notmuch-select-tag-with-completion (prompt &rest search-terms)
\r
128 > - (let ((tag-list (notmuch-tag-completions nil search-terms)))
\r
129 > + (let ((tag-list (notmuch-tag-completions search-terms)))
\r
130 > (completing-read prompt tag-list)))
\r
132 > -(defun notmuch-select-tags-with-completion (prompt &optional prefixes &rest search-terms)
\r
133 > - (let ((tag-list (notmuch-tag-completions prefixes search-terms))
\r
134 > - (crm-separator " ")
\r
135 > - ;; By default, space is bound to "complete word" function.
\r
136 > - ;; Re-bind it to insert a space instead. Note that <tab>
\r
137 > - ;; still does the completion.
\r
138 > - (crm-local-completion-map
\r
139 > - (let ((map (make-sparse-keymap)))
\r
140 > - (set-keymap-parent map crm-local-completion-map)
\r
141 > - (define-key map " " 'self-insert-command)
\r
143 > - (delete "" (completing-read-multiple prompt tag-list))))
\r
144 > +(defun notmuch-read-tag-changes (&optional initial-input &rest search-terms)
\r
145 > + (let* ((all-tag-list (notmuch-tag-completions))
\r
146 > + (add-tag-list (mapcar (apply-partially 'concat "+") all-tag-list))
\r
147 > + (remove-tag-list (mapcar (apply-partially 'concat "-")
\r
148 > + (if (null search-terms)
\r
150 > + (notmuch-tag-completions search-terms))))
\r
151 > + (tag-list (append add-tag-list remove-tag-list))
\r
152 > + (crm-separator " ")
\r
153 > + ;; By default, space is bound to "complete word" function.
\r
154 > + ;; Re-bind it to insert a space instead. Note that <tab>
\r
155 > + ;; still does the completion.
\r
156 > + (crm-local-completion-map
\r
157 > + (let ((map (make-sparse-keymap)))
\r
158 > + (set-keymap-parent map crm-local-completion-map)
\r
159 > + (define-key map " " 'self-insert-command)
\r
161 > + (delete "" (completing-read-multiple "Tags (+add -drop): "
\r
162 > + tag-list nil nil initial-input))))
\r
164 > +(defun notmuch-update-tags (tags tag-changes)
\r
165 > + "Return a copy of TAGS with additions and removals from TAG-CHANGES.
\r
167 > +TAG-CHANGES must be a list of tags names, each prefixed with
\r
168 > +either a \"+\" to indicate the tag should be added to TAGS if not
\r
169 > +present or a \"-\" to indicate that the tag should be removed
\r
170 > +from TAGS if present."
\r
171 > + (let ((result-tags (copy-sequence tags)))
\r
172 > + (dolist (tag-change tag-changes)
\r
173 > + (unless (string= tag-change "")
\r
175 This function should give the "must be of the form" error for empty
\r
176 strings, rather than silently ignoring them. It turns out
\r
177 `string-to-char' on an empty string is fine (it returns 0, which will
\r
178 trigger the error), but `substring' isn't. Perhaps move the unless
\r
179 into the let before, like
\r
180 (let ((op (string-to-char tag-change))
\r
181 (tag (unless (string= tag-change "") (substring tag-change 1))))
\r
183 > + (let ((op (string-to-char tag-change))
\r
184 > + (tag (substring tag-change 1)))
\r
186 > + (?+ (unless (member tag result-tags)
\r
187 > + (push tag result-tags)))
\r
188 > + (?- (setq result-tags (delete tag result-tags)))
\r
190 > + (error "Changed tag must be of the form `+this_tag' or `-that_tag'"))))))
\r
191 > + (sort result-tags 'string<)))
\r
193 > (defun notmuch-foreach-mime-part (function mm-handle)
\r
194 > (cond ((stringp (car mm-handle))
\r
195 > @@ -447,6 +466,10 @@ Complete list of currently available key bindings:
\r
196 > "Return a list of threads for the current region"
\r
197 > (notmuch-search-properties-in-region 'notmuch-search-thread-id beg end))
\r
199 > +(defun notmuch-search-find-thread-id-region-search (beg end)
\r
200 > + "Return a search string for threads for the current region"
\r
201 > + (mapconcat 'identity (notmuch-search-find-thread-id-region beg end) " or "))
\r
203 > (defun notmuch-search-find-authors ()
\r
204 > "Return the authors for the current thread"
\r
205 > (get-text-property (point) 'notmuch-search-authors))
\r
206 > @@ -590,74 +613,53 @@ the messages that were tagged"
\r
207 > (forward-line 1))
\r
210 > -(defun notmuch-search-add-tag-thread (tag)
\r
211 > - (notmuch-search-add-tag-region tag (point) (point)))
\r
212 > +(defun notmuch-search-tag-thread (&rest tags)
\r
214 Maybe "tag-changes" instead of "tags" for this and
\r
215 notmuch-search-tag-region?
\r
217 > + "Change tags for the currently selected thread.
\r
219 > -(defun notmuch-search-add-tag-region (tag beg end)
\r
220 > - (let ((search-id-string (mapconcat 'identity (notmuch-search-find-thread-id-region beg end) " or ")))
\r
221 > - (notmuch-tag search-id-string (concat "+" tag))
\r
222 > - (save-excursion
\r
223 > - (let ((last-line (line-number-at-pos end))
\r
224 > - (max-line (- (line-number-at-pos (point-max)) 2)))
\r
225 > - (goto-char beg)
\r
226 > - (while (<= (line-number-at-pos) (min last-line max-line))
\r
227 > - (notmuch-search-set-tags (delete-dups (sort (cons tag (notmuch-search-get-tags)) 'string<)))
\r
228 > - (forward-line))))))
\r
229 > +See `notmuch-search-tag-region' for details."
\r
230 > + (apply 'notmuch-search-tag-region (point) (point) tags))
\r
232 > -(defun notmuch-search-remove-tag-thread (tag)
\r
233 > - (notmuch-search-remove-tag-region tag (point) (point)))
\r
234 > +(defun notmuch-search-tag-region (beg end &rest tags)
\r
235 > + "Change tags for threads in the given region.
\r
237 > -(defun notmuch-search-remove-tag-region (tag beg end)
\r
238 > - (let ((search-id-string (mapconcat 'identity (notmuch-search-find-thread-id-region beg end) " or ")))
\r
239 > - (notmuch-tag search-id-string (concat "-" tag))
\r
240 > +TAGS is a list of tag operations for `notmuch-tag'. The tags are
\r
241 > +added or removed for all threads in the region from BEG to END."
\r
242 > + (let ((search-string (notmuch-search-find-thread-id-region-search beg end)))
\r
243 > + (apply 'notmuch-tag search-string tags)
\r
245 > (let ((last-line (line-number-at-pos end))
\r
246 > (max-line (- (line-number-at-pos (point-max)) 2)))
\r
248 > (while (<= (line-number-at-pos) (min last-line max-line))
\r
249 > - (notmuch-search-set-tags (delete tag (notmuch-search-get-tags)))
\r
250 > + (notmuch-search-set-tags
\r
251 > + (notmuch-update-tags (notmuch-search-get-tags) tags))
\r
252 > (forward-line))))))
\r
254 > -(defun notmuch-search-add-tag (tag)
\r
255 > - "Add a tag to the currently selected thread or region.
\r
257 > -The tag is added to all messages in the currently selected thread
\r
258 > -or threads in the current region."
\r
260 > - (list (notmuch-select-tag-with-completion "Tag to add: ")))
\r
261 > - (save-excursion
\r
262 > - (if (region-active-p)
\r
263 > - (let* ((beg (region-beginning))
\r
264 > - (end (region-end)))
\r
265 > - (notmuch-search-add-tag-region tag beg end))
\r
266 > - (notmuch-search-add-tag-thread tag))))
\r
268 > -(defun notmuch-search-remove-tag (tag)
\r
269 > - "Remove a tag from the currently selected thread or region.
\r
271 It's great to see all of this old copy-pasted code go away!
\r
273 > +(defun notmuch-search-tag (&optional initial-input)
\r
274 > + "Change tags for the currently selected thread or region."
\r
276 > + (let* ((beg (if (region-active-p) (region-beginning) (point)))
\r
277 > + (end (if (region-active-p) (region-end) (point)))
\r
278 > + (search-string (notmuch-search-find-thread-id-region-search beg end))
\r
279 > + (tags (notmuch-read-tag-changes initial-input search-string)))
\r
280 > + (apply 'notmuch-search-tag-region beg end tags)))
\r
282 > +(defun notmuch-search-add-tag ()
\r
283 > + "Same as `notmuch-search-tag' but sets initial input to '+'."
\r
285 > + (notmuch-search-tag "+"))
\r
287 > -The tag is removed from all messages in the currently selected
\r
288 > -thread or threads in the current region."
\r
290 > - (list (notmuch-select-tag-with-completion
\r
291 > - "Tag to remove: "
\r
292 > - (if (region-active-p)
\r
293 > - (mapconcat 'identity
\r
294 > - (notmuch-search-find-thread-id-region (region-beginning) (region-end))
\r
296 > - (notmuch-search-find-thread-id)))))
\r
297 > - (save-excursion
\r
298 > - (if (region-active-p)
\r
299 > - (let* ((beg (region-beginning))
\r
300 > - (end (region-end)))
\r
301 > - (notmuch-search-remove-tag-region tag beg end))
\r
302 > - (notmuch-search-remove-tag-thread tag))))
\r
303 > +(defun notmuch-search-remove-tag ()
\r
304 > + "Same as `notmuch-search-tag' but sets initial input to '-'."
\r
306 > + (notmuch-search-tag "-"))
\r
308 > (defun notmuch-search-archive-thread ()
\r
309 > "Archive the currently selected thread (remove its \"inbox\" tag).
\r
311 > This function advances the next thread when finished."
\r
313 > - (notmuch-search-remove-tag-thread "inbox")
\r
314 > + (notmuch-search-tag-thread "-inbox")
\r
315 > (notmuch-search-next-thread))
\r
317 > (defvar notmuch-search-process-filter-data nil
\r
318 > @@ -893,9 +895,7 @@ will prompt for tags to be added or removed. Tags prefixed with
\r
319 > Each character of the tag name may consist of alphanumeric
\r
320 > characters as well as `_.+-'.
\r
322 > - (interactive (notmuch-select-tags-with-completion
\r
323 > - "Operations (+add -drop): notmuch tag "
\r
325 > + (interactive (notmuch-read-tag-changes))
\r
326 > (apply 'notmuch-tag notmuch-search-query-string actions))
\r
328 > (defun notmuch-search-buffer-title (query)
\r