From: David Bremner <david@tethera.net>
To: Fabio Natali <me@fabionatali.com>, notmuch@notmuchmail.org
Cc: David Bremner <david@tethera.net>
Subject: [PATCH] emacs: run notmuch-search-hook lazily
Date: Sun, 12 Sep 2021 22:03:50 -0300 [thread overview]
Message-ID: <20210913010350.2211117-1-david@tethera.net> (raw)
In-Reply-To: <YT3ueuZHKW931NW3@localhost>
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
next prev parent reply other threads:[~2021-09-13 1:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-12 12:11 Minor UX issue with hl-line-mode and notmuch-search Fabio Natali
2021-09-13 1:03 ` David Bremner [this message]
2021-12-04 16:14 ` [PATCH] emacs: run notmuch-search-hook lazily David Bremner
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=20210913010350.2211117-1-david@tethera.net \
--to=david@tethera.net \
--cc=me@fabionatali.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).