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 5743F431FAF
\r
6 for <notmuch@notmuchmail.org>; Wed, 25 Jan 2012 18:46:21 -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 eVlZHLhR8EyI for <notmuch@notmuchmail.org>;
\r
17 Wed, 25 Jan 2012 18:46:20 -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 366B6431FAE
\r
22 for <notmuch@notmuchmail.org>; Wed, 25 Jan 2012 18:46:20 -0800 (PST)
\r
23 Received: by bkbzt19 with SMTP id zt19so92251bkb.26
\r
24 for <notmuch@notmuchmail.org>; Wed, 25 Jan 2012 18:46:18 -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=UNvhxVoM5IGvXycrX8QL5mC1md562khPLwutApwzDFg=;
\r
28 b=YlkMgjxvP4NS9ozqRrQWoMBCXbPdHkBDus2lvVVp+XeUnUu7Lvu4AnJfAljgjCOfrR
\r
29 4SrAdzJq8dTPDzDoh5OngopMH+025f220IhuIkzIUSNYBq8f6niyt5HSb8rM0IyxK0kr
\r
30 8iES0AvRwVp1FeBGLInze9woKT6T8Y4YlhIHE=
\r
31 Received: by 10.204.130.28 with SMTP id q28mr131388bks.10.1327545978824;
\r
32 Wed, 25 Jan 2012 18:46:18 -0800 (PST)
\r
33 Received: from localhost ([91.144.186.21])
\r
34 by mx.google.com with ESMTPS id ek9sm5324251bkb.10.2012.01.25.18.46.17
\r
35 (version=TLSv1/SSLv3 cipher=OTHER);
\r
36 Wed, 25 Jan 2012 18:46:18 -0800 (PST)
\r
37 From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>
\r
38 To: notmuch@notmuchmail.org
\r
39 Subject: [PATCH v3] emacs: add completion to "tag all" operation ("*" binding)
\r
40 Date: Thu, 26 Jan 2012 06:45:12 +0400
\r
41 Message-Id: <1327545912-16754-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 02:46:21 -0000
\r
59 The patch adds <tab> completion to "tag all" operation bound to "*"
\r
60 (`notmuch-search-operate-all' function).
\r
67 * fixed comments from Austin's review [1]
\r
71 * s/thistag/this_tag/ for consistency with "that_tag", since we touch
\r
77 [1] id:"20120126013727.GB1176@mit.edu"
\r
79 emacs/notmuch-show.el | 4 +-
\r
80 emacs/notmuch.el | 55 ++++++++++++++++++++++++++++++++++++------------
\r
81 2 files changed, 43 insertions(+), 16 deletions(-)
\r
83 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
\r
84 index e6a5b31..b23a981 100644
\r
85 --- a/emacs/notmuch-show.el
\r
86 +++ b/emacs/notmuch-show.el
\r
89 (declare-function notmuch-call-notmuch-process "notmuch" (&rest args))
\r
90 (declare-function notmuch-fontify-headers "notmuch" nil)
\r
91 -(declare-function notmuch-select-tag-with-completion "notmuch" (prompt &rest search-terms))
\r
92 +(declare-function notmuch-select-tag-with-completion "notmuch" (prompt &optional prefixes &rest search-terms))
\r
93 (declare-function notmuch-search-show-thread "notmuch" nil)
\r
95 (defcustom notmuch-message-headers '("Subject" "To" "Cc" "Date")
\r
96 @@ -1474,7 +1474,7 @@ the result."
\r
97 "Remove a tag from the current message."
\r
99 (list (notmuch-select-tag-with-completion
\r
100 - "Tag to remove: " (notmuch-show-get-message-id))))
\r
101 + "Tag to remove: " nil (notmuch-show-get-message-id))))
\r
103 (let* ((current-tags (notmuch-show-get-tags))
\r
104 (new-tags (notmuch-show-del-tags-worker current-tags toremove)))
\r
105 diff --git a/emacs/notmuch.el b/emacs/notmuch.el
\r
106 index e02966f..ba8f8e1 100644
\r
107 --- a/emacs/notmuch.el
\r
108 +++ b/emacs/notmuch.el
\r
110 ;; required, but is available from http://notmuchmail.org).
\r
112 (eval-when-compile (require 'cl))
\r
117 @@ -75,12 +76,36 @@ For example:
\r
118 (defvar notmuch-query-history nil
\r
119 "Variable to store minibuffer history for notmuch queries")
\r
121 -(defun notmuch-select-tag-with-completion (prompt &rest search-terms)
\r
122 +(defun notmuch-tag-completions (&optional prefixes search-terms)
\r
124 (with-output-to-string
\r
125 (with-current-buffer standard-output
\r
126 (apply 'call-process notmuch-command nil t nil "search-tags" search-terms)))))
\r
127 - (completing-read prompt (split-string tag-list "\n+" t) nil nil nil)))
\r
128 + (setq tag-list (split-string tag-list "\n+" t))
\r
129 + (if (null prefixes)
\r
132 + (mapcar (lambda (tag)
\r
133 + (mapcar (lambda (prefix)
\r
134 + (concat prefix tag)) prefixes))
\r
137 +(defun notmuch-select-tag-with-completion (prompt &optional prefixes &rest search-terms)
\r
138 + (let ((tag-list (notmuch-tag-completions prefixes search-terms)))
\r
139 + (completing-read prompt tag-list)))
\r
141 +(defun notmuch-select-tags-with-completion (prompt &optional prefixes &rest search-terms)
\r
142 + (let ((tag-list (notmuch-tag-completions prefixes search-terms))
\r
143 + (crm-separator " ")
\r
144 + (crm-local-completion-map
\r
145 + (let ((map (make-sparse-keymap)))
\r
146 + (set-keymap-parent map crm-local-completion-map)
\r
148 + ;; By default, space is bound to "complete word" function.
\r
149 + ;; Re-bind it to insert a space instead. Note that <tab> still
\r
150 + ;; does the completion.
\r
151 + (define-key crm-local-completion-map " " 'self-insert-command)
\r
152 + (completing-read-multiple prompt tag-list)))
\r
154 (defun notmuch-foreach-mime-part (function mm-handle)
\r
155 (cond ((stringp (car mm-handle))
\r
156 @@ -606,7 +631,7 @@ The tag is removed from all messages in the currently selected
\r
157 thread or threads in the current region."
\r
159 (list (notmuch-select-tag-with-completion
\r
160 - "Tag to remove: "
\r
161 + "Tag to remove: " nil
\r
162 (if (region-active-p)
\r
163 (mapconcat 'identity
\r
164 (notmuch-search-find-thread-id-region (region-beginning) (region-end))
\r
165 @@ -849,7 +874,7 @@ non-authors is found, assume that all of the authors match."
\r
166 (goto-char found-target)))
\r
167 (delete-process proc))))
\r
169 -(defun notmuch-search-operate-all (action)
\r
170 +(defun notmuch-search-operate-all (&rest actions)
\r
171 "Add/remove tags from all matching messages.
\r
173 This command adds or removes tags from all messages matching the
\r
174 @@ -860,16 +885,18 @@ will prompt for tags to be added or removed. Tags prefixed with
\r
175 Each character of the tag name may consist of alphanumeric
\r
176 characters as well as `_.+-'.
\r
178 - (interactive "sOperation (+add -drop): notmuch tag ")
\r
179 - (let ((action-split (split-string action " +")))
\r
180 - ;; Perform some validation
\r
181 - (let ((words action-split))
\r
182 - (when (null words) (error "No operation given"))
\r
184 - (unless (string-match-p "^[-+][-+_.[:word:]]+$" (car words))
\r
185 - (error "Action must be of the form `+thistag -that_tag'"))
\r
186 - (setq words (cdr words))))
\r
187 - (apply 'notmuch-tag notmuch-search-query-string action-split)))
\r
188 + (interactive (notmuch-select-tags-with-completion
\r
189 + "Operations (+add -drop): notmuch tag "
\r
191 + (setq actions (delete "" actions))
\r
192 + ;; Perform some validation
\r
193 + (let ((words actions))
\r
194 + (when (null words) (error "No operations given"))
\r
196 + (unless (string-match-p "^[-+][-+_.[:word:]]+$" (car words))
\r
197 + (error "Action must be of the form `+this_tag' or `-that_tag'"))
\r
198 + (setq words (cdr words))))
\r
199 + (apply 'notmuch-tag notmuch-search-query-string actions))
\r
201 (defun notmuch-search-buffer-title (query)
\r
202 "Returns the title for a buffer with notmuch search results."
\r