[PATCH] emacs: show: mark messages unread if seen in buffer
Mark Walters
markwalters1009 at gmail.com
Wed Jul 16 10:55:39 PDT 2014
This adds a function that marks messages unread if they are "seen"
that is a user configurable amount of them has been visible in the
buffer.
---
This adds my preferred mark unread function as an option: see
id:1399650320-1382-1-git-send-email-markwalters1009 at gmail.com for a
previous version. This version moves this functions configuration
parameter inside the defcustom. I am not sure if this (using :set) is
the best way to do that but it works and will work if other people
want to add functions which have parameters too.
Best wishes
Mark
emacs/notmuch-show.el | 76 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 75 insertions(+), 1 deletion(-)
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 529baa9..9563a74 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -225,7 +225,29 @@ For example, if you wanted to remove an \"unread\" tag and add a
(defcustom notmuch-show-mark-read-function #'notmuch-show-seen-current-message
"Function to control which messages are marked read."
- :type 'function
+ :type '(radio (const :format "%h" :doc "Mark current message read.
+
+Marks the message containing point read."
+ notmuch-show-seen-current-message)
+ (list :format "%v"
+ (const :tag "Mark read if enough of the message has been visible" notmuch-show-do-seen)
+ (number :format "%h %v"
+ :doc "Proportion or Lines needed
+
+A message is marked read if both the top of the message
+and a point far \"enough\" down in the message have each been
+visible in the buffer at some point. This parameter controls the
+definition of enough. Seeing the bottom of message is always
+deemed enough. Additionally, it is deemed enough if a point n
+lines into the message has been visible in the window where n is
+this variable if this variable is an integer and n is this
+variable times the height of the window if this variable is a
+float."
+ :value 0.75))
+ (function))
+ :set (lambda (symbol value) (if (listp value)
+ (set-default symbol (apply 'apply-partially (car value) (cdr value)))
+ (set-default symbol value)))
:group 'notmuch-show)
(defmacro with-current-notmuch-show-message (&rest body)
@@ -1569,6 +1591,58 @@ 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-update-seen (top-or-bottom)
+ "Update seen status of current message
+
+Mark that we have seen the TOP-OR-BOTTOM of current message."
+ (let ((current (notmuch-show-get-prop :seen)))
+ (unless (or (eq current 'both) (eq current top-or-bottom))
+ (if (not current)
+ (notmuch-show-set-prop :seen top-or-bottom)
+ (notmuch-show-set-prop :seen 'both)
+ (notmuch-show-mark-read)))))
+
+(defun notmuch-show-do-message-seen (needed start end)
+ "Update seen status for the current message.
+
+A message is seen if both the top and enough of the rest of the
+message have been visible in the buffer. Enough means either the
+bottom of the message or a point in the message more than
+LINES-NEEDED lines into the message. LINES-NEEDED is
+NEEDED if NEEDED is an integer and NEEDED
+times the current window height if NEEDED is a float."
+ (let* ((lines-needed (if (integerp needed)
+ needed
+ (truncate (* needed (window-body-height)))))
+ (top (notmuch-show-message-top))
+ (bottom (notmuch-show-message-bottom)))
+ (when (notmuch-show-message-visible-p)
+ (when (>= top start)
+ (notmuch-show-update-seen 'top))
+ (when (or (<= bottom end)
+ (> (count-screen-lines top end) lines-needed))
+ (notmuch-show-update-seen 'bottom)))))
+
+(defun notmuch-show-do-seen (needed start end)
+ "Update seen status for all messages between start and end.
+
+We mark the top (bottom) of a message seen if the top (enough of
+the rest of the message) respectively have been visible in the
+buffer. See `notmuch-show-do-message-seen` for the definition of
+enough. When both the top and bottom have been seen we mark the
+message read."
+ (save-excursion
+ (goto-char start)
+ (notmuch-show-do-message-seen needed start end)
+ (while (and (< (notmuch-show-message-bottom) end)
+ (notmuch-show-goto-message-next))
+ (notmuch-show-do-message-seen needed start end))
+ ;; This is a work around because emacs gives weird answers for
+ ;; window-end if the buffer ends with invisible text.
+ (when (and (pos-visible-in-window-p (point-max))
+ (notmuch-show-message-visible-p))
+ (notmuch-show-update-seen 'bottom))))
+
(defun notmuch-show-seen-current-message (start end)
"Mark the current message read if it is open.
--
1.7.10.4
More information about the notmuch
mailing list