mu4e: clean up update handling

When we have a mu4e-headers window open and there's an update, try to
refresh it. If there's no open window, don't.
This commit is contained in:
djcb 2017-01-16 23:45:14 +02:00
parent 52ef84ccab
commit e0c21252c9
1 changed files with 24 additions and 19 deletions

View File

@ -583,7 +583,7 @@ found."
(add-face-text-property 0 (length line) face t line)) (add-face-text-property 0 (length line) face t line))
line)) line))
(defun mu4e~headers-line-handler (msg line) (defsubst mu4e~headers-line-handler (msg line)
(dolist (func mu4e~headers-line-handler-functions) (dolist (func mu4e~headers-line-handler-functions)
(setq line (funcall func msg line))) (setq line (funcall func msg line)))
line) line)
@ -592,14 +592,16 @@ found."
(defun mu4e~headers-header-handler (msg &optional point) (defun mu4e~headers-header-handler (msg &optional point)
"Create a one line description of MSG in this buffer, at POINT, "Create a one line description of MSG in this buffer, at POINT,
if provided, or at the end of the buffer otherwise." if provided, or at the end of the buffer otherwise."
(unless (and mu4e-headers-hide-predicate (when (buffer-live-p mu4e~headers-buffer)
(funcall mu4e-headers-hide-predicate msg)) (with-current-buffer mu4e~headers-buffer
(let ((docid (mu4e-message-field msg :docid)) (unless (and mu4e-headers-hide-predicate
(line (mapconcat (lambda (f-w) (funcall mu4e-headers-hide-predicate msg))
(mu4e~headers-field-handler f-w msg)) (let ((docid (mu4e-message-field msg :docid))
mu4e-headers-fields " "))) (line (mapconcat
(setq line (mu4e~headers-line-handler msg line)) (lambda (f-w) (mu4e~headers-field-handler f-w msg))
(mu4e~headers-add-header line docid point msg)))) mu4e-headers-fields " ")))
(setq line (mu4e~headers-line-handler msg line))
(mu4e~headers-add-header line docid point msg))))))
(defconst mu4e~no-matches "No matching messages found") (defconst mu4e~no-matches "No matching messages found")
(defconst mu4e~end-of-results "End of search results") (defconst mu4e~end-of-results "End of search results")
@ -890,15 +892,17 @@ after the end of the search results."
(defvar mu4e-headers-mode-abbrev-table nil) (defvar mu4e-headers-mode-abbrev-table nil)
(defun mu4e~headers-do-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 is
no user-interaction ongoing." no user-interaction ongoing."
(message "DO UPDA")
(when (and mu4e-headers-auto-update ;; must be set (when (and mu4e-headers-auto-update ;; must be set
(zerop (mu4e-mark-marks-num)) ;; non active marks (zerop (mu4e-mark-marks-num)) ;; non active marks
(not (active-minibuffer-window))) ;; no user input (not (active-minibuffer-window))) ;; no user input only
(with-current-buffer mu4e~headers-buffer ;; rerun search if there's a live window with search results;
;; otherwise we'd trigger a headers view from out of nowhere.
(when (and (buffer-live-p mu4e~hâeaders-buffer)
(window-live-p (get-buffer-window mu4e~headers-buffer)))
(mu4e-headers-rerun-search)))) (mu4e-headers-rerun-search))))
(define-derived-mode mu4e-headers-mode special-mode (define-derived-mode mu4e-headers-mode special-mode
@ -912,10 +916,9 @@ 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 (add-hook 'mu4e-index-updated-hook
'mu4e~headers-do-auto-update nil t) (lambda() (run-hooks 'mu4e-message-changed-hook)) t)
(add-hook 'mu4e-index-updated-hook
(lambda () (run-hooks 'mu4e-message-changed-hook)) 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
@ -1097,9 +1100,11 @@ the query history stack."
(mu4e~quote-for-modeline mu4e~headers-last-query) (mu4e~quote-for-modeline mu4e~headers-last-query)
'face 'mu4e-modeline-face) 'face 'mu4e-modeline-face)
" " " "
(mu4e-context-label))))) (mu4e-context-label)))))
;; when the buffer is already visible, select it; otherwise,
(switch-to-buffer buf) ;; switch to it.
(unless (get-buffer-window buf 'visible)
(switch-to-buffer buf))
(run-hook-with-args 'mu4e-headers-search-hook expr) (run-hook-with-args 'mu4e-headers-search-hook expr)
(mu4e~proc-find (mu4e~proc-find
expr expr