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

Dmitry Kurochkin dmitry.kurochkin at gmail.com
Fri Jan 27 21:59:07 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 2ca4d92..e606224 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 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 currently shown messages."
+  (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 currently shown
+messages."
+  (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 ()
@@ -1496,7 +1517,7 @@ i.e. a list of tags to change with '+' and '-' prefixes."
 `Changed-tags' is a list of tag operations for \"notmuch tag\",
 i.e. a list of tags to change with '+' and '-' prefixes."
   (interactive (notmuch-select-tags-with-completion nil notmuch-show-thread-id))
-  (apply 'notmuch-tag notmuch-show-thread-id changed-tags)
+  (apply 'notmuch-tag (notmuch-show-get-messages-ids-search) changed-tags)
   (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