1 Return-Path: <dmitry.kurochkin@gmail.com>
\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 21F58429E34
\r
6 for <notmuch@notmuchmail.org>; Sun, 29 Jan 2012 18:27:48 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5
\r
12 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
\r
13 FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] 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 Dltnf7qenUNe for <notmuch@notmuchmail.org>;
\r
17 Sun, 29 Jan 2012 18:27:44 -0800 (PST)
\r
18 Received: from mail-bk0-f53.google.com (mail-bk0-f53.google.com
\r
19 [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id A214B429E49
\r
22 for <notmuch@notmuchmail.org>; Sun, 29 Jan 2012 18:27:41 -0800 (PST)
\r
23 Received: by mail-bk0-f53.google.com with SMTP id 11so960274bke.26
\r
24 for <notmuch@notmuchmail.org>; Sun, 29 Jan 2012 18:27:41 -0800 (PST)
\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;
\r
26 h=from:to:subject:date:message-id:x-mailer:in-reply-to:references;
\r
27 bh=XsLEVwRpCRbtcTWssSF7LuFHmmS+F3wmSThf4Pwcqao=;
\r
28 b=EwYemo/IHPa7tnmDiWCuEd//tXPdevrUasJ4JTNxnrDBUB+HDpz6HFkI1OcfxEEFM0
\r
29 6nH0dcF9hHPWjRgxjZxmgIwNSc9AQ0JuyKJuD+VXml7SrpICJG6d0c8lnR3IxhLCssQv
\r
30 U6kvjFGjfdocUhyj8mWOCtVkjeiUHwrx96sGM=
\r
31 Received: by 10.204.152.206 with SMTP id h14mr7458140bkw.62.1327890461366;
\r
32 Sun, 29 Jan 2012 18:27:41 -0800 (PST)
\r
33 Received: from localhost ([91.144.186.21])
\r
34 by mx.google.com with ESMTPS id x20sm19030783bka.9.2012.01.29.18.27.40
\r
35 (version=TLSv1/SSLv3 cipher=OTHER);
\r
36 Sun, 29 Jan 2012 18:27:40 -0800 (PST)
\r
37 From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>
\r
38 To: notmuch@notmuchmail.org
\r
39 Subject: [PATCH v2 03/13] emacs: make "+" and "-" tagging operations in
\r
40 notmuch-search more robust
\r
41 Date: Mon, 30 Jan 2012 06:26:12 +0400
\r
42 Message-Id: <1327890382-548-4-git-send-email-dmitry.kurochkin@gmail.com>
\r
43 X-Mailer: git-send-email 1.7.8.3
\r
44 In-Reply-To: <1327890382-548-1-git-send-email-dmitry.kurochkin@gmail.com>
\r
45 References: <1327725684-5887-1-git-send-email-dmitry.kurochkin@gmail.com>
\r
46 <1327890382-548-1-git-send-email-dmitry.kurochkin@gmail.com>
\r
47 X-BeenThere: notmuch@notmuchmail.org
\r
48 X-Mailman-Version: 2.1.13
\r
50 List-Id: "Use and development of the notmuch mail system."
\r
51 <notmuch.notmuchmail.org>
\r
52 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
53 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
54 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
55 List-Post: <mailto:notmuch@notmuchmail.org>
\r
56 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
57 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
58 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
59 X-List-Received-Date: Mon, 30 Jan 2012 02:27:48 -0000
\r
61 Before the change, "+" and "-" tagging operations in notmuch-search
\r
62 view accepted only a single tag. The patch makes them use the
\r
63 recently added `notmuch-read-tag-changes' function (renamed
\r
64 `notmuch-select-tags-with-completion'), which allows to enter multiple
\r
65 tags with "+" and "-" prefixes. So after the change, "+" and "-"
\r
66 bindings in notmuch-search view allow to both add and remove multiple
\r
67 tags. The only difference between "+" and "-" is the minibuffer
\r
68 initial input ("+" and "-" respectively).
\r
70 emacs/notmuch.el | 164 +++++++++++++++++++++++++++---------------------------
\r
71 1 files changed, 82 insertions(+), 82 deletions(-)
\r
73 diff --git a/emacs/notmuch.el b/emacs/notmuch.el
\r
74 index ff46617..90b594c 100644
\r
75 --- a/emacs/notmuch.el
\r
76 +++ b/emacs/notmuch.el
\r
77 @@ -76,38 +76,57 @@ For example:
\r
78 (defvar notmuch-query-history nil
\r
79 "Variable to store minibuffer history for notmuch queries")
\r
81 -(defun notmuch-tag-completions (&optional prefixes search-terms)
\r
84 - (with-output-to-string
\r
85 - (with-current-buffer standard-output
\r
86 - (apply 'call-process notmuch-command nil t
\r
87 - nil "search-tags" search-terms)))
\r
89 - (if (null prefixes)
\r
92 - (mapcar (lambda (tag)
\r
93 - (mapcar (lambda (prefix)
\r
94 - (concat prefix tag)) prefixes))
\r
96 +(defun notmuch-tag-completions (&optional search-terms)
\r
98 + (with-output-to-string
\r
99 + (with-current-buffer standard-output
\r
100 + (apply 'call-process notmuch-command nil t
\r
101 + nil "search-tags" search-terms)))
\r
104 (defun notmuch-select-tag-with-completion (prompt &rest search-terms)
\r
105 - (let ((tag-list (notmuch-tag-completions nil search-terms)))
\r
106 + (let ((tag-list (notmuch-tag-completions search-terms)))
\r
107 (completing-read prompt tag-list)))
\r
109 -(defun notmuch-select-tags-with-completion (prompt &optional prefixes &rest search-terms)
\r
110 - (let ((tag-list (notmuch-tag-completions prefixes search-terms))
\r
111 - (crm-separator " ")
\r
112 - ;; By default, space is bound to "complete word" function.
\r
113 - ;; Re-bind it to insert a space instead. Note that <tab>
\r
114 - ;; still does the completion.
\r
115 - (crm-local-completion-map
\r
116 - (let ((map (make-sparse-keymap)))
\r
117 - (set-keymap-parent map crm-local-completion-map)
\r
118 - (define-key map " " 'self-insert-command)
\r
120 - (delete "" (completing-read-multiple prompt tag-list))))
\r
121 +(defun notmuch-read-tag-changes (&optional initial-input &rest search-terms)
\r
122 + (let* ((all-tag-list (notmuch-tag-completions))
\r
123 + (add-tag-list (mapcar (apply-partially 'concat "+") all-tag-list))
\r
124 + (remove-tag-list (mapcar (apply-partially 'concat "-")
\r
125 + (if (null search-terms)
\r
127 + (notmuch-tag-completions search-terms))))
\r
128 + (tag-list (append add-tag-list remove-tag-list))
\r
129 + (crm-separator " ")
\r
130 + ;; By default, space is bound to "complete word" function.
\r
131 + ;; Re-bind it to insert a space instead. Note that <tab>
\r
132 + ;; still does the completion.
\r
133 + (crm-local-completion-map
\r
134 + (let ((map (make-sparse-keymap)))
\r
135 + (set-keymap-parent map crm-local-completion-map)
\r
136 + (define-key map " " 'self-insert-command)
\r
138 + (delete "" (completing-read-multiple "Tags (+add -drop): "
\r
139 + tag-list nil nil initial-input))))
\r
141 +(defun notmuch-update-tags (tags tag-changes)
\r
142 + "Return a copy of TAGS with additions and removals from TAG-CHANGES.
\r
144 +TAG-CHANGES must be a list of tags names, each prefixed with
\r
145 +either a \"+\" to indicate the tag should be added to TAGS if not
\r
146 +present or a \"-\" to indicate that the tag should be removed
\r
147 +from TAGS if present."
\r
148 + (let ((result-tags (copy-sequence tags)))
\r
149 + (dolist (tag-change tag-changes)
\r
150 + (unless (string= tag-change "")
\r
151 + (let ((op (string-to-char tag-change))
\r
152 + (tag (substring tag-change 1)))
\r
154 + (?+ (unless (member tag result-tags)
\r
155 + (push tag result-tags)))
\r
156 + (?- (setq result-tags (delete tag result-tags)))
\r
158 + (error "Changed tag must be of the form `+this_tag' or `-that_tag'"))))))
\r
159 + (sort result-tags 'string<)))
\r
161 (defun notmuch-foreach-mime-part (function mm-handle)
\r
162 (cond ((stringp (car mm-handle))
\r
163 @@ -447,6 +466,10 @@ Complete list of currently available key bindings:
\r
164 "Return a list of threads for the current region"
\r
165 (notmuch-search-properties-in-region 'notmuch-search-thread-id beg end))
\r
167 +(defun notmuch-search-find-thread-id-region-search (beg end)
\r
168 + "Return a search string for threads for the current region"
\r
169 + (mapconcat 'identity (notmuch-search-find-thread-id-region beg end) " or "))
\r
171 (defun notmuch-search-find-authors ()
\r
172 "Return the authors for the current thread"
\r
173 (get-text-property (point) 'notmuch-search-authors))
\r
174 @@ -590,74 +613,53 @@ the messages that were tagged"
\r
178 -(defun notmuch-search-add-tag-thread (tag)
\r
179 - (notmuch-search-add-tag-region tag (point) (point)))
\r
180 +(defun notmuch-search-tag-thread (&rest tags)
\r
181 + "Change tags for the currently selected thread.
\r
183 -(defun notmuch-search-add-tag-region (tag beg end)
\r
184 - (let ((search-id-string (mapconcat 'identity (notmuch-search-find-thread-id-region beg end) " or ")))
\r
185 - (notmuch-tag search-id-string (concat "+" tag))
\r
187 - (let ((last-line (line-number-at-pos end))
\r
188 - (max-line (- (line-number-at-pos (point-max)) 2)))
\r
190 - (while (<= (line-number-at-pos) (min last-line max-line))
\r
191 - (notmuch-search-set-tags (delete-dups (sort (cons tag (notmuch-search-get-tags)) 'string<)))
\r
192 - (forward-line))))))
\r
193 +See `notmuch-search-tag-region' for details."
\r
194 + (apply 'notmuch-search-tag-region (point) (point) tags))
\r
196 -(defun notmuch-search-remove-tag-thread (tag)
\r
197 - (notmuch-search-remove-tag-region tag (point) (point)))
\r
198 +(defun notmuch-search-tag-region (beg end &rest tags)
\r
199 + "Change tags for threads in the given region.
\r
201 -(defun notmuch-search-remove-tag-region (tag beg end)
\r
202 - (let ((search-id-string (mapconcat 'identity (notmuch-search-find-thread-id-region beg end) " or ")))
\r
203 - (notmuch-tag search-id-string (concat "-" tag))
\r
204 +TAGS is a list of tag operations for `notmuch-tag'. The tags are
\r
205 +added or removed for all threads in the region from BEG to END."
\r
206 + (let ((search-string (notmuch-search-find-thread-id-region-search beg end)))
\r
207 + (apply 'notmuch-tag search-string tags)
\r
209 (let ((last-line (line-number-at-pos end))
\r
210 (max-line (- (line-number-at-pos (point-max)) 2)))
\r
212 (while (<= (line-number-at-pos) (min last-line max-line))
\r
213 - (notmuch-search-set-tags (delete tag (notmuch-search-get-tags)))
\r
214 + (notmuch-search-set-tags
\r
215 + (notmuch-update-tags (notmuch-search-get-tags) tags))
\r
216 (forward-line))))))
\r
218 -(defun notmuch-search-add-tag (tag)
\r
219 - "Add a tag to the currently selected thread or region.
\r
221 -The tag is added to all messages in the currently selected thread
\r
222 -or threads in the current region."
\r
224 - (list (notmuch-select-tag-with-completion "Tag to add: ")))
\r
226 - (if (region-active-p)
\r
227 - (let* ((beg (region-beginning))
\r
228 - (end (region-end)))
\r
229 - (notmuch-search-add-tag-region tag beg end))
\r
230 - (notmuch-search-add-tag-thread tag))))
\r
232 -(defun notmuch-search-remove-tag (tag)
\r
233 - "Remove a tag from the currently selected thread or region.
\r
234 +(defun notmuch-search-tag (&optional initial-input)
\r
235 + "Change tags for the currently selected thread or region."
\r
237 + (let* ((beg (if (region-active-p) (region-beginning) (point)))
\r
238 + (end (if (region-active-p) (region-end) (point)))
\r
239 + (search-string (notmuch-search-find-thread-id-region-search beg end))
\r
240 + (tags (notmuch-read-tag-changes initial-input search-string)))
\r
241 + (apply 'notmuch-search-tag-region beg end tags)))
\r
243 +(defun notmuch-search-add-tag ()
\r
244 + "Same as `notmuch-search-tag' but sets initial input to '+'."
\r
246 + (notmuch-search-tag "+"))
\r
248 -The tag is removed from all messages in the currently selected
\r
249 -thread or threads in the current region."
\r
251 - (list (notmuch-select-tag-with-completion
\r
252 - "Tag to remove: "
\r
253 - (if (region-active-p)
\r
254 - (mapconcat 'identity
\r
255 - (notmuch-search-find-thread-id-region (region-beginning) (region-end))
\r
257 - (notmuch-search-find-thread-id)))))
\r
259 - (if (region-active-p)
\r
260 - (let* ((beg (region-beginning))
\r
261 - (end (region-end)))
\r
262 - (notmuch-search-remove-tag-region tag beg end))
\r
263 - (notmuch-search-remove-tag-thread tag))))
\r
264 +(defun notmuch-search-remove-tag ()
\r
265 + "Same as `notmuch-search-tag' but sets initial input to '-'."
\r
267 + (notmuch-search-tag "-"))
\r
269 (defun notmuch-search-archive-thread ()
\r
270 "Archive the currently selected thread (remove its \"inbox\" tag).
\r
272 This function advances the next thread when finished."
\r
274 - (notmuch-search-remove-tag-thread "inbox")
\r
275 + (notmuch-search-tag-thread "-inbox")
\r
276 (notmuch-search-next-thread))
\r
278 (defvar notmuch-search-process-filter-data nil
\r
279 @@ -893,9 +895,7 @@ will prompt for tags to be added or removed. Tags prefixed with
\r
280 Each character of the tag name may consist of alphanumeric
\r
281 characters as well as `_.+-'.
\r
283 - (interactive (notmuch-select-tags-with-completion
\r
284 - "Operations (+add -drop): notmuch tag "
\r
286 + (interactive (notmuch-read-tag-changes))
\r
287 (apply 'notmuch-tag notmuch-search-query-string actions))
\r
289 (defun notmuch-search-buffer-title (query)
\r