From f3e3cc9ca2ba3eb6c40e464f79c6d9a9fa294371 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Thu, 21 Oct 2021 19:13:02 +0300 Subject: [PATCH] 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'. --- mu4e/mu4e-headers.el | 17 +++++++---------- mu4e/mu4e-update.el | 27 ++++++++++++++++----------- mu4e/mu4e.el | 20 +++++++++++++++----- 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/mu4e/mu4e-headers.el b/mu4e/mu4e-headers.el index 4d0df787..c49ee206 100644 --- a/mu4e/mu4e-headers.el +++ b/mu4e/mu4e-headers.el @@ -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 diff --git a/mu4e/mu4e-update.el b/mu4e/mu4e-update.el index 5f07ceea..790085a1 100644 --- a/mu4e/mu4e-update.el +++ b/mu4e/mu4e-update.el @@ -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 +:updated