Re: [PATCH v2 03/13] emacs: make "+" and "-" tagging operations in notmuch-search...
authorAustin Clements <amdragon@MIT.EDU>
Mon, 30 Jan 2012 04:48:06 +0000 (23:48 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:43:34 +0000 (09:43 -0800)
24/2bd0c9dadfbfffcc9ccbee5a20f20434e09e7a [new file with mode: 0644]

diff --git a/24/2bd0c9dadfbfffcc9ccbee5a20f20434e09e7a b/24/2bd0c9dadfbfffcc9ccbee5a20f20434e09e7a
new file mode 100644 (file)
index 0000000..aec63b9
--- /dev/null
@@ -0,0 +1,328 @@
+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 73E18429E34\r
+       for <notmuch@notmuchmail.org>; Sun, 29 Jan 2012 20:49:09 -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 EmA5AgOtOpBj for <notmuch@notmuchmail.org>;\r
+       Sun, 29 Jan 2012 20:49:02 -0800 (PST)\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 02587431FBC\r
+       for <notmuch@notmuchmail.org>; Sun, 29 Jan 2012 20:49:01 -0800 (PST)\r
+X-AuditID: 12074422-b7fd66d0000008f9-5c-4f2621396f83\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+       by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 59.98.02297.931262F4; Sun, 29 Jan 2012 23:48:57 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q0U4munF017066; \r
+       Sun, 29 Jan 2012 23:48:57 -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 q0U4mt7L028524\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Sun, 29 Jan 2012 23:48:56 -0500 (EST)\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1Rrj9y-0000VZ-PP; Sun, 29 Jan 2012 23:48:06 -0500\r
+Date: Sun, 29 Jan 2012 23:48:06 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
+Subject: Re: [PATCH v2 03/13] emacs: make "+" and "-" tagging operations in\r
+       notmuch-search more robust\r
+Message-ID: <20120130044806.GM17991@mit.edu>\r
+References: <1327725684-5887-1-git-send-email-dmitry.kurochkin@gmail.com>\r
+       <1327890382-548-1-git-send-email-dmitry.kurochkin@gmail.com>\r
+       <1327890382-548-4-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: <1327890382-548-4-git-send-email-dmitry.kurochkin@gmail.com>\r
+User-Agent: Mutt/1.5.21 (2010-09-15)\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFlrEKsWRmVeSWpSXmKPExsUixG6nrmujqOZvsGK1tMXVrf3sFtdvzmR2\r
+       YPLYOesuu8ezVbeYA5iiuGxSUnMyy1KL9O0SuDL+XXnPUnA1pKJ/91XGBsYZLl2MnBwSAiYS\r
+       F19eY4SwxSQu3FvP1sXIxSEksI9RomvZG0YIZwOjxI4pB1ggnJNMEpv/rWGHcJYwSnRO+8kM\r
+       0s8ioCpxee55dhCbTUBDYtv+5WBzRQQMJW5dfAVWwywgLfHtdzMTiC0skCHR2LYNyObg4BXQ\r
+       kXh0EWrbcUaJYysfgNXzCghKnJz5hAWiV0vixr+XYPUgc5b/4wAJcwp4Suy4spYVxBYVUJGY\r
+       cnIb2wRGoVlIumch6Z6F0L2AkXkVo2xKbpVubmJmTnFqsm5xcmJeXmqRrqlebmaJXmpK6SZG\r
+       cGC7KO1g/HlQ6RCjAAejEg9v0D9VfyHWxLLiytxDjJIcTEqivEkKav5CfEn5KZUZicUZ8UWl\r
+       OanFhxglOJiVRHgf/QQq501JrKxKLcqHSUlzsCiJ86prvfMTEkhPLEnNTk0tSC2CyWpwcAhc\r
+       OXhkNqMUS15+XqqSBG8RyALBotT01Iq0zJwShFImDk6QRTxAi0pAaniLCxJzizPTIfKnGI05\r
+       2t/uPs/I8Xb+/vOMQmDjpMR5Y0FKBUBKM0rz4KbBktYrRnGgR4V5z4NU8QATHty8V0CrmIBW\r
+       PWcA+am4JBEhJdXAuFzzitYWIa4fMYeORfYpcy0+u+63GcvGJ5ciSs7+1hDZpZ+o/+23l8+p\r
+       AvW2vcpH505VTm+zqf/5Sd+sTjAxJlNjxf6P8aEWytOTKyJ63J00zmZ96Uri+aN35cNtu/ef\r
+       NI/5+62/ZWb99fLFKLPUWwrXqrvunT1avpCpQ22D3Hb3q0tFN3THKrEUZyQaajEXFScCALwa\r
+       BO01AwAA\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: Mon, 30 Jan 2012 04:49:09 -0000\r
+\r
+Looking good.  Just a few small points below.\r
+\r
+Quoth Dmitry Kurochkin on Jan 30 at  6:26 am:\r
+> Before the change, "+" and "-" tagging operations in notmuch-search\r
+> view accepted only a single tag.  The patch makes them use the\r
+> recently added `notmuch-read-tag-changes' function (renamed\r
+> `notmuch-select-tags-with-completion'), which allows to enter multiple\r
+> tags with "+" and "-" prefixes.  So after the change, "+" and "-"\r
+> bindings in notmuch-search view allow to both add and remove multiple\r
+> tags.  The only difference between "+" and "-" is the minibuffer\r
+> initial input ("+" and "-" respectively).\r
+> ---\r
+>  emacs/notmuch.el |  164 +++++++++++++++++++++++++++---------------------------\r
+>  1 files changed, 82 insertions(+), 82 deletions(-)\r
+> \r
+> diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+> index ff46617..90b594c 100644\r
+> --- a/emacs/notmuch.el\r
+> +++ b/emacs/notmuch.el\r
+> @@ -76,38 +76,57 @@ 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-read-tag-changes (&optional initial-input &rest search-terms)\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
+> +     (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 "Tags (+add -drop): "\r
+> +            tag-list nil nil initial-input))))\r
+> +\r
+> +(defun notmuch-update-tags (tags tag-changes)\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\r
+> +either a \"+\" to indicate the tag should be added to TAGS if not\r
+> +present or a \"-\" to indicate that the tag should be removed\r
+> +from TAGS if present."\r
+> +  (let ((result-tags (copy-sequence tags)))\r
+> +    (dolist (tag-change tag-changes)\r
+> +      (unless (string= tag-change "")\r
+\r
+This function should give the "must be of the form" error for empty\r
+strings, rather than silently ignoring them.  It turns out\r
+`string-to-char' on an empty string is fine (it returns 0, which will\r
+trigger the error), but `substring' isn't.  Perhaps move the unless\r
+into the let before, like\r
+ (let ((op (string-to-char tag-change))\r
+       (tag (unless (string= tag-change "") (substring tag-change 1))))\r
+\r
+> +    (let ((op (string-to-char tag-change))\r
+> +          (tag (substring tag-change 1)))\r
+> +      (case op\r
+> +        (?+ (unless (member tag result-tags)\r
+> +              (push tag result-tags)))\r
+> +        (?- (setq result-tags (delete tag result-tags)))\r
+> +        (otherwise\r
+> +         (error "Changed tag must be of the form `+this_tag' or `-that_tag'"))))))\r
+> +    (sort result-tags 'string<)))\r
+>  \r
+>  (defun notmuch-foreach-mime-part (function mm-handle)\r
+>    (cond ((stringp (car mm-handle))\r
+> @@ -447,6 +466,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 +613,53 @@ 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
+\r
+Maybe "tag-changes" instead of "tags" for this and\r
+notmuch-search-tag-region?\r
+\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'.  The tags are\r
+> +added or removed for all threads in the region from BEG to END."\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
+\r
+It's great to see all of this old copy-pasted code go away!\r
+\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
+> +     (search-string (notmuch-search-find-thread-id-region-search beg end))\r
+> +     (tags (notmuch-read-tag-changes 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 +895,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-read-tag-changes))\r
+>    (apply 'notmuch-tag notmuch-search-query-string actions))\r
+>  \r
+>  (defun notmuch-search-buffer-title (query)\r