emacs: run notmuch-search-hook lazily

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.
This commit is contained in:
David Bremner 2021-09-12 22:03:50 -03:00
parent 1e7d33961e
commit eafb033d32

View file

@ -880,6 +880,14 @@ sets the :orig-tag property."
(setq notmuch-search-target-thread "found") (setq notmuch-search-target-thread "found")
(goto-char pos)))) (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) (defun notmuch-search-process-filter (proc string)
"Process and filter the output of \"notmuch search\"." "Process and filter the output of \"notmuch search\"."
(let ((results-buf (process-buffer proc)) (let ((results-buf (process-buffer proc))
@ -892,7 +900,9 @@ sets the :orig-tag property."
(goto-char (point-max)) (goto-char (point-max))
(insert string)) (insert string))
(notmuch-sexp-parse-partial-list 'notmuch-search-append-result (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) ;;; Commands (and some helper functions used by them)
@ -1036,8 +1046,7 @@ the configured default sort order."
(process-put proc 'parse-buf (process-put proc 'parse-buf
(generate-new-buffer " *notmuch search parse*")) (generate-new-buffer " *notmuch search parse*"))
(set-process-filter proc 'notmuch-search-process-filter) (set-process-filter proc 'notmuch-search-process-filter)
(set-process-query-on-exit-flag proc nil)))) (set-process-query-on-exit-flag proc nil))))))
(run-hooks 'notmuch-search-hook)))
(defun notmuch-search-refresh-view () (defun notmuch-search-refresh-view ()
"Refresh the current view. "Refresh the current view.