From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 8BB40431FAF for ; Wed, 25 Jan 2012 23:05:19 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8qchAPqufW33 for ; Wed, 25 Jan 2012 23:05:18 -0800 (PST) Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU [18.9.25.12]) by olra.theworths.org (Postfix) with ESMTP id A1E75431FAE for ; Wed, 25 Jan 2012 23:05:18 -0800 (PST) X-AuditID: 1209190c-b7fad6d000000920-76-4f20fb2e2445 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP id 61.4D.02336.E2BF02F4; Thu, 26 Jan 2012 02:05:18 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q0Q75IaD023221; Thu, 26 Jan 2012 02:05:18 -0500 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0Q75Gxw007215 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Thu, 26 Jan 2012 02:05:17 -0500 (EST) Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) (envelope-from ) id 1RqJNv-0000nm-Vd; Thu, 26 Jan 2012 02:04:40 -0500 Date: Thu, 26 Jan 2012 02:04:39 -0500 From: Austin Clements To: Dmitry Kurochkin Subject: Re: [PATCH v4] emacs: add completion to "tag all" operation ("*" binding) Message-ID: <20120126070439.GC1940@mit.edu> References: <1327540351-5249-1-git-send-email-dmitry.kurochkin@gmail.com> <1327554400-7616-1-git-send-email-dmitry.kurochkin@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1327554400-7616-1-git-send-email-dmitry.kurochkin@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplleLIzCtJLcpLzFFi42IR4hTV1tX7reBvsOQur8XVrf3sFtdvzmR2 YPLYOesuu8ezVbeYA5iiuGxSUnMyy1KL9O0SuDJunp/GWrBdveLdjDmsDYxr5LsYOTkkBEwk Fv1bxQ5hi0lcuLeerYuRi0NIYB+jxJ77TcwQzgZGiXsXe9ghnJNMEpc2f2KEcJYwSmy6c4YJ pJ9FQFWi9dITRhCbTUBDYtv+5WC2iIChxK2Lr5hBbGYBaYlvv5vB6oUFQiSWrW1mA7F5BbQl Gi6ehNrdySgx/e9JRoiEoMTJmU9YIJq1JG78ewnUzAE2aPk/DpAwp4CXxKXj88F+EBVQkZhy chvbBEahWUi6ZyHpnoXQvYCReRWjbEpulW5uYmZOcWqybnFyYl5eapGuoV5uZoleakrpJkZw aEvy7GB8c1DpEKMAB6MSD+8OIwV/IdbEsuLK3EOMkhxMSqK8/34ChfiS8lMqMxKLM+KLSnNS iw8xSnAwK4nwitkD5XhTEiurUovyYVLSHCxK4rwqWu/8hATSE0tSs1NTC1KLYLIyHBxKErzM v4AaBYtS01Mr0jJzShDSTBycIMN5gIZrgtTwFhck5hZnpkPkTzEqSonzioAkBEASGaV5cL2w 1POKURzoFWFeU5AqHmDagut+BTSYCWjwUl15kMEliQgpqQbGrnNcgqHrgiRelhw4oG6gkfeI nXWG0pG32nHPy1kqqrP0T++LXVtuxrY9e2W52P4uq7t23TI86ypOc/53/8qr+lb99ZGcn5OM xG+5uH23y9Z/Fn/HyXqNV2jUaVdJq4mV/06eUz9Zcv142e7z34UM8l3OnlM9LLZRMfbXTtML zyZbnHH1cnBWYinOSDTUYi4qTgQAoyaTmhgDAAA= Cc: notmuch@notmuchmail.org X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Jan 2012 07:05:19 -0000 Quoth Dmitry Kurochkin on Jan 26 at 9:06 am: > The patch adds completion to "tag all" operation bound to "*" > (`notmuch-search-operate-all' function). > --- > > On a second thought, `notmuch-select-tag-with-completion' should never > need `prefixes' argument at all. So I reverted the API and related > changes. > > Changes: > > v4: > > * do not change `notmuch-select-tag-with-completion' API, revert > related changes > > v3: > > * fixed comments from Austin's review [1] > > v2: > > * s/thistag/this_tag/ for consistency with "that_tag", since we touch > the line anyway > > Regards, > Dmitry > > [1] id:"20120126013727.GB1176@mit.edu" > > emacs/notmuch.el | 53 ++++++++++++++++++++++++++++++++++++++++------------- > 1 files changed, 40 insertions(+), 13 deletions(-) > > diff --git a/emacs/notmuch.el b/emacs/notmuch.el > index e02966f..d2af630 100644 > --- a/emacs/notmuch.el > +++ b/emacs/notmuch.el > @@ -48,6 +48,7 @@ > ;; required, but is available from http://notmuchmail.org). > > (eval-when-compile (require 'cl)) > +(require 'crm) > (require 'mm-view) > (require 'message) > > @@ -75,12 +76,36 @@ For example: > (defvar notmuch-query-history nil > "Variable to store minibuffer history for notmuch queries") > > -(defun notmuch-select-tag-with-completion (prompt &rest search-terms) > +(defun notmuch-tag-completions (&optional prefixes search-terms) > (let ((tag-list > (with-output-to-string > (with-current-buffer standard-output > (apply 'call-process notmuch-command nil t nil "search-tags" search-terms))))) > - (completing-read prompt (split-string tag-list "\n+" t) nil nil nil))) > + (setq tag-list (split-string tag-list "\n+" t)) Since this setq is unconditional, you can do the split-string right in the let binding, around the with-output-to-string. > + (if (null prefixes) > + tag-list > + (apply #'append > + (mapcar (lambda (tag) > + (mapcar (lambda (prefix) > + (concat prefix tag)) prefixes)) > + tag-list))))) > + > +(defun notmuch-select-tag-with-completion (prompt &rest search-terms) > + (let ((tag-list (notmuch-tag-completions nil search-terms))) > + (completing-read prompt tag-list))) > + > +(defun notmuch-select-tags-with-completion (prompt &optional prefixes &rest search-terms) > + (let ((tag-list (notmuch-tag-completions prefixes search-terms)) > + (crm-separator " ") > + (crm-local-completion-map > + (let ((map (make-sparse-keymap))) > + (set-keymap-parent map crm-local-completion-map) > + map))) > + ;; By default, space is bound to "complete word" function. > + ;; Re-bind it to insert a space instead. Note that still > + ;; does the completion. > + (define-key crm-local-completion-map " " 'self-insert-command) You could do the define-key inside the (let ((map ..)) ..) so you get back the fully formed keymap. Your call. > + (completing-read-multiple prompt tag-list))) > > (defun notmuch-foreach-mime-part (function mm-handle) > (cond ((stringp (car mm-handle)) > @@ -849,7 +874,7 @@ non-authors is found, assume that all of the authors match." > (goto-char found-target))) > (delete-process proc)))) > > -(defun notmuch-search-operate-all (action) > +(defun notmuch-search-operate-all (&rest actions) > "Add/remove tags from all matching messages. > > This command adds or removes tags from all messages matching the > @@ -860,16 +885,18 @@ will prompt for tags to be added or removed. Tags prefixed with > Each character of the tag name may consist of alphanumeric > characters as well as `_.+-'. > " > - (interactive "sOperation (+add -drop): notmuch tag ") > - (let ((action-split (split-string action " +"))) > - ;; Perform some validation > - (let ((words action-split)) > - (when (null words) (error "No operation given")) > - (while words > - (unless (string-match-p "^[-+][-+_.[:word:]]+$" (car words)) > - (error "Action must be of the form `+thistag -that_tag'")) > - (setq words (cdr words)))) > - (apply 'notmuch-tag notmuch-search-query-string action-split))) > + (interactive (notmuch-select-tags-with-completion > + "Operations (+add -drop): notmuch tag " > + '("+" "-"))) > + (setq actions (delete "" actions)) Either this line isn't necessary or notmuch-select-tags-with-completion can do something funny that it should take care of internally. > + ;; Perform some validation > + (let ((words actions)) > + (when (null words) (error "No operations given")) > + (while words > + (unless (string-match-p "^[-+][-+_.[:word:]]+$" (car words)) > + (error "Action must be of the form `+this_tag' or `-that_tag'")) > + (setq words (cdr words)))) > + (apply 'notmuch-tag notmuch-search-query-string actions)) > > (defun notmuch-search-buffer-title (query) > "Returns the title for a buffer with notmuch search results."