Re: [PATCH 3/6] emacs: make "+" and "-" tagging operations more robust
authorAustin Clements <amdragon@MIT.EDU>
Sun, 29 Jan 2012 22:57:10 +0000 (17:57 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:43:32 +0000 (09:43 -0800)
fa/654471f8b97bb8bad9989fb1178c83c8968639 [new file with mode: 0644]

diff --git a/fa/654471f8b97bb8bad9989fb1178c83c8968639 b/fa/654471f8b97bb8bad9989fb1178c83c8968639
new file mode 100644 (file)
index 0000000..bb92226
--- /dev/null
@@ -0,0 +1,497 @@
+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 98606429E4C\r
+       for <notmuch@notmuchmail.org>; Sun, 29 Jan 2012 14:58:02 -0800 (PST)\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 xZymCiIjACJx for <notmuch@notmuchmail.org>;\r
+       Sun, 29 Jan 2012 14:58:01 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU\r
+       [18.9.25.15])\r
+       by olra.theworths.org (Postfix) with ESMTP id D4D7F431E64\r
+       for <notmuch@notmuchmail.org>; Sun, 29 Jan 2012 14:58:00 -0800 (PST)\r
+X-AuditID: 1209190f-b7f8a6d000000914-14-4f25cef8cadb\r
+Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
+       by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 7D.D6.02324.8FEC52F4; Sun, 29 Jan 2012 17:58:00 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id q0TMvxIA014616; \r
+       Sun, 29 Jan 2012 17:58:00 -0500\r
+Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
+       (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0TMvwHX022164\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Sun, 29 Jan 2012 17:57:59 -0500 (EST)\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1RrdgM-00007O-Hb; Sun, 29 Jan 2012 17:57:10 -0500\r
+Date: Sun, 29 Jan 2012 17:57:10 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
+Subject: Re: [PATCH 3/6] emacs: make "+" and "-" tagging operations more\r
+ robust\r
+Message-ID: <20120129225710.GG17991@mit.edu>\r
+References: <1327725684-5887-1-git-send-email-dmitry.kurochkin@gmail.com>\r
+       <1327725684-5887-3-git-send-email-dmitry.kurochkin@gmail.com>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Content-Disposition: inline\r
+In-Reply-To: <1327725684-5887-3-git-send-email-dmitry.kurochkin@gmail.com>\r
+User-Agent: Mutt/1.5.21 (2010-09-15)\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFprEKsWRmVeSWpSXmKPExsUixCmqrPvjnKq/wesjPBZXt/azW1y/OZPZ\r
+       gclj56y77B7PVt1iDmCK4rJJSc3JLEst0rdL4Mp4f3Quc8HMXsaKnt0X2BoYfxZ2MXJySAiY\r
+       SKx8fIoJwhaTuHBvPVsXIxeHkMA+Rol1p2+yQjgbGCU6Hx5ih3BOMkns29zDBOEsYZRY/fAu\r
+       M0g/i4CqxMaz6xlBbDYBDYlt+5eD2SIChhK3Lr4Cq2EWkJb49rsZbJ+wQKBE1+W1LCA2r4CO\r
+       xJ6t0xkhhnYySsyd/QIqIShxcuYTFohmLYkb/14CNXOADVr+jwMkzCngJXFnzyJ2EFtUQEVi\r
+       ysltbBMYhWYh6Z6FpHsWQvcCRuZVjLIpuVW6uYmZOcWpybrFyYl5ealFuiZ6uZkleqkppZsY\r
+       wcEtyb+D8dtBpUOMAhyMSjy8J5aq+AuxJpYVV+YeYpTkYFIS5W05o+ovxJeUn1KZkVicEV9U\r
+       mpNafIhRgoNZSYR3zjKgHG9KYmVValE+TEqag0VJnFdN652fkEB6YklqdmpqQWoRTFaGg0NJ\r
+       gjcPGMVCgkWp6akVaZk5JQhpJg5OkOE8QMN7QGp4iwsSc4sz0yHypxh1Od7O33+eUYglLz8v\r
+       VUqcNxqkSACkKKM0D24OLCm9YhQHekuYNxKkigeY0OAmvQJawgS05DkD2JKSRISUVAOjdWMZ\r
+       177jsb8vzs8+ctXyvpi80ObOVV3icqyFdcK/hesjtHef7PqUFvtx/lp930mz1pw4Z/vPR917\r
+       zpwDleldHrrLW6JNmufd+1Dr1PzFYuOkCUL3bKT4avk9+DfIsMkpaCjUzItkMunq3z/7Qrlh\r
+       t5b+wfVXCuZmZ/X3vAhi7f215E5Cp4USS3FGoqEWc1FxIgC9rLRQJQMAAA==\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: Sun, 29 Jan 2012 22:58:02 -0000\r
+\r
+I'm looking forward to having this.  I think it'll streamline tagging\r
+operations.\r
+\r
+Quoth Dmitry Kurochkin on Jan 28 at  8:41 am:\r
+> Before the change, "+" and "-" tagging operations in notmuch-search\r
+> and notmuch-show views accepted only a single tag.  The patch makes\r
+> them use the recently added `notmuch-select-tags-with-completion'\r
+> function, which allows to enter multiple tags with "+" and "-"\r
+> prefixes.  So after the change, "+" and "-" bindings allow to both add\r
+> and remove multiple tags.  The only difference between "+" and "-" is\r
+> the minibuffer initial input ("+" and "-" respectively).\r
+\r
+This patch was a little difficult to review because it was largish and\r
+the diff happened to contain a bunch of forward references.  If it's\r
+convenient (don't bother if it's not), could you divide up the next\r
+version a little?  Something simple like sending the show changes as a\r
+separate patch would probably make it a lot easier.\r
+\r
+> ---\r
+>  emacs/notmuch-show.el |   65 +++++++------------\r
+>  emacs/notmuch.el      |  165 +++++++++++++++++++++++++------------------------\r
+>  2 files changed, 107 insertions(+), 123 deletions(-)\r
+> \r
+> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+> index 84ac624..03eadfb 100644\r
+> --- a/emacs/notmuch-show.el\r
+> +++ b/emacs/notmuch-show.el\r
+> @@ -38,8 +38,9 @@\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-tags-with-completion "notmuch" (&optional initial-input &rest search-terms))\r
+>  (declare-function notmuch-search-show-thread "notmuch" nil)\r
+> +(declare-function notmuch-update-tags "notmuch" (current-tags changed-tags))\r
+>  \r
+>  (defcustom notmuch-message-headers '("Subject" "To" "Cc" "Date")\r
+>    "Headers that should be shown in a message, in this order.\r
+> @@ -1267,7 +1268,7 @@ Some useful entries are:\r
+>  \r
+>  (defun notmuch-show-mark-read ()\r
+>    "Mark the current message as read."\r
+> -  (notmuch-show-remove-tag "unread"))\r
+> +  (notmuch-show-tag-message "-unread"))\r
+>  \r
+>  ;; Functions for getting attributes of several messages in the current\r
+>  ;; thread.\r
+> @@ -1470,51 +1471,33 @@ than only the current message."\r
+>          (message (format "Command '%s' exited abnormally with code %d"\r
+>                           shell-command exit-code))))))))\r
+>  \r
+> -(defun notmuch-show-add-tags-worker (current-tags add-tags)\r
+> -  "Add to `current-tags' with any tags from `add-tags' not\r
+> -currently present and return the result."\r
+> -  (let ((result-tags (copy-sequence current-tags)))\r
+> -    (mapc (lambda (add-tag)\r
+> -        (unless (member add-tag current-tags)\r
+> -          (setq result-tags (push add-tag result-tags))))\r
+> -        add-tags)\r
+> -    (sort result-tags 'string<)))\r
+> -\r
+> -(defun notmuch-show-del-tags-worker (current-tags del-tags)\r
+> -  "Remove any tags in `del-tags' from `current-tags' and return\r
+> -the result."\r
+> -  (let ((result-tags (copy-sequence current-tags)))\r
+> -    (mapc (lambda (del-tag)\r
+> -        (setq result-tags (delete del-tag result-tags)))\r
+> -      del-tags)\r
+> -    result-tags))\r
+> -\r
+> -(defun notmuch-show-add-tag (&rest toadd)\r
+> -  "Add a tag to the current message."\r
+> -  (interactive\r
+> -   (list (notmuch-select-tag-with-completion "Tag to add: ")))\r
+> +(defun notmuch-show-tag-message (&rest changed-tags)\r
+> +  "Change tags for the current message.\r
+>  \r
+> +`Changed-tags' is a list of tag operations for \"notmuch tag\",\r
+> +i.e. a list of tags to change with '+' and '-' prefixes."\r
+\r
+Ticks in a docstring indicate functions (and will be hyperlinked as\r
+such by describe-function).  Typically, argument names are indicated\r
+by writing them in all caps.\r
+\r
+Also, it probably makes more sense to reference `notmuch-tag' than\r
+"notmuch tag", since this is Lisp land (and, since that will be\r
+helpfully hyperlinked, you probably don't need to explain changed-tags\r
+here).\r
+\r
+>    (let* ((current-tags (notmuch-show-get-tags))\r
+> -     (new-tags (notmuch-show-add-tags-worker current-tags toadd)))\r
+> -\r
+> +     (new-tags (notmuch-update-tags current-tags changed-tags)))\r
+>      (unless (equal current-tags new-tags)\r
+> -      (apply 'notmuch-tag (notmuch-show-get-message-id)\r
+> -         (mapcar (lambda (s) (concat "+" s)) toadd))\r
+> +      (apply 'notmuch-tag (notmuch-show-get-message-id) changed-tags)\r
+>        (notmuch-show-set-tags new-tags))))\r
+>  \r
+> -(defun notmuch-show-remove-tag (&rest toremove)\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
+> +(defun notmuch-show-tag (&optional initial-input)\r
+> +  "Change tags for the current message, read input from the minibuffer."\r
+> +  (interactive)\r
+> +  (let ((changed-tags (notmuch-select-tags-with-completion\r
+> +                   initial-input (notmuch-show-get-message-id))))\r
+> +    (apply 'notmuch-show-tag-message changed-tags)))\r
+>  \r
+> -  (let* ((current-tags (notmuch-show-get-tags))\r
+> -     (new-tags (notmuch-show-del-tags-worker current-tags toremove)))\r
+> +(defun notmuch-show-add-tag ()\r
+> +  "Same as `notmuch-show-tag' but sets initial input to '+'."\r
+> +  (interactive)\r
+> +  (notmuch-show-tag "+"))\r
+>  \r
+> -    (unless (equal current-tags new-tags)\r
+> -      (apply 'notmuch-tag (notmuch-show-get-message-id)\r
+> -         (mapcar (lambda (s) (concat "-" s)) toremove))\r
+> -      (notmuch-show-set-tags new-tags))))\r
+> +(defun notmuch-show-remove-tag ()\r
+> +  "Same as `notmuch-show-tag' but sets initial input to '-'."\r
+> +  (interactive)\r
+> +  (notmuch-show-tag "-"))\r
+\r
+Should notmuch-show-{add,remove}-tag be considered public functions?\r
+Previously, they were amenable to creating bindings for adding or\r
+removing individual tags, and I believe people have done this.  If\r
+we're okay with breaking backward-compatibility, there should at least\r
+be a NEWS item explaining how to convert such custom bindings to use\r
+notmuch-show-tag-message.\r
+\r
+>  \r
+>  (defun notmuch-show-toggle-headers ()\r
+>    "Toggle the visibility of the current message headers."\r
+> @@ -1559,7 +1542,7 @@ argument, hide all of the messages."\r
+>  (defun notmuch-show-archive-thread-internal (show-next)\r
+>    ;; Remove the tag from the current set of messages.\r
+>    (goto-char (point-min))\r
+> -  (loop do (notmuch-show-remove-tag "inbox")\r
+> +  (loop do (notmuch-show-tag-message "-inbox")\r
+>      until (not (notmuch-show-goto-message-next)))\r
+>    ;; Move to the next item in the search results, if any.\r
+>    (let ((parent-buffer notmuch-show-parent-buffer))\r
+> diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+> index ff46617..24b0ea3 100644\r
+> --- a/emacs/notmuch.el\r
+> +++ b/emacs/notmuch.el\r
+> @@ -76,38 +76,56 @@ For example:\r
+>  (defvar notmuch-query-history nil\r
+>    "Variable to store minibuffer history for notmuch queries")\r
+>  \r
+> -(defun notmuch-tag-completions (&optional prefixes search-terms)\r
+> -  (let ((tag-list\r
+> -     (split-string\r
+> -      (with-output-to-string\r
+> -        (with-current-buffer standard-output\r
+> -          (apply 'call-process notmuch-command nil t\r
+> -                 nil "search-tags" search-terms)))\r
+> -      "\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
+> +(defun notmuch-tag-completions (&optional search-terms)\r
+> +  (split-string\r
+> +   (with-output-to-string\r
+> +     (with-current-buffer standard-output\r
+> +       (apply 'call-process notmuch-command nil t\r
+> +          nil "search-tags" search-terms)))\r
+> +   "\n+" t))\r
+>  \r
+>  (defun notmuch-select-tag-with-completion (prompt &rest search-terms)\r
+> -  (let ((tag-list (notmuch-tag-completions nil search-terms)))\r
+> +  (let ((tag-list (notmuch-tag-completions 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
+> -    ;; By default, space is bound to "complete word" function.\r
+> -    ;; Re-bind it to insert a space instead.  Note that <tab>\r
+> -    ;; still does the completion.\r
+> -    (crm-local-completion-map\r
+> -     (let ((map (make-sparse-keymap)))\r
+> -       (set-keymap-parent map crm-local-completion-map)\r
+> -       (define-key map " " 'self-insert-command)\r
+> -       map)))\r
+> -    (delete "" (completing-read-multiple prompt tag-list))))\r
+> +(defun notmuch-select-tags-with-completion (&optional initial-input &rest search-terms)\r
+\r
+I don't know if notmuch-select-tags-with-completion is the right name\r
+for this now that it hard-codes the +/- prefixes (which seems like the\r
+right thing to do, BTW).  Maybe notmuch-read-tags-add-remove?\r
+\r
+> +  (let* ((add-tag-list (mapcar (apply-partially 'concat "+")\r
+> +                           (notmuch-tag-completions)))\r
+> +     (remove-tag-list (mapcar (apply-partially 'concat "-")\r
+> +                              (notmuch-tag-completions search-terms)))\r
+\r
+This will make two calls to notmuch search, but often one will\r
+suffice.  It's probably worth optimizing the case were search-terms is\r
+nil.\r
+\r
+> +     (tag-list (append add-tag-list remove-tag-list))\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
+> +     ;; still does the completion.\r
+> +     (crm-local-completion-map\r
+> +      (let ((map (make-sparse-keymap)))\r
+> +        (set-keymap-parent map crm-local-completion-map)\r
+> +        (define-key map " " 'self-insert-command)\r
+> +        map)))\r
+> +    (delete "" (completing-read-multiple\r
+> +            "Operations (+add -drop): notmuch tag " tag-list nil\r
+\r
+I don't think the "notmuch tag" part is necessary.  From the\r
+perspective of a person who only uses the Emacs UI, this will be\r
+meaningless.  Maybe "Tag changes (+add -drop): " or even just "Tags\r
+(+add -drop): " since the "+add -drop" part implies what you're doing.\r
+\r
+> +            nil initial-input))))\r
+> +\r
+> +(defun notmuch-update-tags (current-tags changed-tags)\r
+\r
+Maybe just "tags" instead of "current-tags"?  Nothing says they have\r
+to be current.  It's just a list of tags.\r
+\r
+Also, changed-tags makes it sound like a list of tags, which is isn't.\r
+Maybe tag-changes?\r
+\r
+> +  "Update `current-tags' with `changed-tags' and return the result.\r
+> +\r
+> +`Changed-tags' is a list of tag operations given to \"notmuch\r
+> +tag\", i.e. a list of changed tags with '+' and '-' prefixes."\r
+\r
+Same comment about ticks and "notmuch tag".\r
+\r
+I found this docstring a bit confusing.  I wasn't sure exactly what it\r
+meant to "update current-tags with changed-tags" (though replacing\r
+changed-tags with tag-changes would probably help).  Plus, this\r
+function does not, in fact, update current-tags.  Maybe,\r
+\r
+  "Return a copy of TAGS with additions and removals from TAG-CHANGES.\r
+\r
+TAG-CHANGES must be a list of tags names, each prefixed with either a\r
+\"+\" to indicate the tag should be added to TAGS if not present or a\r
+\"-\" to indicate that the tag should be removed from TAGS if\r
+present."\r
+\r
+> +  (let ((result-tags (copy-sequence current-tags)))\r
+> +    (mapc (lambda (changed-tag)\r
+\r
+Consider dolist instead of mapc, though this is a matter of taste.  It\r
+leads to less indentation (and does have precedent in the notmuch\r
+code, though mapc is more common).\r
+\r
+Too bad Elisp doesn't have fold.\r
+\r
+> +        (unless (string= changed-tag "")\r
+> +          (let ((op (substring changed-tag 0 1))\r
+> +                (tag (substring changed-tag 1)))\r
+> +            (cond ((string= op "+")\r
+> +                   (unless (member tag result-tags)\r
+> +                     (push tag result-tags)))\r
+> +                  ((string= op "-")\r
+> +                   (setq result-tags (delete tag result-tags)))\r
+> +                  (t\r
+> +                   (error "Changed tag must be of the form `+this_tag' or `-that_tag'"))))))\r
+\r
+I would suggest case instead of cond, but, again, that's a matter of\r
+taste.\r
+\r
+> +       changed-tags)\r
+> +    (sort result-tags 'string<)))\r
+>  \r
+>  (defun notmuch-foreach-mime-part (function mm-handle)\r
+>    (cond ((stringp (car mm-handle))\r
+> @@ -447,6 +465,10 @@ Complete list of currently available key bindings:\r
+>    "Return a list of threads for the current region"\r
+>    (notmuch-search-properties-in-region 'notmuch-search-thread-id beg end))\r
+>  \r
+> +(defun notmuch-search-find-thread-id-region-search (beg end)\r
+> +  "Return a search string for threads for the current region"\r
+> +  (mapconcat 'identity (notmuch-search-find-thread-id-region beg end) " or "))\r
+> +\r
+>  (defun notmuch-search-find-authors ()\r
+>    "Return the authors for the current thread"\r
+>    (get-text-property (point) 'notmuch-search-authors))\r
+> @@ -590,74 +612,55 @@ the messages that were tagged"\r
+>      (forward-line 1))\r
+>        output)))\r
+>  \r
+> -(defun notmuch-search-add-tag-thread (tag)\r
+> -  (notmuch-search-add-tag-region tag (point) (point)))\r
+> +(defun notmuch-search-tag-thread (&rest tags)\r
+> +  "Change tags for the currently selected thread.\r
+>  \r
+> -(defun notmuch-search-add-tag-region (tag beg end)\r
+> -  (let ((search-id-string (mapconcat 'identity (notmuch-search-find-thread-id-region beg end) " or ")))\r
+> -    (notmuch-tag search-id-string (concat "+" tag))\r
+> -    (save-excursion\r
+> -      (let ((last-line (line-number-at-pos end))\r
+> -        (max-line (- (line-number-at-pos (point-max)) 2)))\r
+> -    (goto-char beg)\r
+> -    (while (<= (line-number-at-pos) (min last-line max-line))\r
+> -      (notmuch-search-set-tags (delete-dups (sort (cons tag (notmuch-search-get-tags)) 'string<)))\r
+> -      (forward-line))))))\r
+> +See `notmuch-search-tag-region' for details."\r
+> +  (apply 'notmuch-search-tag-region (point) (point) tags))\r
+>  \r
+> -(defun notmuch-search-remove-tag-thread (tag)\r
+> -  (notmuch-search-remove-tag-region tag (point) (point)))\r
+> +(defun notmuch-search-tag-region (beg end &rest tags)\r
+> +  "Change tags for threads in the given region.\r
+>  \r
+> -(defun notmuch-search-remove-tag-region (tag beg end)\r
+> -  (let ((search-id-string (mapconcat 'identity (notmuch-search-find-thread-id-region beg end) " or ")))\r
+> -    (notmuch-tag search-id-string (concat "-" tag))\r
+> +`Tags' is a list of tag operations for \"notmuch tag\", i.e. a\r
+> +list of tags to change with '+' and '-' prefixes.  The tags are\r
+> +added or removed for all threads in the region from `beg' to\r
+> +`end'."\r
+\r
+Same comment about ticks and "notmuch tag".\r
+\r
+> +  (let ((search-string (notmuch-search-find-thread-id-region-search beg end)))\r
+> +    (apply 'notmuch-tag search-string tags)\r
+>      (save-excursion\r
+>        (let ((last-line (line-number-at-pos end))\r
+>          (max-line (- (line-number-at-pos (point-max)) 2)))\r
+>      (goto-char beg)\r
+>      (while (<= (line-number-at-pos) (min last-line max-line))\r
+> -      (notmuch-search-set-tags (delete tag (notmuch-search-get-tags)))\r
+> +      (notmuch-search-set-tags\r
+> +       (notmuch-update-tags (notmuch-search-get-tags) tags))\r
+>        (forward-line))))))\r
+>  \r
+> -(defun notmuch-search-add-tag (tag)\r
+> -  "Add a tag to the currently selected thread or region.\r
+> -\r
+> -The tag is added to all messages in the currently selected thread\r
+> -or threads in the current region."\r
+> -  (interactive\r
+> -   (list (notmuch-select-tag-with-completion "Tag to add: ")))\r
+> -  (save-excursion\r
+> -    (if (region-active-p)\r
+> -    (let* ((beg (region-beginning))\r
+> -           (end (region-end)))\r
+> -      (notmuch-search-add-tag-region tag beg end))\r
+> -      (notmuch-search-add-tag-thread tag))))\r
+> -\r
+> -(defun notmuch-search-remove-tag (tag)\r
+> -  "Remove a tag from the currently selected thread or region.\r
+> +(defun notmuch-search-tag (&optional initial-input)\r
+> +  "Change tags for the currently selected thread or region."\r
+> +  (interactive)\r
+> +  (let* ((beg (if (region-active-p) (region-beginning) (point)))\r
+> +     (end (if (region-active-p) (region-end) (point)))\r
+\r
+While you're in here, these should probably be `use-region-p'.\r
+\r
+> +     (search-string (notmuch-search-find-thread-id-region-search beg end))\r
+> +     (tags (notmuch-select-tags-with-completion initial-input search-string)))\r
+> +    (apply 'notmuch-search-tag-region beg end tags)))\r
+> +\r
+> +(defun notmuch-search-add-tag ()\r
+> +  "Same as `notmuch-search-tag' but sets initial input to '+'."\r
+> +  (interactive)\r
+> +  (notmuch-search-tag "+"))\r
+>  \r
+> -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
+> -      (if (region-active-p)\r
+> -          (mapconcat 'identity\r
+> -                     (notmuch-search-find-thread-id-region (region-beginning) (region-end))\r
+> -                     " ")\r
+> -        (notmuch-search-find-thread-id)))))\r
+> -  (save-excursion\r
+> -    (if (region-active-p)\r
+> -    (let* ((beg (region-beginning))\r
+> -           (end (region-end)))\r
+> -      (notmuch-search-remove-tag-region tag beg end))\r
+> -      (notmuch-search-remove-tag-thread tag))))\r
+> +(defun notmuch-search-remove-tag ()\r
+> +  "Same as `notmuch-search-tag' but sets initial input to '-'."\r
+> +  (interactive)\r
+> +  (notmuch-search-tag "-"))\r
+>  \r
+>  (defun notmuch-search-archive-thread ()\r
+>    "Archive the currently selected thread (remove its \"inbox\" tag).\r
+>  \r
+>  This function advances the next thread when finished."\r
+>    (interactive)\r
+> -  (notmuch-search-remove-tag-thread "inbox")\r
+> +  (notmuch-search-tag-thread "-inbox")\r
+>    (notmuch-search-next-thread))\r
+>  \r
+>  (defvar notmuch-search-process-filter-data nil\r
+> @@ -893,9 +896,7 @@ 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 (notmuch-select-tags-with-completion\r
+> -            "Operations (+add -drop): notmuch tag "\r
+> -            '("+" "-")))\r
+> +  (interactive (notmuch-select-tags-with-completion))\r
+>    (apply 'notmuch-tag notmuch-search-query-string actions))\r
+>  \r
+>  (defun notmuch-search-buffer-title (query)\r