Re: [PATCH v4] emacs: add completion to "tag all" operation ("*" binding)
authorDmitry Kurochkin <dmitry.kurochkin@gmail.com>
Thu, 26 Jan 2012 17:37:38 +0000 (21:37 +0400)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:43:22 +0000 (09:43 -0800)
dc/b9949f1af1da946bfbd739e0ea7c603fe3c656 [new file with mode: 0644]

diff --git a/dc/b9949f1af1da946bfbd739e0ea7c603fe3c656 b/dc/b9949f1af1da946bfbd739e0ea7c603fe3c656
new file mode 100644 (file)
index 0000000..ce164b4
--- /dev/null
@@ -0,0 +1,216 @@
+Return-Path: <dmitry.kurochkin@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id F0C30431FAF\r
+       for <notmuch@notmuchmail.org>; Thu, 26 Jan 2012 09:38:48 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id 4o5mNdoT9Efr for <notmuch@notmuchmail.org>;\r
+       Thu, 26 Jan 2012 09:38:48 -0800 (PST)\r
+Received: from mail-bk0-f53.google.com (mail-bk0-f53.google.com\r
+       [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id D26BE431FAE\r
+       for <notmuch@notmuchmail.org>; Thu, 26 Jan 2012 09:38:47 -0800 (PST)\r
+Received: by bkbzt19 with SMTP id zt19so782544bkb.26\r
+       for <notmuch@notmuchmail.org>; Thu, 26 Jan 2012 09:38:46 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
+       h=from:to:cc:subject:in-reply-to:references:user-agent:date\r
+       :message-id:mime-version:content-type;\r
+       bh=ReMARUJ4gzWk4MV6FccgllYy/jiz6t48loU540xRPBk=;\r
+       b=iIvM7gzK9Ya5rL1StzU5EFWHb/TO5s/pKvTXmdynFNCmIHL8GwUvSHDuJisDNYllXv\r
+       E9TegGNely0aBhOS/l9rN+vB3jW0+7TnJINRV2A4fLWpTwSDUEBBlUQePdTXhl5F2Hzh\r
+       bOJrTFmM+vjmhEcJVgXZ/wxQCL2TtmUB3gJgc=\r
+Received: by 10.205.128.133 with SMTP id he5mr1480834bkc.17.1327599526492;\r
+       Thu, 26 Jan 2012 09:38:46 -0800 (PST)\r
+Received: from localhost ([91.144.186.21])\r
+       by mx.google.com with ESMTPS id z15sm7456782bkd.7.2012.01.26.09.38.45\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Thu, 26 Jan 2012 09:38:45 -0800 (PST)\r
+From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
+To: Austin Clements <amdragon@MIT.EDU>\r
+Subject: Re: [PATCH v4] emacs: add completion to "tag all" operation ("*"\r
+       binding)\r
+In-Reply-To: <20120126070439.GC1940@mit.edu>\r
+References: <1327540351-5249-1-git-send-email-dmitry.kurochkin@gmail.com>\r
+       <1327554400-7616-1-git-send-email-dmitry.kurochkin@gmail.com>\r
+       <20120126070439.GC1940@mit.edu>\r
+User-Agent: Notmuch/0.11+116~ge6e10b8 (http://notmuchmail.org) Emacs/23.3.1\r
+       (x86_64-pc-linux-gnu)\r
+Date: Thu, 26 Jan 2012 21:37:38 +0400\r
+Message-ID: <87y5su8ivx.fsf@gmail.com>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Cc: notmuch@notmuchmail.org\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 26 Jan 2012 17:38:49 -0000\r
+\r
+On Thu, 26 Jan 2012 02:04:39 -0500, Austin Clements <amdragon@MIT.EDU> wrote:\r
+> Quoth Dmitry Kurochkin on Jan 26 at  9:06 am:\r
+> > The patch adds <tab> completion to "tag all" operation bound to "*"\r
+> > (`notmuch-search-operate-all' function).\r
+> > ---\r
+> > \r
+> > On a second thought, `notmuch-select-tag-with-completion' should never\r
+> > need `prefixes' argument at all.  So I reverted the API and related\r
+> > changes.\r
+> > \r
+> > Changes:\r
+> > \r
+> > v4:\r
+> > \r
+> > * do not change `notmuch-select-tag-with-completion' API, revert\r
+> >   related changes\r
+> > \r
+> > v3:\r
+> > \r
+> > * fixed comments from Austin's review [1]\r
+> > \r
+> > v2:\r
+> > \r
+> > * s/thistag/this_tag/ for consistency with "that_tag", since we touch\r
+> >   the line anyway\r
+> > \r
+> > Regards,\r
+> >   Dmitry\r
+> > \r
+> > [1] id:"20120126013727.GB1176@mit.edu"\r
+> > \r
+> >  emacs/notmuch.el |   53 ++++++++++++++++++++++++++++++++++++++++-------------\r
+> >  1 files changed, 40 insertions(+), 13 deletions(-)\r
+> > \r
+> > diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+> > index e02966f..d2af630 100644\r
+> > --- a/emacs/notmuch.el\r
+> > +++ b/emacs/notmuch.el\r
+> > @@ -48,6 +48,7 @@\r
+> >  ;; required, but is available from http://notmuchmail.org).\r
+> >  \r
+> >  (eval-when-compile (require 'cl))\r
+> > +(require 'crm)\r
+> >  (require 'mm-view)\r
+> >  (require 'message)\r
+> >  \r
+> > @@ -75,12 +76,36 @@ For example:\r
+> >  (defvar notmuch-query-history nil\r
+> >    "Variable to store minibuffer history for notmuch queries")\r
+> >  \r
+> > -(defun notmuch-select-tag-with-completion (prompt &rest search-terms)\r
+> > +(defun notmuch-tag-completions (&optional prefixes search-terms)\r
+> >    (let ((tag-list\r
+> >     (with-output-to-string\r
+> >       (with-current-buffer standard-output\r
+> >         (apply 'call-process notmuch-command nil t nil "search-tags" search-terms)))))\r
+> > -    (completing-read prompt (split-string tag-list "\n+" t) nil nil nil)))\r
+> > +    (setq tag-list (split-string tag-list "\n+" t))\r
+> \r
+> Since this setq is unconditional, you can do the split-string right in\r
+> the let binding, around the with-output-to-string.\r
+> \r
+\r
+I was thinking about it, but decided to use `setq', to make the diff\r
+smaller and the let binding simpler.  Changed in v5.\r
+\r
+> > +    (if (null prefixes)\r
+> > +  tag-list\r
+> > +      (apply #'append\r
+> > +       (mapcar (lambda (tag)\r
+> > +                 (mapcar (lambda (prefix)\r
+> > +                           (concat prefix tag)) prefixes))\r
+> > +               tag-list)))))\r
+> > +\r
+> > +(defun notmuch-select-tag-with-completion (prompt &rest search-terms)\r
+> > +  (let ((tag-list (notmuch-tag-completions nil search-terms)))\r
+> > +    (completing-read prompt tag-list)))\r
+> > +\r
+> > +(defun notmuch-select-tags-with-completion (prompt &optional prefixes &rest search-terms)\r
+> > +  (let ((tag-list (notmuch-tag-completions prefixes search-terms))\r
+> > +  (crm-separator " ")\r
+> > +  (crm-local-completion-map\r
+> > +   (let ((map (make-sparse-keymap)))\r
+> > +     (set-keymap-parent map crm-local-completion-map)\r
+> > +     map)))\r
+> > +    ;; By default, space is bound to "complete word" function.\r
+> > +    ;; Re-bind it to insert a space instead.  Note that <tab> still\r
+> > +    ;; does the completion.\r
+> > +    (define-key crm-local-completion-map " " 'self-insert-command)\r
+> \r
+> You could do the define-key inside the (let ((map ..)) ..) so you get\r
+> back the fully formed keymap.  Your call.\r
+> \r
+\r
+Good point.  Changed in v5.\r
+\r
+> > +    (completing-read-multiple prompt tag-list)))\r
+> >  \r
+> >  (defun notmuch-foreach-mime-part (function mm-handle)\r
+> >    (cond ((stringp (car mm-handle))\r
+> > @@ -849,7 +874,7 @@ non-authors is found, assume that all of the authors match."\r
+> >          (goto-char found-target)))\r
+> >        (delete-process proc))))\r
+> >  \r
+> > -(defun notmuch-search-operate-all (action)\r
+> > +(defun notmuch-search-operate-all (&rest actions)\r
+> >    "Add/remove tags from all matching messages.\r
+> >  \r
+> >  This command adds or removes tags from all messages matching the\r
+> > @@ -860,16 +885,18 @@ will prompt for tags to be added or removed. Tags prefixed with\r
+> >  Each character of the tag name may consist of alphanumeric\r
+> >  characters as well as `_.+-'.\r
+> >  "\r
+> > -  (interactive "sOperation (+add -drop): notmuch tag ")\r
+> > -  (let ((action-split (split-string action " +")))\r
+> > -    ;; Perform some validation\r
+> > -    (let ((words action-split))\r
+> > -      (when (null words) (error "No operation given"))\r
+> > -      (while words\r
+> > -  (unless (string-match-p "^[-+][-+_.[:word:]]+$" (car words))\r
+> > -    (error "Action must be of the form `+thistag -that_tag'"))\r
+> > -  (setq words (cdr words))))\r
+> > -    (apply 'notmuch-tag notmuch-search-query-string action-split)))\r
+> > +  (interactive (notmuch-select-tags-with-completion\r
+> > +          "Operations (+add -drop): notmuch tag "\r
+> > +          '("+" "-")))\r
+> > +  (setq actions (delete "" actions))\r
+> \r
+> Either this line isn't necessary or\r
+> notmuch-select-tags-with-completion can do something funny that it\r
+> should take care of internally.\r
+> \r
+\r
+It is necessary and it belongs to `notmuch-select-tags-with-completion',\r
+thanks.  Changed in v5.\r
+\r
+Regards,\r
+  Dmitry\r
+\r
+> > +  ;; Perform some validation\r
+> > +  (let ((words actions))\r
+> > +    (when (null words) (error "No operations given"))\r
+> > +    (while words\r
+> > +      (unless (string-match-p "^[-+][-+_.[:word:]]+$" (car words))\r
+> > +  (error "Action must be of the form `+this_tag' or `-that_tag'"))\r
+> > +      (setq words (cdr words))))\r
+> > +  (apply 'notmuch-tag notmuch-search-query-string actions))\r
+> >  \r
+> >  (defun notmuch-search-buffer-title (query)\r
+> >    "Returns the title for a buffer with notmuch search results."\r