[PATCH v2 10/13] emacs: use message ids instead of thread id in `notmuch-show-operate-all'

Dmitry Kurochkin dmitry.kurochkin at gmail.com
Sun Jan 29 18:26:19 PST 2012


Before the change, `notmuch-show-operate-all' used thread id for
"notmuch tag" search.  This could result in tagging unexpected
messages that were added to the thread after the notmuch-show buffer
was created.  The patch changes `notmuch-show-operate-all' to use ids
of shown messages to fix this.
---
 emacs/notmuch-show.el |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 0d90c1e..b115a8f 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1170,6 +1170,15 @@ All currently available key bindings:
     (notmuch-show-move-to-message-top)
     t))
 
+(defun notmuch-show-mapc (function)
+  "Iterate through all messages in the current thread with
+`notmuch-show-goto-message-next' and call FUNCTION for side
+effects."
+  (save-excursion
+    (goto-char (point-min))
+    (loop do (funcall function)
+	  while (notmuch-show-goto-message-next))))
+
 ;; Functions relating to the visibility of messages and their
 ;; components.
 
@@ -1222,6 +1231,18 @@ Some useful entries are:
   "Return the message id of the current message."
   (concat "id:\"" (notmuch-show-get-prop :id) "\""))
 
+(defun notmuch-show-get-messages-ids ()
+  "Return all message ids of messages in the current thread."
+  (let ((message-ids))
+    (notmuch-show-mapc
+     (lambda () (push (notmuch-show-get-message-id) message-ids)))
+    message-ids))
+
+(defun notmuch-show-get-messages-ids-search ()
+  "Return a search string for all message ids of messages in the
+current thread."
+  (mapconcat 'identity (notmuch-show-get-messages-ids) " or "))
+
 ;; dme: Would it make sense to use a macro for many of these?
 
 (defun notmuch-show-get-filename ()
@@ -1494,7 +1515,7 @@ TAG-CHANGES is a list of tag operations for `notmuch-tag'."
 
 TAG-CHANGES is a list of tag operations for `notmuch-tag'."
   (interactive (notmuch-read-tag-changes nil notmuch-show-thread-id))
-  (apply 'notmuch-tag notmuch-show-thread-id tag-changes)
+  (apply 'notmuch-tag (notmuch-show-get-messages-ids-search) tag-changes)
   (save-excursion
     (goto-char (point-min))
     (loop do (let* ((current-tags (notmuch-show-get-tags))
-- 
1.7.8.3



More information about the notmuch mailing list