unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [Patch v2 0/2] emacs: show: mark messages read if seen in buffer
@ 2014-09-06 16:22 Mark Walters
  2014-09-06 16:22 ` [Patch v2 1/2] emacs: show: document the mark unread defcustom function Mark Walters
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Mark Walters @ 2014-09-06 16:22 UTC (permalink / raw)
  To: notmuch

This is v2 of this patch: v1 is at id:1405533339-7666-1-git-send-email-markwalters1009@gmail.com

The first patch just documents what is required for a mark-read
function. The second patch adds my preferred logic of marking a
message seen if `enough' of it has been visible in the buffer.

There are two changes from v1. First patch 1 is new. Secondly I have
modified the defcustom for the second patch. It is slightly fiddly as
my function has a parameter the default function does not. The
defcustom in the previous patch worked but it was unable to parse
itself so when you revisited the defcustom it looked like you had
specified the lisp manually rather than having selected one of the two
options.

The new version fixes this so the defcustom behaves exactly as you would expect.

I like this version of the mark read function; but it is quite a lot
of code (all unused unless the user selects this option so it is low
risk). If people would prefer not to include it then I can just post
the relevant code to the wiki and people can add it to their .emacs
file if they want this function.

Best wishes

Mark




Mark Walters (2):
  emacs: show: document the mark unread defcustom function
  emacs: show: mark messages unread if seen in buffer

 emacs/notmuch-show.el |   82 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 80 insertions(+), 2 deletions(-)

-- 
1.7.10.4

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Patch v2 1/2] emacs: show: document the mark unread defcustom function
  2014-09-06 16:22 [Patch v2 0/2] emacs: show: mark messages read if seen in buffer Mark Walters
@ 2014-09-06 16:22 ` Mark Walters
  2014-09-08 16:10   ` Tomi Ollila
  2014-11-09 17:58   ` David Bremner
  2014-09-06 16:22 ` [Patch v2 2/2] emacs: show: mark messages unread if seen in buffer Mark Walters
  2014-09-08  9:19 ` [Patch v2 0/2] emacs: show: mark messages read " David Edmondson
  2 siblings, 2 replies; 6+ messages in thread
From: Mark Walters @ 2014-09-06 16:22 UTC (permalink / raw)
  To: notmuch

---
 emacs/notmuch-show.el |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 7549fbb..5695d95 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -224,7 +224,13 @@ For example, if you wanted to remove an \"unread\" tag and add a
   :group 'notmuch-show)
 
 (defcustom notmuch-show-mark-read-function #'notmuch-show-seen-current-message
-  "Function to control which messages are marked read."
+  "Function to control which messages are marked read.
+
+The function should take two arguments START and END which will
+be the start and end of the visible portion of the buffer and
+should mark the appropriate messages read by applying
+`notmuch-show-mark-read'. This function will be called after
+every user interaction with notmuch."
   :type 'function
   :group 'notmuch-show)
 
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Patch v2 2/2] emacs: show: mark messages unread if seen in buffer
  2014-09-06 16:22 [Patch v2 0/2] emacs: show: mark messages read if seen in buffer Mark Walters
  2014-09-06 16:22 ` [Patch v2 1/2] emacs: show: document the mark unread defcustom function Mark Walters
@ 2014-09-06 16:22 ` Mark Walters
  2014-09-08  9:19 ` [Patch v2 0/2] emacs: show: mark messages read " David Edmondson
  2 siblings, 0 replies; 6+ messages in thread
From: Mark Walters @ 2014-09-06 16:22 UTC (permalink / raw)
  To: notmuch

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.
---
 emacs/notmuch-show.el |   74 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 73 insertions(+), 1 deletion(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 5695d95..7d2c5d2 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -231,7 +231,27 @@ be the start and end of the visible portion of the buffer and
 should mark the appropriate messages read by applying
 `notmuch-show-mark-read'. This function will be called after
 every user interaction with notmuch."
