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 3FE8C431FAF
\r
6 for <notmuch@notmuchmail.org>; Wed, 25 Jan 2012 21:07:51 -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 l6T-2TCCV5FX for <notmuch@notmuchmail.org>;
\r
17 Wed, 25 Jan 2012 21:07:50 -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 09C6E431FAE
\r
22 for <notmuch@notmuchmail.org>; Wed, 25 Jan 2012 21:07:49 -0800 (PST)
\r
23 Received: by bkbzt19 with SMTP id zt19so168189bkb.26
\r
24 for <notmuch@notmuchmail.org>; Wed, 25 Jan 2012 21:07:47 -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=a+VEpFXRmFOJOGj+q4Vc7l/AG19vozRZwwJFUXKvM3c=;
\r
28 b=Rx3Vczr94gwLtR91dlFWyJE7Vd6P3aeiW0WENIsv8bNqY/ynBrpXTqa7AdDau3aZG9
\r
29 q6gYJ7hRop+jo8fAwtvtKxt+DNXLyutMPsD1+zXZZ8Ub6EYgG3sL5shlBbx45RNklKtI
\r
30 KX33OcbLbBiyXpZkU9M7dx74BGD6vNBdsI0Cg=
\r
31 Received: by 10.204.129.203 with SMTP id p11mr248770bks.109.1327554467184;
\r
32 Wed, 25 Jan 2012 21:07:47 -0800 (PST)
\r
33 Received: from localhost ([91.144.186.21])
\r
34 by mx.google.com with ESMTPS id ga13sm6079069bkc.5.2012.01.25.21.07.45
\r
35 (version=TLSv1/SSLv3 cipher=OTHER);
\r
36 Wed, 25 Jan 2012 21:07:46 -0800 (PST)
\r
37 From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>
\r
38 To: notmuch@notmuchmail.org
\r
39 Subject: [PATCH v4] emacs: add completion to "tag all" operation ("*" binding)
\r
40 Date: Thu, 26 Jan 2012 09:06:40 +0400
\r
41 Message-Id: <1327554400-7616-1-git-send-email-dmitry.kurochkin@gmail.com>
\r
42 X-Mailer: git-send-email 1.7.8.3
\r
43 In-Reply-To: <1327540351-5249-1-git-send-email-dmitry.kurochkin@gmail.com>
\r
44 References: <1327540351-5249-1-git-send-email-dmitry.kurochkin@gmail.com>
\r
45 X-BeenThere: notmuch@notmuchmail.org
\r
46 X-Mailman-Version: 2.1.13
\r
48 List-Id: "Use and development of the notmuch mail system."
\r
49 <notmuch.notmuchmail.org>
\r
50 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
51 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
52 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
53 List-Post: <mailto:notmuch@notmuchmail.org>
\r
54 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
55 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
56 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
57 X-List-Received-Date: Thu, 26 Jan 2012 05:07:51 -0000
\r
59 The patch adds <tab> completion to "tag all" operation bound to "*"
\r
60 (`notmuch-search-operate-all' function).
\r
63 On a second thought, `notmuch-select-tag-with-completion' should never
\r
64 need `prefixes' argument at all. So I reverted the API and related
\r
71 * do not change `notmuch-select-tag-with-completion' API, revert
\r
76 * fixed comments from Austin's review [1]
\r
80 * s/thistag/this_tag/ for consistency with "that_tag", since we touch
\r
86 [1] id:"20120126013727.GB1176@mit.edu"
\r
88 emacs/notmuch.el | 53 ++++++++++++++++++++++++++++++++++++++++-------------
\r
89 1 files changed, 40 insertions(+), 13 deletions(-)
\r
91 diff --git a/emacs/notmuch.el b/emacs/notmuch.el
\r
92 index e02966f..d2af630 100644
\r
93 --- a/emacs/notmuch.el
\r
94 +++ b/emacs/notmuch.el
\r
96 ;; required, but is available from http://notmuchmail.org).
\r
98 (eval-when-compile (require 'cl))
\r
103 @@ -75,12 +76,36 @@ For example:
\r
104 (defvar notmuch-query-history nil
\r
105 "Variable to store minibuffer history for notmuch queries")
\r
107 -(defun notmuch-select-tag-with-completion (prompt &rest search-terms)
\r
108 +(defun notmuch-tag-completions (&optional prefixes search-terms)
\r
110 (with-output-to-string
\r
111 (with-current-buffer standard-output
\r
112 (apply 'call-process notmuch-command nil t nil "search-tags" search-terms)))))
\r
113 - (completing-read prompt (split-string tag-list "\n+" t) nil nil nil)))
\r
114 + (setq tag-list (split-string tag-list "\n+" t))
\r
115 + (if (null prefixes)
\r
118 + (mapcar (lambda (tag)
\r
119 + (mapcar (lambda (prefix)
\r
120 + (concat prefix tag)) prefixes))
\r
123 +(defun notmuch-select-tag-with-completion (prompt &rest search-terms)
\r
124 + (let ((tag-list (notmuch-tag-completions nil search-terms)))
\r
125 + (completing-read prompt tag-list)))
\r
127 +(defun notmuch-select-tags-with-completion (prompt &optional prefixes &rest search-terms)
\r
128 + (let ((tag-list (notmuch-tag-completions prefixes search-terms))
\r
129 + (crm-separator " ")
\r
130 + (crm-local-completion-map
\r
131 + (let ((map (make-sparse-keymap)))
\r
132 + (set-keymap-parent map crm-local-completion-map)
\r
134 + ;; By default, space is bound to "complete word" function.
\r
135 + ;; Re-bind it to insert a space instead. Note that <tab> still
\r
136 + ;; does the completion.
\r
137 + (define-key crm-local-completion-map " " 'self-insert-command)
\r
138 + (completing-read-multiple prompt tag-list)))
\r
140 (defun notmuch-foreach-mime-part (function mm-handle)
\r
141 (cond ((stringp (car mm-handle))
\r
142 @@ -849,7 +874,7 @@ non-authors is found, assume that all of the authors match."
\r
143 (goto-char found-target)))
\r
144 (delete-process proc))))
\r
146 -(defun notmuch-search-operate-all (action)
\r
147 +(defun notmuch-search-operate-all (&rest actions)
\r
148 "Add/remove tags from all matching messages.
\r
150 This command adds or removes tags from all messages matching the
\r
151 @@ -860,16 +885,18 @@ will prompt for tags to be added or removed. Tags prefixed with
\r
152 Each character of the tag name may consist of alphanumeric
\r
153 characters as well as `_.+-'.
\r
155 - (interactive "sOperation (+add -drop): notmuch tag ")
\r
156 - (let ((action-split (split-string action " +")))
\r
157 - ;; Perform some validation
\r
158 - (let ((words action-split))
\r
159 - (when (null words) (error "No operation given"))
\r
161 - (unless (string-match-p "^[-+][-+_.[:word:]]+$" (car words))
\r
162 - (error "Action must be of the form `+thistag -that_tag'"))
\r
163 - (setq words (cdr words))))
\r
164 - (apply 'notmuch-tag notmuch-search-query-string action-split)))
\r
165 + (interactive (notmuch-select-tags-with-completion
\r
166 + "Operations (+add -drop): notmuch tag "
\r
168 + (setq actions (delete "" actions))
\r
169 + ;; Perform some validation
\r
170 + (let ((words actions))
\r
171 + (when (null words) (error "No operations given"))
\r
173 + (unless (string-match-p "^[-+][-+_.[:word:]]+$" (car words))
\r
174 + (error "Action must be of the form `+this_tag' or `-that_tag'"))
\r
175 + (setq words (cdr words))))
\r
176 + (apply 'notmuch-tag notmuch-search-query-string actions))
\r
178 (defun notmuch-search-buffer-title (query)
\r
179 "Returns the title for a buffer with notmuch search results."
\r