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 2577D429E36 for ; Wed, 25 Jan 2012 17:38:07 -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 ShWWM3SZU-Ag for ; Wed, 25 Jan 2012 17:38:06 -0800 (PST) Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU [18.9.25.14]) by olra.theworths.org (Postfix) with ESMTP id 22430431FBC for ; Wed, 25 Jan 2012 17:38:06 -0800 (PST) X-AuditID: 1209190e-b7f7c6d0000008c3-2c-4f20ae7dadc8 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP id 6E.74.02243.D7EA02F4; Wed, 25 Jan 2012 20:38:05 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q0Q1c4iE020042; Wed, 25 Jan 2012 20:38:05 -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 q0Q1c3Zh004019 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Wed, 25 Jan 2012 20:38:04 -0500 (EST) Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) (envelope-from ) id 1RqEHH-0000To-Lo; Wed, 25 Jan 2012 20:37:27 -0500 Date: Wed, 25 Jan 2012 20:37:27 -0500 From: Austin Clements To: Dmitry Kurochkin Subject: Re: [PATCH] emacs: add completion to "tag all" operation ("*" binding) Message-ID: <20120126013727.GB1176@mit.edu> References: <1327540351-5249-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: <1327540351-5249-1-git-send-email-dmitry.kurochkin@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpileLIzCtJLcpLzFFi42IRYrdT161dp+BvcPyvusXVrf3sFtdvzmR2 YPLYOesuu8ezVbeYA5iiuGxSUnMyy1KL9O0SuDIeLtjGXHBWpWLKtL9MDYwrZbsYOTgkBEwk TndndzFyApliEhfurWfrYuTiEBLYxyjx79RGFghnA6PEj0vLmCCck0wS927fhipbwijxdvlm ZpB+FgFViUmf97KA2GwCGhLb9i9nBLFFBAwlbl18BVbDLCAt8e13MxOILSwQKLG5/xgbiM0r oC3R/XkGG8hJQgKeEj+ee0OEBSVOznzCAtGqJXHj30smkBKQMcv/cYCEOQW8JB5Pm8oOYosK qEhMObmNbQKj0Cwk3bOQdM9C6F7AyLyKUTYlt0o3NzEzpzg1Wbc4OTEvL7VI11gvN7NELzWl dBMjKKg5Jfl2MH49qHSIUYCDUYmHV8BUwV+INbGsuDL3EKMkB5OSKK/XGqAQX1J+SmVGYnFG fFFpTmrxIUYJDmYlEV4xe6Acb0piZVVqUT5MSpqDRUmcV03rnZ+QQHpiSWp2ampBahFMVoaD Q0mC9+daoEbBotT01Iq0zJwShDQTByfIcB6g4e9AaniLCxJzizPTIfKnGBWlxHm/gyQEQBIZ pXlwvbCk84pRHOgVYd7rIFU8wIQF1/0KaDAT0OCluvIgg0sSEVJSDYzsfA35GhMsjjQr6T3P OBQiGn5sUUdE1/MlKh865jHVdMctOun8QXWhmk/Ox+n+PO1iKSvOMMw0qH7p4HVGKCCUbcN2 h9/py7b4O2xhPxIlzvazLNb1sNnOi9e3hXw3OXu3TUGWL/iazawXTbviQmJvxYdqCj/fl7H7 +S+tje7Vj1aWJ1spXVViKc5INNRiLipOBABzQo35FQMAAA== 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 01:38:07 -0000 Neat. As an aside, I would love to see a prompt like this for + and -, allowing multiple tags to be modified at once (and starting out with whichever of + or - got you in to the prompt). Quoth Dmitry Kurochkin on Jan 26 at 5:12 am: > The patch adds completion to "tag all" operation bound to "*" > (`notmuch-search-operate-all' function). > --- > emacs/notmuch.el | 48 ++++++++++++++++++++++++++++++++++++------------ > 1 files changed, 36 insertions(+), 12 deletions(-) > > diff --git a/emacs/notmuch.el b/emacs/notmuch.el > index e02966f..71b0221 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,33 @@ 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 search-terms prefixes) > (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)) > + (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 &optional search-terms prefixes) This changes the API of notmuch-select-tag-with-completion in a non-backwards-compatible way. I'm pretty sure this breaks notmuch-search-remove-tag and notmuch-show-remove-tag, but I haven't tested it. > + (let ((tag-list (notmuch-tag-completions search-terms prefixes))) > + (completing-read prompt tag-list))) > + > +(defun notmuch-select-tags-with-completion (prompt &optional search-terms prefixes) > + (let ((tag-list (notmuch-tag-completions search-terms prefixes)) > + (crm-separator " ") > + (crm-local-completion-map (copy-keymap crm-local-completion-map))) Alternatively, you could create a child keymap. crm-local-completion-map is small enough that it probably doesn't matter, so whatever makes the code clearer. > + ;; 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) > + (completing-read-multiple prompt tag-list))) > > (defun notmuch-foreach-mime-part (function mm-handle) > (cond ((stringp (car mm-handle)) > @@ -860,16 +882,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 `_.+-'. > " Technically this changes the API of notmuch-search-operate-all, though the new one is better. Perhaps it should test for (stringp action) and be backwards-compatible? The argument should probably be called "actions" now and it may even make sense to make it a &rest argument (though then you can't make it backwards-compatible). > - (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 (list (notmuch-select-tags-with-completion > + "Operation (+add -drop): notmuch tag " nil > + '("+" "-")))) > + (setq action (delete "" action)) > + ;; Perform some validation > + (let ((words action)) > + (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)))) This should really be a mapc or a dolist, but maybe that's for another patch. > + (apply 'notmuch-tag notmuch-search-query-string action)) > > (defun notmuch-search-buffer-title (query) > "Returns the title for a buffer with notmuch search results."