-  :type 'function
+  :type '(radio (const :format "%h" :doc "Mark current message read.
+
+Marks the message containing point read."
+		       notmuch-show-seen-current-message)
+		(group :format "%v"
+		      (const :inline t :format "" (lambda (start end)))
+		      (list :format "%h %v\n"
+			    :doc "Mark read if enough of the message has been visible.
+
+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. The definition of enough is
+controlled by the following paramater. 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."
+			    (const :inline t :tag "" :format "" (notmuch-show-do-seen start end))
+			    (number :tag "Proportion needed" 0.75)))
+		(function))
   :group 'notmuch-show)
 
 (defmacro with-current-notmuch-show-message (&rest body)
@@ -1576,6 +1596,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 (start end needed)
+  "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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Patch v2 0/2] emacs: show: mark messages read if seen in buffer
  2014-09-06 16:22 [Patch v2 0/2] emacs: show: mark messages read if seen in buffer Mark Walters
  2014-09-06 16:22 ` [Patch v2 1/2] emacs: show: document the mark unread defcustom function Mark Walters
  2014-09-06 16:22 ` [Patch v2 2/2] emacs: show: mark messages unread if seen in buffer Mark Walters
@ 2014-09-08  9:19 ` David Edmondson
  2 siblings, 0 replies; 6+ messages in thread
From: David Edmondson @ 2014-09-08  9:19 UTC (permalink / raw)
  To: Mark Walters, notmuch

I like the general approach.

On Sat, Sep 06 2014, Mark Walters wrote:
> There are two changes from v1. First patch 1 is new. Secondly I have
> modified the defcustom for the second patch. It is slightly fiddly as
> my function has a parameter the default function does not. The
> defcustom in the previous patch worked but it was unable to parse
> itself so when you revisited the defcustom it looked like you had
> specified the lisp manually rather than having selected one of the two
> options.

Is this because you want to include the parameter at the same point in
the custom definition? It's not uncommon to have a separate variable for
(things like) the proportion. It would make the declaration much simpler.

> I like this version of the mark read function; but it is quite a lot
> of code (all unused unless the user selects this option so it is low
> risk). If people would prefer not to include it then I can just post
> the relevant code to the wiki and people can add it to their .emacs
> file if they want this function.

If it's not the default, then I would be in favour of including it.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Patch v2 1/2] emacs: show: document the mark unread defcustom function
  2014-09-06 16:22 ` [Patch v2 1/2] emacs: show: document the mark unread defcustom function Mark Walters
@ 2014-09-08 16:10   ` Tomi Ollila
  2014-11-09 17:58   ` David Bremner
  1 sibling, 0 replies; 6+ messages in thread
From: Tomi Ollila @ 2014-09-08 16:10 UTC (permalink / raw)
  To: Mark Walters, notmuch

On Sat, Sep 06 2014, Mark Walters <markwalters1009@gmail.com> wrote:

> ---
>  emacs/notmuch-show.el |    8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
> index 7549fbb..5695d95 100644
> --- a/emacs/notmuch-show.el
> +++ b/emacs/notmuch-show.el
> @@ -224,7 +224,13 @@ For example, if you wanted to remove an \"unread\" tag and add a
>    :group 'notmuch-show)
>  
>  (defcustom notmuch-show-mark-read-function #'notmuch-show-seen-current-message
> -  "Function to control which messages are marked read."
> +  "Function to control which messages are marked read.
> +
> +The function should take two arguments START and END which will
> +be the start and end of the visible portion of the buffer and
> +should mark the appropriate messages read by applying
> +`notmuch-show-mark-read'. This function will be called after
> +every user interaction with notmuch."

This patch LGTM. Now that we know more I would have liked this function
would not take the START & END parameters but the function itself could
have done (window-start) (window-end) if it so desires...

... as we have discussed in IRC my current version uses (point) in place
of END (window-end) and I may drop START too (while investigating Mark's
IRC-given suggestions).

Anyway, the ship may have sailed and therefore I am inclined to give +1
to this patch...

Tomi


>    :type 'function
>    :group 'notmuch-show)
>  
> -- 
> 1.7.10.4
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Patch v2 1/2] emacs: show: document the mark unread defcustom function
  2014-09-06 16:22 ` [Patch v2 1/2] emacs: show: document the mark unread defcustom function Mark Walters
  2014-09-08 16:10   ` Tomi Ollila
@ 2014-11-09 17:58   ` David Bremner
  1 sibling, 0 replies; 6+ messages in thread
From: David Bremner @ 2014-11-09 17:58 UTC (permalink / raw)
  To: Mark Walters, notmuch

Mark Walters <markwalters1009@gmail.com> writes:

> ---
>  emacs/notmuch-show.el |    8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)

pushed to master and release.

d

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-11-09 17:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-06 16:22 [Patch v2 0/2] emacs: show: mark messages read if seen in buffer Mark Walters
2014-09-06 16:22 ` [Patch v2 1/2] emacs: show: document the mark unread defcustom function Mark Walters
2014-09-08 16:10   ` Tomi Ollila
2014-11-09 17:58   ` David Bremner
2014-09-06 16:22 ` [Patch v2 2/2] emacs: show: mark messages unread if seen in buffer Mark Walters
2014-09-08  9:19 ` [Patch v2 0/2] emacs: show: mark messages read " David Edmondson

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).