mirror of https://github.com/djcb/mu.git
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:
parent
4adee3c1f0
commit
f3e3cc9ca2
|
@ -46,6 +46,7 @@
|
||||||
(require 'mu4e-actions)
|
(require 'mu4e-actions)
|
||||||
(require 'mu4e-message)
|
(require 'mu4e-message)
|
||||||
(require 'mu4e-lists)
|
(require 'mu4e-lists)
|
||||||
|
(require 'mu4e-update)
|
||||||
(require 'mu4e-folders)
|
(require 'mu4e-folders)
|
||||||
|
|
||||||
(declare-function mu4e-view "mu4e-view")
|
(declare-function mu4e-view "mu4e-view")
|
||||||
|
@ -1085,9 +1086,11 @@ after the end of the search results."
|
||||||
|
|
||||||
(defun mu4e~headers-maybe-auto-update ()
|
(defun mu4e~headers-maybe-auto-update ()
|
||||||
"Update the current headers buffer after indexing has brought
|
"Update the current headers buffer after indexing has brought
|
||||||
some changes, `mu4e-headers-auto-update' is non-nil and there is
|
some changes, `mu4e-headers-auto-update' is non-nil and there
|
||||||
no user-interaction ongoing."
|
isno user-interaction ongoing."
|
||||||
(when (and mu4e-headers-auto-update ;; must be set
|
(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
|
(zerop (mu4e-mark-marks-num)) ;; non active marks
|
||||||
(not (active-minibuffer-window))) ;; no user input only
|
(not (active-minibuffer-window))) ;; no user input only
|
||||||
;; rerun search if there's a live window with search results;
|
;; 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)
|
(set (make-local-variable 'hl-line-face) 'mu4e-header-highlight-face)
|
||||||
|
|
||||||
;; maybe update the current headers upon indexing changes
|
;; 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-maybe-auto-update)
|
||||||
(add-hook 'mu4e-index-updated-hook
|
|
||||||
#'mu4e~headers-index-updated-hook-fn
|
|
||||||
t)
|
|
||||||
(setq
|
(setq
|
||||||
truncate-lines t
|
truncate-lines t
|
||||||
buffer-undo-list t ;; don't record undo information
|
buffer-undo-list t ;; don't record undo information
|
||||||
|
@ -1122,9 +1122,6 @@ no user-interaction ongoing."
|
||||||
(mu4e-search-minor-mode)
|
(mu4e-search-minor-mode)
|
||||||
(hl-line-mode 1))
|
(hl-line-mode 1))
|
||||||
|
|
||||||
(defun mu4e~headers-index-updated-hook-fn ()
|
|
||||||
(run-hooks 'mu4e-message-changed-hook))
|
|
||||||
|
|
||||||
;;; Highlighting
|
;;; Highlighting
|
||||||
|
|
||||||
(defvar mu4e~highlighted-docid nil
|
(defvar mu4e~highlighted-docid nil
|
||||||
|
|
|
@ -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
|
timestamps to decide whether it needs to check the messages
|
||||||
beneath it. This makes indexing much faster, but might miss some
|
beneath it. This makes indexing much faster, but might miss some
|
||||||
changes. For this, you might want to occasionally call
|
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
|
:type 'boolean
|
||||||
:group 'mu4e
|
:group 'mu4e
|
||||||
:safe 'booleanp)
|
:safe 'booleanp)
|
||||||
|
@ -109,22 +110,26 @@ some specific setting.")
|
||||||
:type 'boolean
|
:type 'boolean
|
||||||
:group 'mu4e)
|
:group 'mu4e)
|
||||||
|
|
||||||
|
|
||||||
(defvar mu4e-index-updated-hook nil
|
(defvar mu4e-index-updated-hook nil
|
||||||
"Hook run when the indexing process had one or more updated messages.
|
"Hook run when the indexing process has completed.
|
||||||
This can be used as a simple way to invoke some action when new
|
The variable `mu4e-index-update-status' can be used to get
|
||||||
messages appear, but note that an update in the index does not
|
information about what changed.")
|
||||||
necessarily mean a new message.")
|
|
||||||
|
|
||||||
|
|
||||||
(defvar mu4e-message-changed-hook nil
|
(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
|
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
|
can be used as a simple way to invoke some action when a message
|
||||||
changed.")
|
changed")
|
||||||
|
|
||||||
(make-obsolete-variable 'mu4e-msg-changed-hook
|
(defvar mu4e-index-update-status nil
|
||||||
'mu4e-message-changed-hook "0.9.19")
|
"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)")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
20
mu4e/mu4e.el
20
mu4e/mu4e.el
|
@ -187,6 +187,14 @@ successful, call FUNC (if non-nil) afterwards."
|
||||||
(110 (display-warning 'mu4e errmsg :error)) ;; schema version.
|
(110 (display-warning 'mu4e errmsg :error)) ;; schema version.
|
||||||
(t (mu4e-error "Error %d: %s" errcode errmsg))))
|
(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)
|
(defun mu4e--info-handler (info)
|
||||||
"Handler function for (:INFO ...) sexps received from server."
|
"Handler function for (:INFO ...) sexps received from server."
|
||||||
(let* ((type (plist-get info :info))
|
(let* ((type (plist-get info :info))
|
||||||
|
@ -200,15 +208,17 @@ successful, call FUNC (if non-nil) afterwards."
|
||||||
(if (eq (plist-get info :status) 'running)
|
(if (eq (plist-get info :status) 'running)
|
||||||
(mu4e-index-message
|
(mu4e-index-message
|
||||||
"Indexing... processed %d, updated %d" processed updated)
|
"Indexing... processed %d, updated %d" processed updated)
|
||||||
(progn
|
(progn ;; i.e. 'complete
|
||||||
|
(mu4e--update-status info)
|
||||||
(mu4e-index-message
|
(mu4e-index-message
|
||||||
"%s completed; processed %d, updated %d, cleaned-up %d"
|
"%s completed; processed %d, updated %d, cleaned-up %d"
|
||||||
(if mu4e-index-lazy-check "Lazy indexing" "Indexing")
|
(if mu4e-index-lazy-check "Lazy indexing" "Indexing")
|
||||||
processed updated cleaned-up)
|
processed updated cleaned-up)
|
||||||
;; call the updated hook if anything changed.
|
(run-hooks 'mu4e-index-updated-hook)
|
||||||
(unless (zerop (+ updated cleaned-up))
|
;; backward compatibility...
|
||||||
(run-hooks 'mu4e-index-updated-hook))
|
(unless (zerop (+ updated cleaned-up))
|
||||||
(unless (and (not (string= mu4e--contacts-tstamp "0"))
|
mu4e-message-changed-hook)
|
||||||
|
(unless (and (not (string= mu4e--contacts-tstamp "0"))
|
||||||
(zerop (plist-get info :updated)))
|
(zerop (plist-get info :updated)))
|
||||||
(mu4e--request-contacts-maybe))
|
(mu4e--request-contacts-maybe))
|
||||||
(when (and (buffer-live-p mainbuf) (get-buffer-window mainbuf))
|
(when (and (buffer-live-p mainbuf) (get-buffer-window mainbuf))
|
||||||
|
|
Loading…
Reference in New Issue