From: Mark Walters <markwalters1009@gmail.com>
To: notmuch@notmuchmail.org
Subject: [PATCH 1/5] emacs: show: make `seen' mean user viewed whole message
Date: Sat, 14 Dec 2013 23:44:32 +0000 [thread overview]
Message-ID: <1387064676-15508-2-git-send-email-markwalters1009@gmail.com> (raw)
In-Reply-To: <1387064676-15508-1-git-send-email-markwalters1009@gmail.com>
This changes `seen' to mean that the user viewed `enough' of the whole
message: more precisely, a message is deemed seen if the top of the
message and either the bottom of the message or a point at least some
customisable number of lines into the message have each been visible
in the buffer at some point.
This is placed into the post-command-hook infrastructure introudced in
the previous patch.
---
emacs/notmuch-show.el | 73 +++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 71 insertions(+), 2 deletions(-)
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 51366e9..4850bd0 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -211,6 +211,19 @@ For example, if you wanted to remove an \"unread\" tag and add a
:type '(repeat string)
:group 'notmuch-show)
+(defcustom notmuch-show-seen-lines-needed 0.75
+ "Control which messages get marked seen.
+
+A message is marked seen 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, but additionally...it an integer n then at least n
+lines of message must be visible in the window. If it is a float
+x then at least that proportion of the window must contain the
+message."
+ :type 'number
+ :group 'notmuch-show)
(defmacro with-current-notmuch-show-message (&rest body)
"Evaluate body with current buffer set to the text of current message"
@@ -1541,9 +1554,65 @@ 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-local))
+ new)
+ (unless (eq current 'both)
+ (if (eq top-or-bottom 'top)
+ (if (eq current 'bottom)
+ (setq new 'both)
+ (setq new 'top))
+ (if (eq current 'top)
+ (setq new 'both)
+ (setq new 'bottom)))
+ (unless (eq current new)
+ (notmuch-show-set-prop :seen-local new))
+ (when (eq new 'both)
+ (notmuch-show-mark-read)))))
+
+(defun notmuch-show-do-message-seen (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
+`notmuch-show-seen-lines-needed` if that is an integer and that
+times the current window height if it is a float."
+ (let* ((lines-needed (if (integerp notmuch-show-seen-lines-needed)
+ notmuch-show-seen-lines-needed
+ (truncate (* notmuch-show-seen-lines-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 (start end)
- "Update seen status for all messages between start and end."
- )
+ "Update seen status for all messages between start and end.
+
+A message is seen if both the top and enough of the rest of the
+message have been visible in the buffer. See
+`notmuch-show-do-message-seen` for the definition of enough. Seen
+is a buffer local property. The unread status is removed from all
+seen messages when the user quits the show buffer."
+ (save-excursion
+ (goto-char start)
+ (while (and (or (notmuch-show-do-message-seen start end) t)
+ (< (notmuch-show-message-bottom) end)
+ (notmuch-show-goto-message-next)))
+
+ ;; 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-command-hook ()
(when (eq major-mode 'notmuch-show-mode)
--
1.7.9.1
next prev parent reply other threads:[~2013-12-14 23:44 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-14 23:44 [PATCH 0/5] emacs: show: redesign unread/read logic Mark Walters
2013-12-14 23:44 ` Mark Walters [this message]
2013-12-14 23:44 ` [PATCH 2/5] emacs: show: add an update seen function to post-command-hook Mark Walters
2013-12-14 23:44 ` [PATCH 3/5] emacs: show: mark tags changed since buffer loaded Mark Walters
2013-12-14 23:44 ` [PATCH 4/5] emacs: tree: make the tree code force the mark read update Mark Walters
2013-12-14 23:44 ` [PATCH 5/5] test: make test_emacs call post-command-hook Mark Walters
2014-01-22 1:32 ` [PATCH] " David Bremner
2014-01-23 17:35 ` Mark Walters
2014-01-24 14:58 ` Tomi Ollila
2014-01-24 15:52 ` David Bremner
2014-01-24 18:34 ` Tomi Ollila
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1387064676-15508-2-git-send-email-markwalters1009@gmail.com \
--to=markwalters1009@gmail.com \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).