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 C47F0429E36 for ; Wed, 25 Jan 2012 17:48:16 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, 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 fmkQ864dweL6 for ; Wed, 25 Jan 2012 17:48:16 -0800 (PST) Received: from mail-bk0-f53.google.com (mail-bk0-f53.google.com [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id A122D431FBC for ; Wed, 25 Jan 2012 17:48:15 -0800 (PST) Received: by bkbzt19 with SMTP id zt19so58492bkb.26 for ; Wed, 25 Jan 2012 17:48:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:subject:in-reply-to:references:user-agent:date:message-id :mime-version:content-type; bh=cc7FxKkN6l/j5Slz/O1TDbAZncZmvmZbi1uoIifqatQ=; b=JLEt4+8Z2n+XOVcgmNll+kBPJ6+DhOmUxtSD9VXvPh9UiT2e/X8w3INAP6Whl4w0hp odqgD/jmUKqTNeFyhczVfK3wrBB3HESbfi+AezCpipv+sl/FczO+vx8WvJE3YlKwyaI3 LUB+T4k8ivrIYzhs9d2MpIv1Kf2og/W7e7Jyo= Received: by 10.204.10.66 with SMTP id o2mr13126bko.104.1327542494267; Wed, 25 Jan 2012 17:48:14 -0800 (PST) Received: from localhost ([91.144.186.21]) by mx.google.com with ESMTPS id fb7sm5040552bkc.9.2012.01.25.17.48.13 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 25 Jan 2012 17:48:13 -0800 (PST) From: Dmitry Kurochkin To: Austin Clements , notmuch@notmuchmail.org Subject: Re: [PATCH] emacs: add completion to "tag all" operation ("*" binding) In-Reply-To: <20120126013727.GB1176@mit.edu> References: <1327540351-5249-1-git-send-email-dmitry.kurochkin@gmail.com> <20120126013727.GB1176@mit.edu> User-Agent: Notmuch/0.11+116~ge6e10b8 (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu) Date: Thu, 26 Jan 2012 05:47:07 +0400 Message-ID: <87wr8fqlpg.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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:48:16 -0000 On Wed, 25 Jan 2012 20:37:27 -0500, Austin Clements wrote: > 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). > Yeah, I was thinking about making "+" and "-" accepting multiple tags using `notmuch-select-tags-with-completion'. But that is for another patch. > 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. > I tested only tag additions. It works, and I assumed tag removal is no different. Will fix. > > + (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. > Thanks, I will look into it. > > + ;; 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? > In this case, I do not think there are many users of the function. So I would prefer to keep the code clean. > 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). > Makes sense, will do. > > - (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. > Yes, I changed "this_tag" spelling in v2, but would prefer to leave non-trivial changes in this code for another patch. Regards, Dmitry > > + (apply 'notmuch-tag notmuch-search-query-string action)) > > > > (defun notmuch-search-buffer-title (query) > > "Returns the title for a buffer with notmuch search results."