--- /dev/null
+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 5743F431FAF\r
+ for <notmuch@notmuchmail.org>; Wed, 25 Jan 2012 18:46:21 -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 eVlZHLhR8EyI for <notmuch@notmuchmail.org>;\r
+ Wed, 25 Jan 2012 18:46:20 -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 366B6431FAE\r
+ for <notmuch@notmuchmail.org>; Wed, 25 Jan 2012 18:46:20 -0800 (PST)\r
+Received: by bkbzt19 with SMTP id zt19so92251bkb.26\r
+ for <notmuch@notmuchmail.org>; Wed, 25 Jan 2012 18:46:18 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
+ h=from:to:subject:date:message-id:x-mailer:in-reply-to:references;\r
+ bh=UNvhxVoM5IGvXycrX8QL5mC1md562khPLwutApwzDFg=;\r
+ b=YlkMgjxvP4NS9ozqRrQWoMBCXbPdHkBDus2lvVVp+XeUnUu7Lvu4AnJfAljgjCOfrR\r
+ 4SrAdzJq8dTPDzDoh5OngopMH+025f220IhuIkzIUSNYBq8f6niyt5HSb8rM0IyxK0kr\r
+ 8iES0AvRwVp1FeBGLInze9woKT6T8Y4YlhIHE=\r
+Received: by 10.204.130.28 with SMTP id q28mr131388bks.10.1327545978824;\r
+ Wed, 25 Jan 2012 18:46:18 -0800 (PST)\r
+Received: from localhost ([91.144.186.21])\r
+ by mx.google.com with ESMTPS id ek9sm5324251bkb.10.2012.01.25.18.46.17\r
+ (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Wed, 25 Jan 2012 18:46:18 -0800 (PST)\r
+From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3] emacs: add completion to "tag all" operation ("*" binding)\r
+Date: Thu, 26 Jan 2012 06:45:12 +0400\r
+Message-Id: <1327545912-16754-1-git-send-email-dmitry.kurochkin@gmail.com>\r
+X-Mailer: git-send-email 1.7.8.3\r
+In-Reply-To: <1327540351-5249-1-git-send-email-dmitry.kurochkin@gmail.com>\r
+References: <1327540351-5249-1-git-send-email-dmitry.kurochkin@gmail.com>\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 02:46:21 -0000\r
+\r
+The patch adds <tab> completion to "tag all" operation bound to "*"\r
+(`notmuch-search-operate-all' function).\r
+---\r
+\r
+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-show.el | 4 +-\r
+ emacs/notmuch.el | 55 ++++++++++++++++++++++++++++++++++++------------\r
+ 2 files changed, 43 insertions(+), 16 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index e6a5b31..b23a981 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -38,7 +38,7 @@\r
+ \r
+ (declare-function notmuch-call-notmuch-process "notmuch" (&rest args))\r
+ (declare-function notmuch-fontify-headers "notmuch" nil)\r
+-(declare-function notmuch-select-tag-with-completion "notmuch" (prompt &rest search-terms))\r
++(declare-function notmuch-select-tag-with-completion "notmuch" (prompt &optional prefixes &rest search-terms))\r
+ (declare-function notmuch-search-show-thread "notmuch" nil)\r
+ \r
+ (defcustom notmuch-message-headers '("Subject" "To" "Cc" "Date")\r
+@@ -1474,7 +1474,7 @@ the result."\r
+ "Remove a tag from the current message."\r
+ (interactive\r
+ (list (notmuch-select-tag-with-completion\r
+- "Tag to remove: " (notmuch-show-get-message-id))))\r
++ "Tag to remove: " nil (notmuch-show-get-message-id))))\r
+ \r
+ (let* ((current-tags (notmuch-show-get-tags))\r
+ (new-tags (notmuch-show-del-tags-worker current-tags toremove)))\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index e02966f..ba8f8e1 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
++ (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 &optional prefixes &rest search-terms)\r
++ (let ((tag-list (notmuch-tag-completions prefixes 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
++ (completing-read-multiple prompt tag-list)))\r
+ \r
+ (defun notmuch-foreach-mime-part (function mm-handle)\r
+ (cond ((stringp (car mm-handle))\r
+@@ -606,7 +631,7 @@ The tag is removed from all messages in the currently selected\r
+ thread or threads in the current region."\r
+ (interactive\r
+ (list (notmuch-select-tag-with-completion\r
+- "Tag to remove: "\r
++ "Tag to remove: " nil\r
+ (if (region-active-p)\r
+ (mapconcat 'identity\r
+ (notmuch-search-find-thread-id-region (region-beginning) (region-end))\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
++ ;; 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
+-- \r
+1.7.8.3\r
+\r