mu4e: always run mu4e-index-updated-hook after index

Fire mu4e-index-updated-hook after any index operations, where anything changed
or not. Add a new variable `mu4e-index-update-status' which can be used to see
what changed (if anything) in the last indexing operation.

Keep mu4e-message-changed-hook in place; it only fires when a message
changed (and when it is update).

Remove the long-obsolete `mu4e-msg-changed-hook'.
This commit is contained in:
Dirk-Jan C. Binnema 2021-10-21 19:13:02 +03:00
parent 4adee3c1f0
commit f3e3cc9ca2
3 changed files with 38 additions and 26 deletions

View File

@ -46,6 +46,7 @@
(require 'mu4e-actions)
(require 'mu4e-message)
(require 'mu4e-lists)
(require 'mu4e-update)
(require 'mu4e-folders)
(declare-function mu4e-view "mu4e-view")
@ -1085,9 +1086,11 @@ after the end of the search results."
(defun mu4e~headers-maybe-auto-update ()
"Update the current headers buffer after indexing has brought
some changes, `mu4e-headers-auto-update' is non-nil and there is
no user-interaction ongoing."
(when (and mu4e-headers-auto-update ;; must be set
some changes, `mu4e-headers-auto-update' is non-nil and there
isno user-interaction ongoing."
(when (and mu4e-headers-auto-update ;; must be set
mu4e-index-update-status
(> 0 (plist-get mu4e-index-update-status :updated))
(zerop (mu4e-mark-marks-num)) ;; non active marks
(not (active-minibuffer-window))) ;; no user input only
;; rerun search if there's a live window with search results;
@ -1106,10 +1109,7 @@ no user-interaction ongoing."
(set (make-local-variable 'hl-line-face) 'mu4e-header-highlight-face)
;; maybe update the current headers upon indexing changes
(add-hook 'mu4e-index-updated-hook 'mu4e~headers-maybe-auto-update)
(add-hook 'mu4e-index-updated-hook
#'mu4e~headers-index-updated-hook-fn
t)
(add-hook 'mu4e-index-updated-hook #'mu4e~headers-maybe-auto-update)
(setq
truncate-lines t
buffer-undo-list t ;; don't record undo information
@ -1122,9 +1122,6 @@ no user-interaction ongoing."
(mu4e-search-minor-mode)
(hl-line-mode 1))
(defun mu4e~headers-index-updated-hook-fn ()
(run-hooks 'mu4e-message-changed-hook))
;;; Highlighting
(defvar mu4e~highlighted-docid nil

View File

@ -85,7 +85,8 @@ When this is set to non-nil, mu only uses the directory
timestamps to decide whether it needs to check the messages
beneath it. This makes indexing much faster, but might miss some
changes. For this, you might want to occasionally call
`mu4e-update-index-nonlazy'."
`mu4e-update-index-nonlazy'; `mu4e-update-pre-hook' can be used
to automate this."
:type 'boolean
:group 'mu4e
:safe 'booleanp)
@ -109,22 +110,26 @@ some specific setting.")
:type 'boolean
:group 'mu4e)
(defvar mu4e-index-updated-hook nil
"Hook run when the indexing process had one or more updated messages.
This can be used as a simple way to invoke some action when new
messages appear, but note that an update in the index does not
necessarily mean a new message.")
"Hook run when the indexing process has completed.
The variable `mu4e-index-update-status' can be used to get
information about what changed.")
(defvar mu4e-message-changed-hook nil
"Hook run when there is a message changed in db.
"Hook run when there is a message changed in the data store.
For new messages, it depends on `mu4e-index-updated-hook'. This
can be used as a simple way to invoke some action when a message
changed.")
changed")
(make-obsolete-variable 'mu4e-msg-changed-hook
'mu4e-message-changed-hook "0.9.19")
(defvar mu4e-index-update-status nil
"Last-seen completed update status, based on server status messages.
If non-nil, this is a plist of the form:
\(
:processed <number of messages processed>
:updated <number of messages updated (incl. new messages)
:cleaned-up <number of stale messages removed from store
:stamp <emacs (current-time) timestamp for the status)")

View File

@ -187,6 +187,14 @@ successful, call FUNC (if non-nil) afterwards."
(110 (display-warning 'mu4e errmsg :error)) ;; schema version.
(t (mu4e-error "Error %d: %s" errcode errmsg))))
(defun mu4e--update-status (info)
"Update the status message."
(setq mu4e-index-update-status
`(:tstamp ,(current-time)
:updated ,(plist-get info :updated)
:processed ,(plist-get info :processed)
:cleaned-up ,(plist-get info :cleaned-up))))
(defun mu4e--info-handler (info)
"Handler function for (:INFO ...) sexps received from server."
(let* ((type (plist-get info :info))
@ -200,15 +208,17 @@ successful, call FUNC (if non-nil) afterwards."
(if (eq (plist-get info :status) 'running)
(mu4e-index-message
"Indexing... processed %d, updated %d" processed updated)
(progn
(progn ;; i.e. 'complete
(mu4e--update-status info)
(mu4e-index-message
"%s completed; processed %d, updated %d, cleaned-up %d"
(if mu4e-index-lazy-check "Lazy indexing" "Indexing")
processed updated cleaned-up)
;; call the updated hook if anything changed.
(unless (zerop (+ updated cleaned-up))
(run-hooks 'mu4e-index-updated-hook))
(unless (and (not (string= mu4e--contacts-tstamp "0"))
(run-hooks 'mu4e-index-updated-hook)
;; backward compatibility...
(unless (zerop (+ updated cleaned-up))
mu4e-message-changed-hook)
(unless (and (not (string= mu4e--contacts-tstamp "0"))
(zerop (plist-get info :updated)))
(mu4e--request-contacts-maybe))
(when (and (buffer-live-p mainbuf) (get-buffer-window mainbuf))