[PATCH WIP v2 2/6] emacs: show: add some seen helpers

Mark Walters markwalters1009 at gmail.com
Sun Dec 1 02:02:23 PST 2013


We separate out "seeing" a message from marking it read. The intention
is only to mark read at certain times (eg quitting a show buffer). We
use the term seen to mean we have seen the message (for some
definition of seen) in the current buffer, but have not (typically)
marked the message read yet.

This adds helper functions to test/set the seen property and a
function to tag all seen messages read. The last of these tells the
user how many messages have been marked read.  It also takes an
argument that tells the function not to do any marking.  This last use
case displays a messages saying "Not marking messages read" and keeps
the logic of what to do when the user does not want to sync seen to
read in one place.
---
 emacs/notmuch-show.el |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index a135e79..c63d295 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1536,6 +1536,40 @@ marked as unread, i.e. the tag changes in
     (apply 'notmuch-show-tag-message
 	   (notmuch-tag-change-list notmuch-show-mark-read-tags unread))))
 
+(defun notmuch-show-seen-p ()
+  "Return t if current message has been seen."
+  (notmuch-show-get-prop :seen))
+
+(defun notmuch-show-mark-seen ()
+  "Mark current message seen."
+  (notmuch-show-set-prop :seen t))
+
+(defun notmuch-show-mark-all-seen-read (&optional not-mark)
+  "Mark read all messages that have been seen in this buffer.
+
+If NOT-MARK then do not mark the messages read, and tell the user
+we are not marking them."
+  (if not-mark
+      (message "Not marking messages read")
+    (let ((messages-to-mark-read))
+      ;; We get a list of all message to tag read. A list means that
+      ;; we can tag all the messages in one tag operation rather than
+      ;; needing one per read message.
+      (notmuch-show-mapc
+       (lambda ()
+	 (when (and (notmuch-show-seen-p) (notmuch-show-unread-p))
+	   (push (notmuch-show-get-message-id) messages-to-mark-read))))
+      (when messages-to-mark-read
+	(notmuch-tag (mapconcat #'identity messages-to-mark-read " ")
+		     (notmuch-tag-change-list notmuch-show-mark-read-tags)))
+      (let ((count (length messages-to-mark-read)))
+	(cond ((> count 1)
+	       (message "Marked %s messages read" count))
+	      ((= count 1)
+	       (message "Marked one message read"))
+	      ((= count 0)
+	       (message "No messages marked read")))))))
+
 ;; Functions for getting attributes of several messages in the current
 ;; thread.
 
-- 
1.7.9.1



More information about the notmuch mailing list