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 C47F0429E36
\r
6 for <notmuch@notmuchmail.org>; Wed, 25 Jan 2012 17:48:16 -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 fmkQ864dweL6 for <notmuch@notmuchmail.org>;
\r
17 Wed, 25 Jan 2012 17:48:16 -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 A122D431FBC
\r
22 for <notmuch@notmuchmail.org>; Wed, 25 Jan 2012 17:48:15 -0800 (PST)
\r
23 Received: by bkbzt19 with SMTP id zt19so58492bkb.26
\r
24 for <notmuch@notmuchmail.org>; Wed, 25 Jan 2012 17:48:14 -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:in-reply-to:references:user-agent:date:message-id
\r
27 :mime-version:content-type;
\r
28 bh=cc7FxKkN6l/j5Slz/O1TDbAZncZmvmZbi1uoIifqatQ=;
\r
29 b=JLEt4+8Z2n+XOVcgmNll+kBPJ6+DhOmUxtSD9VXvPh9UiT2e/X8w3INAP6Whl4w0hp
\r
30 odqgD/jmUKqTNeFyhczVfK3wrBB3HESbfi+AezCpipv+sl/FczO+vx8WvJE3YlKwyaI3
\r
31 LUB+T4k8ivrIYzhs9d2MpIv1Kf2og/W7e7Jyo=
\r
32 Received: by 10.204.10.66 with SMTP id o2mr13126bko.104.1327542494267;
\r
33 Wed, 25 Jan 2012 17:48:14 -0800 (PST)
\r
34 Received: from localhost ([91.144.186.21])
\r
35 by mx.google.com with ESMTPS id fb7sm5040552bkc.9.2012.01.25.17.48.13
\r
36 (version=TLSv1/SSLv3 cipher=OTHER);
\r
37 Wed, 25 Jan 2012 17:48:13 -0800 (PST)
\r
38 From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>
\r
39 To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org
\r
40 Subject: Re: [PATCH] emacs: add completion to "tag all" operation ("*"
\r
42 In-Reply-To: <20120126013727.GB1176@mit.edu>
\r
43 References: <1327540351-5249-1-git-send-email-dmitry.kurochkin@gmail.com>
\r
44 <20120126013727.GB1176@mit.edu>
\r
45 User-Agent: Notmuch/0.11+116~ge6e10b8 (http://notmuchmail.org) Emacs/23.3.1
\r
46 (x86_64-pc-linux-gnu)
\r
47 Date: Thu, 26 Jan 2012 05:47:07 +0400
\r
48 Message-ID: <87wr8fqlpg.fsf@gmail.com>
\r
50 Content-Type: text/plain; charset=us-ascii
\r
51 X-BeenThere: notmuch@notmuchmail.org
\r
52 X-Mailman-Version: 2.1.13
\r
54 List-Id: "Use and development of the notmuch mail system."
\r
55 <notmuch.notmuchmail.org>
\r
56 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
57 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
58 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
59 List-Post: <mailto:notmuch@notmuchmail.org>
\r
60 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
61 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
62 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
63 X-List-Received-Date: Thu, 26 Jan 2012 01:48:16 -0000
\r
65 On Wed, 25 Jan 2012 20:37:27 -0500, Austin Clements <amdragon@MIT.EDU> wrote:
\r
66 > Neat. As an aside, I would love to see a prompt like this for + and
\r
67 > -, allowing multiple tags to be modified at once (and starting out
\r
68 > with whichever of + or - got you in to the prompt).
\r
71 Yeah, I was thinking about making "+" and "-" accepting multiple tags
\r
72 using `notmuch-select-tags-with-completion'. But that is for another
\r
75 > Quoth Dmitry Kurochkin on Jan 26 at 5:12 am:
\r
76 > > The patch adds <tab> completion to "tag all" operation bound to "*"
\r
77 > > (`notmuch-search-operate-all' function).
\r
79 > > emacs/notmuch.el | 48 ++++++++++++++++++++++++++++++++++++------------
\r
80 > > 1 files changed, 36 insertions(+), 12 deletions(-)
\r
82 > > diff --git a/emacs/notmuch.el b/emacs/notmuch.el
\r
83 > > index e02966f..71b0221 100644
\r
84 > > --- a/emacs/notmuch.el
\r
85 > > +++ b/emacs/notmuch.el
\r
86 > > @@ -48,6 +48,7 @@
\r
87 > > ;; required, but is available from http://notmuchmail.org).
\r
89 > > (eval-when-compile (require 'cl))
\r
91 > > (require 'mm-view)
\r
92 > > (require 'message)
\r
94 > > @@ -75,12 +76,33 @@ For example:
\r
95 > > (defvar notmuch-query-history nil
\r
96 > > "Variable to store minibuffer history for notmuch queries")
\r
98 > > -(defun notmuch-select-tag-with-completion (prompt &rest search-terms)
\r
99 > > +(defun notmuch-tag-completions (&optional search-terms prefixes)
\r
100 > > (let ((tag-list
\r
101 > > (with-output-to-string
\r
102 > > (with-current-buffer standard-output
\r
103 > > (apply 'call-process notmuch-command nil t nil "search-tags" search-terms)))))
\r
104 > > - (completing-read prompt (split-string tag-list "\n+" t) nil nil nil)))
\r
105 > > + (setq tag-list (split-string tag-list "\n+" t))
\r
106 > > + (if (null prefixes)
\r
108 > > + (apply #'append
\r
109 > > + (mapcar (lambda (tag)
\r
110 > > + (mapcar (lambda (prefix)
\r
111 > > + (concat prefix tag)) prefixes))
\r
112 > > + tag-list)))))
\r
114 > > +(defun notmuch-select-tag-with-completion (prompt &optional search-terms prefixes)
\r
116 > This changes the API of notmuch-select-tag-with-completion in a
\r
117 > non-backwards-compatible way. I'm pretty sure this breaks
\r
118 > notmuch-search-remove-tag and notmuch-show-remove-tag, but I haven't
\r
122 I tested only tag additions. It works, and I assumed tag removal is no
\r
123 different. Will fix.
\r
125 > > + (let ((tag-list (notmuch-tag-completions search-terms prefixes)))
\r
126 > > + (completing-read prompt tag-list)))
\r
128 > > +(defun notmuch-select-tags-with-completion (prompt &optional search-terms prefixes)
\r
129 > > + (let ((tag-list (notmuch-tag-completions search-terms prefixes))
\r
130 > > + (crm-separator " ")
\r
131 > > + (crm-local-completion-map (copy-keymap crm-local-completion-map)))
\r
133 > Alternatively, you could create a child keymap.
\r
134 > crm-local-completion-map is small enough that it probably doesn't
\r
135 > matter, so whatever makes the code clearer.
\r
138 Thanks, I will look into it.
\r
140 > > + ;; By default, space is bound to "complete word" function.
\r
141 > > + ;; Re-bind it to insert a space instead. Note that <tab> still
\r
142 > > + ;; does the completion.
\r
143 > > + (define-key crm-local-completion-map " " 'self-insert-command)
\r
144 > > + (completing-read-multiple prompt tag-list)))
\r
146 > > (defun notmuch-foreach-mime-part (function mm-handle)
\r
147 > > (cond ((stringp (car mm-handle))
\r
148 > > @@ -860,16 +882,18 @@ will prompt for tags to be added or removed. Tags prefixed with
\r
149 > > Each character of the tag name may consist of alphanumeric
\r
150 > > characters as well as `_.+-'.
\r
153 > Technically this changes the API of notmuch-search-operate-all, though
\r
154 > the new one is better. Perhaps it should test for (stringp action)
\r
155 > and be backwards-compatible?
\r
158 In this case, I do not think there are many users of the function. So I
\r
159 would prefer to keep the code clean.
\r
161 > The argument should probably be called "actions" now and it may even
\r
162 > make sense to make it a &rest argument (though then you can't make it
\r
163 > backwards-compatible).
\r
166 Makes sense, will do.
\r
168 > > - (interactive "sOperation (+add -drop): notmuch tag ")
\r
169 > > - (let ((action-split (split-string action " +")))
\r
170 > > - ;; Perform some validation
\r
171 > > - (let ((words action-split))
\r
172 > > - (when (null words) (error "No operation given"))
\r
174 > > - (unless (string-match-p "^[-+][-+_.[:word:]]+$" (car words))
\r
175 > > - (error "Action must be of the form `+thistag -that_tag'"))
\r
176 > > - (setq words (cdr words))))
\r
177 > > - (apply 'notmuch-tag notmuch-search-query-string action-split)))
\r
178 > > + (interactive (list (notmuch-select-tags-with-completion
\r
179 > > + "Operation (+add -drop): notmuch tag " nil
\r
180 > > + '("+" "-"))))
\r
181 > > + (setq action (delete "" action))
\r
182 > > + ;; Perform some validation
\r
183 > > + (let ((words action))
\r
184 > > + (when (null words) (error "No operation given"))
\r
186 > > + (unless (string-match-p "^[-+][-+_.[:word:]]+$" (car words))
\r
187 > > + (error "Action must be of the form `+thistag -that_tag'"))
\r
188 > > + (setq words (cdr words))))
\r
190 > This should really be a mapc or a dolist, but maybe that's for another
\r
194 Yes, I changed "this_tag" spelling in v2, but would prefer to leave
\r
195 non-trivial changes in this code for another patch.
\r
200 > > + (apply 'notmuch-tag notmuch-search-query-string action))
\r
202 > > (defun notmuch-search-buffer-title (query)
\r
203 > > "Returns the title for a buffer with notmuch search results."
\r