--- /dev/null
+Return-Path: <amdragon@mit.edu>\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 B3E39431FAE\r
+ for <notmuch@notmuchmail.org>; Tue, 22 Oct 2013 17:22:31 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[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 JuWa5BY8Ep22 for <notmuch@notmuchmail.org>;\r
+ Tue, 22 Oct 2013 17:22:26 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-5.mit.edu (dmz-mailsec-scanner-5.mit.edu\r
+ [18.7.68.34])\r
+ by olra.theworths.org (Postfix) with ESMTP id 11059429E29\r
+ for <notmuch@notmuchmail.org>; Tue, 22 Oct 2013 17:22:09 -0700 (PDT)\r
+X-AuditID: 12074422-b7f5a8e000000a34-11-526716b0867f\r
+Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
+ by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id AF.C5.02612.0B617625; Tue, 22 Oct 2013 20:22:08 -0400 (EDT)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+ by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id r9N0M5gN027447; \r
+ Tue, 22 Oct 2013 20:22:05 -0400\r
+Received: from drake.dyndns.org\r
+ (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+ [216.15.114.40]) (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id r9N0M3ir005837\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Tue, 22 Oct 2013 20:22:04 -0400\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1VYmD5-0008KE-N2; Tue, 22 Oct 2013 20:22:03 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 2/8] emacs: Take prompt and current tags in\r
+ `notmuch-read-tag-changes'\r
+Date: Tue, 22 Oct 2013 20:21:55 -0400\r
+Message-Id: <1382487721-31776-3-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.8.4.rc3\r
+In-Reply-To: <1382487721-31776-1-git-send-email-amdragon@mit.edu>\r
+References: <1382487721-31776-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrNIsWRmVeSWpSXmKPExsUixCmqrbtBLD3IoOukscXquTwW12/OZHZg\r
+ 8tg56y67x7NVt5gDmKK4bFJSczLLUov07RK4Mvqm9jMXTJepWPP/DHMD4wTxLkZODgkBE4kN\r
+ LYdYIWwxiQv31rN1MXJxCAnsY5RY/bKdCcLZyCjxe8MGdgjnDpNE348NLCAtQgJzGSXau9RA\r
+ bDYBDYlt+5czgtgiAtISO+/OBhvLLOAo8Xn/IjYQW1ggUmLXx6dAcQ4OFgFViY6uMJAwr4CD\r
+ xN6bfcwQVyhJLDy1DayVE6j1zY4PbBCrHCSm7DzDMoGRfwEjwypG2ZTcKt3cxMyc4tRk3eLk\r
+ xLy81CJdU73czBK91JTSTYygMGJ3UdrB+POg0iFGAQ5GJR7eBy1pQUKsiWXFlbmHGCU5mJRE\r
+ edX504OE+JLyUyozEosz4otKc1KLDzFKcDArifA2+wKV86YkVlalFuXDpKQ5WJTEeW9x2AcJ\r
+ CaQnlqRmp6YWpBbBZGU4OJQkeLtEgYYKFqWmp1akZeaUIKSZODhBhvMADV8BUsNbXJCYW5yZ\r
+ DpE/xagoJc57BiQhAJLIKM2D64XF+StGcaBXhCHaeYApAq77FdBgJqDBU5aAXF1ckoiQkmpg\r
+ TDiQemLmi8mpC5/b75Ofr9u91ZzRfQNv7emL2z86nV3rGXLlmOIGvyTOlcfFnznoXd+qvX39\r
+ 2XSLp8bC+TavzBsybzOZshnyTT/9tVnBUf/R7jcLGzdlPz7EYLb0nnu9cbNRbY/LqQO7nYvf\r
+ rd2/NXxO0jNNl0gfdYeCZW2R+cb7rh3cGLjlhBJLcUaioRZzUXEiAMhRcr3OAgAA\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: Wed, 23 Oct 2013 00:22:32 -0000\r
+\r
+This modifies the interface of `notmuch-read-tag-changes' to take an\r
+optional prompt string as well as a list of existing tags instead of a\r
+query. This list of tags is used to populate the tag removal\r
+completions and lets the caller compute these in a more\r
+efficient/consistent manner than performing a potentially large or\r
+complex query. This patch also updates the sole current caller of\r
+`notmuch-read-tag-changes'.\r
+---\r
+ emacs/notmuch-tag.el | 29 ++++++++++++++++++++---------\r
+ 1 file changed, 20 insertions(+), 9 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el\r
+index 064cfa8..3ad53b2 100644\r
+--- a/emacs/notmuch-tag.el\r
++++ b/emacs/notmuch-tag.el\r
+@@ -188,7 +188,10 @@ the messages that were tagged"\r
+ "Variable to store minibuffer history for\r
+ `notmuch-read-tag-changes' function.")\r
+ \r
+-(defun notmuch-tag-completions (&optional search-terms)\r
++(defun notmuch-tag-completions (&rest search-terms)\r
++ "Return a list of tags for messages matching SEARCH-TERMS.\r
++\r
++Returns all tags if no search terms are given."\r
+ (if (null search-terms)\r
+ (setq search-terms (list "*")))\r
+ (split-string\r
+@@ -199,17 +202,24 @@ the messages that were tagged"\r
+ "\n+" t))\r
+ \r
+ (defun notmuch-select-tag-with-completion (prompt &rest search-terms)\r
+- (let ((tag-list (notmuch-tag-completions search-terms)))\r
++ (let ((tag-list (apply #'notmuch-tag-completions search-terms)))\r
+ (completing-read prompt tag-list nil nil nil 'notmuch-select-tag-history)))\r
+ \r
+-(defun notmuch-read-tag-changes (&optional initial-input &rest search-terms)\r
++(defun notmuch-read-tag-changes (current-tags &optional prompt initial-input)\r
++ "Prompt for tag changes in the minibuffer.\r
++\r
++CURRENT-TAGS is a list of tags that are present on the message or\r
++messages to be changed. These are offered as tag removal\r
++completions. CURRENT-TAGS may contain duplicates. PROMPT, if\r
++non-nil, is the query string to present in the minibuffer. It\r
++defaults to \"Tags\". INITIAL-INPUT, if non-nil, will be the\r
++initial input in the minibuffer."\r
++\r
+ (let* ((all-tag-list (notmuch-tag-completions))\r
+ (add-tag-list (mapcar (apply-partially 'concat "+") all-tag-list))\r
+- (remove-tag-list (mapcar (apply-partially 'concat "-")\r
+- (if (null search-terms)\r
+- all-tag-list\r
+- (notmuch-tag-completions search-terms))))\r
++ (remove-tag-list (mapcar (apply-partially 'concat "-") current-tags))\r
+ (tag-list (append add-tag-list remove-tag-list))\r
++ (prompt (concat (or prompt "Tags") " (+add -drop): "))\r
+ (crm-separator " ")\r
+ ;; By default, space is bound to "complete word" function.\r
+ ;; Re-bind it to insert a space instead. Note that <tab>\r
+@@ -219,7 +229,7 @@ the messages that were tagged"\r
+ (set-keymap-parent map crm-local-completion-map)\r
+ (define-key map " " 'self-insert-command)\r
+ map)))\r
+- (delete "" (completing-read-multiple "Tags (+add -drop): "\r
++ (delete "" (completing-read-multiple prompt\r
+ tag-list nil nil initial-input\r
+ 'notmuch-read-tag-changes-history))))\r
+ \r
+@@ -260,7 +270,8 @@ notmuch-after-tag-hook will be run."\r
+ ;; Perform some validation\r
+ (if (string-or-null-p tag-changes)\r
+ (if (or (string= tag-changes "-") (string= tag-changes "+") (null tag-changes))\r
+- (setq tag-changes (notmuch-read-tag-changes tag-changes query))\r
++ (setq tag-changes (notmuch-read-tag-changes\r
++ (notmuch-tag-completions query) nil tag-changes))\r
+ (setq tag-changes (list tag-changes))))\r
+ (mapc (lambda (tag-change)\r
+ (unless (string-match-p "^[-+]\\S-+$" tag-change)\r
+-- \r
+1.8.4.rc3\r
+\r