[PATCH 5/5] emacs: show tag completion

Mark Walters markwalters1009 at gmail.com
Fri Nov 30 00:21:31 PST 2012


From: markwalters1009 <markwalters1009 at gmail.com>

This makes tagging in show mode pass the list of tags that it believes
occur to the tag completion function. This means that tag-completion
will complete to any tag that the user can see (even if it is no
longer present).
---
The function to get all tags for a thread was taken from Damien's
notmuch-labeler series.

 emacs/notmuch-show.el |   32 +++++++++++++++++++++++++-------
 1 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 489e32c..c2fef7b 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1439,6 +1439,16 @@ current thread."
   "Return the tags of the current message."
   (notmuch-show-get-prop :tags))
 
+(defun notmuch-show-thread-tags ()
+  "Return the list of tags for the current thread."
+  (let ((tags (list)))
+    (notmuch-show-mapc (lambda ()
+			 (mapcar (lambda (elt)
+				   ;; Avoid adding duplicate tags
+				   (add-to-list 'tags elt))
+				 (notmuch-show-get-tags))))
+    tags))
+
 (defun notmuch-show-message-visible-p ()
   "Is the current message visible?"
   (notmuch-show-get-prop :message-visible))
@@ -1730,9 +1740,13 @@ TAG-CHANGES is a list of tag operations for `notmuch-tag'."
 
 See `notmuch-tag' for information on the format of TAG-CHANGES."
   (interactive)
-  (setq tag-changes (funcall 'notmuch-tag (notmuch-show-get-message-id) tag-changes))
-  (let* ((current-tags (notmuch-show-get-tags))
-	 (new-tags (notmuch-update-tags current-tags tag-changes)))
+  (let ((current-tags (notmuch-show-get-tags))
+	(new-tags))
+    (setq tag-changes (funcall 'notmuch-tag
+			       (notmuch-show-get-message-id)
+			       tag-changes
+			       current-tags))
+    (setq new-tags (notmuch-update-tags current-tags tag-changes))
     (unless (equal current-tags new-tags)
       (notmuch-show-set-tags new-tags))))
 
@@ -1741,13 +1755,17 @@ See `notmuch-tag' for information on the format of TAG-CHANGES."
 
 See `notmuch-tag' for information on the format of TAG-CHANGES."
   (interactive)
-  (setq tag-changes (funcall 'notmuch-tag (notmuch-show-get-messages-ids-search) tag-changes))
-  (notmuch-show-mapc
-   (lambda ()
+  (let ((existing-tags (notmuch-show-thread-tags)))
+    (setq tag-changes (funcall 'notmuch-tag
+			       (notmuch-show-get-messages-ids-search)
+			       tag-changes
+			       existing-tags))
+    (notmuch-show-mapc
+     (lambda ()
      (let* ((current-tags (notmuch-show-get-tags))
 	    (new-tags (notmuch-update-tags current-tags tag-changes)))
        (unless (equal current-tags new-tags)
-	 (notmuch-show-set-tags new-tags))))))
+	 (notmuch-show-set-tags new-tags)))))))
 
 (defun notmuch-show-add-tag ()
   "Same as `notmuch-show-tag' but sets initial input to '+'."
-- 
1.7.9.1



More information about the notmuch mailing list