[PATCH v5 04/12] emacs: make "+" and "-" tagging operations in notmuch-show more...
authorDmitry Kurochkin <dmitry.kurochkin@gmail.com>
Sun, 5 Feb 2012 07:13:45 +0000 (11:13 +0400)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:44:08 +0000 (09:44 -0800)
67/99f13dae02e6de6a4eb4ce23a9f462013b0b40 [new file with mode: 0644]

diff --git a/67/99f13dae02e6de6a4eb4ce23a9f462013b0b40 b/67/99f13dae02e6de6a4eb4ce23a9f462013b0b40
new file mode 100644 (file)
index 0000000..e0c20e7
--- /dev/null
@@ -0,0 +1,195 @@
+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 33666431FBC\r
+       for <notmuch@notmuchmail.org>; Sat,  4 Feb 2012 23:15:29 -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 YcX2iICcIfgX for <notmuch@notmuchmail.org>;\r
+       Sat,  4 Feb 2012 23:15:26 -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 090F6431FBD\r
+       for <notmuch@notmuchmail.org>; Sat,  4 Feb 2012 23:15:25 -0800 (PST)\r
+Received: by mail-bk0-f53.google.com with SMTP id 11so4650313bke.26\r
+       for <notmuch@notmuchmail.org>; Sat, 04 Feb 2012 23:15:25 -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=iw5X6IRHB9kRJqk0kUC/6uFY/gwRrswLXwUe20s6Xxw=;\r
+       b=JVGIRjLf8zhuy9RJ4h6FlwTvD84l/xYkP7TVv8020KWAo5c1IS306n9WIxj/VYGWfL\r
+       khOzq04b95R8NDAZp1PRFGxTttjvbIUptV+pDESciKmr+pSgd9PKJS6gBB9rQtJKOcyS\r
+       5HctYpgF7E5gBN1XIJ8jDySKSvoTVn2JKvoZE=\r
+Received: by 10.204.156.155 with SMTP id x27mr6275814bkw.4.1328426125696;\r
+       Sat, 04 Feb 2012 23:15:25 -0800 (PST)\r
+Received: from localhost ([91.144.186.21])\r
+       by mx.google.com with ESMTPS id bw9sm33010948bkb.8.2012.02.04.23.15.24\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Sat, 04 Feb 2012 23:15:25 -0800 (PST)\r
+From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v5 04/12] emacs: make "+" and "-" tagging operations in\r
+       notmuch-show more flexible\r
+Date: Sun,  5 Feb 2012 11:13:45 +0400\r
+Message-Id: <1328426033-21480-5-git-send-email-dmitry.kurochkin@gmail.com>\r
+X-Mailer: git-send-email 1.7.9\r
+In-Reply-To: <1328426033-21480-1-git-send-email-dmitry.kurochkin@gmail.com>\r
+References: <1327725684-5887-1-git-send-email-dmitry.kurochkin@gmail.com>\r
+       <1328426033-21480-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: Sun, 05 Feb 2012 07:15:29 -0000\r
+\r
+Before the change, "+" and "-" tagging operations in notmuch-show view\r
+accepted only a single tag.  The patch makes them use the recently\r
+added `notmuch-read-tag-changes' function, which allows to enter\r
+multiple tags with "+" and "-" prefixes.  So after the change, "+" and\r
+"-" bindings in notmuch-show view allow to both add and remove\r
+multiple tags.  The only difference between "+" and "-" is the\r
+minibuffer initial input ("+" and "-" respectively).\r
+---\r
+ emacs/notmuch-show.el |   73 +++++++++++++++++-------------------------------\r
+ 1 files changed, 26 insertions(+), 47 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 7469e2e..48a2a60 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -38,9 +38,10 @@\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-read-tag-changes "notmuch" (&optional initial-input &rest search-terms))\r
+ (declare-function notmuch-search-next-thread "notmuch" nil)\r
+ (declare-function notmuch-search-show-thread "notmuch" nil)\r
++(declare-function notmuch-update-tags "notmuch" (current-tags tag-changes))\r
+ \r
+ (defcustom notmuch-message-headers '("Subject" "To" "Cc" "Date")\r
+   "Headers that should be shown in a message, in this order.\r
+@@ -1282,7 +1283,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
+@@ -1495,51 +1496,32 @@ 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 tag-changes)\r
++  "Change tags for the current message.\r
+ \r
++TAG-CHANGES is a list of tag operations for `notmuch-tag'."\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 tag-changes)))\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) tag-changes)\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 ((tag-changes (notmuch-read-tag-changes\r
++                    initial-input (notmuch-show-get-message-id))))\r
++    (apply 'notmuch-show-tag-message tag-changes)))\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
+ (defun notmuch-show-toggle-headers ()\r
+   "Toggle the visibility of the current message headers."\r
+@@ -1587,10 +1569,8 @@ argument, hide all of the messages."\r
+ If the remove switch is given, tags will be removed instead of\r
+ added."\r
+   (goto-char (point-min))\r
+-  (let ((tag-function (if remove\r
+-                        'notmuch-show-remove-tag\r
+-                      'notmuch-show-add-tag)))\r
+-    (loop do (funcall tag-function tag)\r
++  (let ((op (if remove "-" "+")))\r
++    (loop do (notmuch-show-tag-message (concat op tag))\r
+         until (not (notmuch-show-goto-message-next)))))\r
+ \r
+ (defun notmuch-show-add-tag-thread (tag)\r
+@@ -1653,9 +1633,8 @@ If a prefix argument is given, the message will be\r
+ \"unarchived\" (ie. the \"inbox\" tag will be added instead of\r
+ removed)."\r
+   (interactive "P")\r
+-  (if unarchive\r
+-      (notmuch-show-add-tag "inbox")\r
+-    (notmuch-show-remove-tag "inbox")))\r
++  (let ((op (if unarchive "+" "-")))\r
++    (notmuch-show-tag-message (concat op "inbox"))))\r
+ \r
+ (defun notmuch-show-archive-message-then-next ()\r
+   "Archive the current message, then show the next open message in the current thread."\r
+-- \r
+1.7.9\r
+\r