unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* Minor UX issue with hl-line-mode and notmuch-search
@ 2021-09-12 12:11 Fabio Natali
  2021-09-13  1:03 ` [PATCH] emacs: run notmuch-search-hook lazily David Bremner
  0 siblings, 1 reply; 3+ messages in thread
From: Fabio Natali @ 2021-09-12 12:11 UTC (permalink / raw)
  To: notmuch

Hi All,

This is to describe a minor UX inconsistency with hl-line-mode in the
Notmuch search page.

How to reproduce: Enter the Notmuch search page, search results are
shown, no message is highlighted. Scroll down the list with your arrow
keys to trigger the highlighting.

What (I think?) should happen instead: Upon entering the search page,
the first search result should be highlighted
straightaway. Nice-to-have: see at the bottom.

By looking at the code, I think the issue may be in the way Notmuch
search hooks are called here [0].

Adding a short delay, e.g. `(sit-for 1)', before `(run-hooks
'notmuch-search-hook)' solves the issue - at the cost of having a fixed
delay though, which is unacceptable of course. An actual solution might
involve to make sure these hooks are only launched synchronously once
the buffer has been displayed?

This is a minor UX glitch but could the effects of this be more serious
should the user user redefine `notmuch-search-hook'?

Nice to have: No highlighting should happen on empty search buffers;
what we now have instead is that "End of search results" gets
highlighted when moving on top of it with your cursor. This clashes with
the idea that if it's highlighted then it's something I can select and
interact with. This is probably a wont-fix though, too hard to achieve
with the hl-line-mode machinery?

I'd be glad to hear your thoughts on this, I'm not particularly familiar
with Emacs Lisp but happy to try and contribute if I can.

Thanks and best,

Fabio.


- [0] https://git.notmuchmail.org/git?p=notmuch;a=blob;f=emacs/notmuch.el;h=2ef67c0e798dbc65c144cef77cd8642c506f98c0;hb=21e365f51a7ff17e5154cf06396aeafe3f7d9bd7#l1040

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

* [PATCH] emacs: run notmuch-search-hook lazily
  2021-09-12 12:11 Minor UX issue with hl-line-mode and notmuch-search Fabio Natali
@ 2021-09-13  1:03 ` David Bremner
  2021-12-04 16:14   ` David Bremner
  0 siblings, 1 reply; 3+ messages in thread
From: David Bremner @ 2021-09-13  1:03 UTC (permalink / raw)
  To: Fabio Natali, notmuch; +Cc: David Bremner

In message id:YT3ueuZHKW931NW3@localhost, Fabio Natali isolated a
visual glitch caused by running notmuch-search-hook too early. This
change moves the running of that hook to
notmuch-search-process-filter, which ensures there is some output in
the buffer before running the hook. Since n-s-p-f can be called many
times for a given buffer, add a buffer local flag to make sure it is
only run once per buffer.
---
 emacs/notmuch.el | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 2ef67c0e..052f7578 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -880,6 +880,14 @@ sets the :orig-tag property."
       (setq notmuch-search-target-thread "found")
       (goto-char pos))))
 
+(defvar-local notmuch--search-hook-run nil
+  "Flag used to ensure the notmuch-search-hook is only run once per buffer")
+
+(defun notmuch--search-hook-wrapper ()
+  (unless notmuch--search-hook-run
+    (setq notmuch--search-hook-run t)
+    (run-hooks 'notmuch-search-hook)))
+
 (defun notmuch-search-process-filter (proc string)
   "Process and filter the output of \"notmuch search\"."
   (let ((results-buf (process-buffer proc))
@@ -892,7 +900,9 @@ sets the :orig-tag property."
 	  (goto-char (point-max))
 	  (insert string))
 	(notmuch-sexp-parse-partial-list 'notmuch-search-append-result
-					 results-buf)))))
+					 results-buf))
+      (with-current-buffer results-buf
+	(notmuch--search-hook-wrapper)))))
 
 ;;; Commands (and some helper functions used by them)
 
@@ -1036,8 +1046,7 @@ the configured default sort order."
 	  (process-put proc 'parse-buf
 		       (generate-new-buffer " *notmuch search parse*"))
 	  (set-process-filter proc 'notmuch-search-process-filter)
-	  (set-process-query-on-exit-flag proc nil))))
-    (run-hooks 'notmuch-search-hook)))
+	  (set-process-query-on-exit-flag proc nil))))))
 
 (defun notmuch-search-refresh-view ()
   "Refresh the current view.
-- 
2.33.0

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

* Re: [PATCH] emacs: run notmuch-search-hook lazily
  2021-09-13  1:03 ` [PATCH] emacs: run notmuch-search-hook lazily David Bremner
@ 2021-12-04 16:14   ` David Bremner
  0 siblings, 0 replies; 3+ messages in thread
From: David Bremner @ 2021-12-04 16:14 UTC (permalink / raw)
  To: Fabio Natali, notmuch

David Bremner <david@tethera.net> writes:

> In message id:YT3ueuZHKW931NW3@localhost, Fabio Natali isolated a
> visual glitch caused by running notmuch-search-hook too early. This
> change moves the running of that hook to
> notmuch-search-process-filter, which ensures there is some output in
> the buffer before running the hook. Since n-s-p-f can be called many
> times for a given buffer, add a buffer local flag to make sure it is
> only run once per buffer.

applied to master

d

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

end of thread, other threads:[~2021-12-04 16:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-12 12:11 Minor UX issue with hl-line-mode and notmuch-search Fabio Natali
2021-09-13  1:03 ` [PATCH] emacs: run notmuch-search-hook lazily David Bremner
2021-12-04 16:14   ` David Bremner

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