mu4e: tweak main-view updating

This commit is contained in:
Dirk-Jan C. Binnema 2023-01-17 20:45:32 +02:00
parent d7eed9e9ff
commit 74fb72035a
3 changed files with 83 additions and 95 deletions

View File

@ -1541,6 +1541,8 @@ region if there is a region, then move to the next message."
(interactive)
(mu4e-mark-handle-when-leaving)
(quit-window t)
;; clear the decks before going to the main-view
(mu4e--query-items-refresh 'reset-baseline)
(mu4e--main-view))

View File

@ -121,10 +121,7 @@ the personal addresses."
(define-key map "S" #'mu4e-kill-update-mail)
(define-key map (kbd "C-S-u") #'mu4e-update-mail-and-index)
(define-key map ";"
(lambda()(interactive)
(mu4e-context-switch)(revert-buffer)))
(define-key map ";" #'mu4e-context-switch)
(define-key map "$" #'mu4e-show-log)
(define-key map "A" #'mu4e-about)
(define-key map "N" #'mu4e-news)
@ -162,11 +159,7 @@ the personal addresses."
(setq-local revert-buffer-function
(lambda (_ignore-auto _noconfirm)
;; reset the baseline and get updated results.
(mu4e--query-items-refresh 'reset-baseline)))
(add-hook 'mu4e-query-items-updated-hook
(lambda ()
(when (get-buffer mu4e-main-buffer-name)
(mu4e--main-redraw-buffer))) nil t))
(mu4e--query-items-refresh 'reset-baseline))))
(defun mu4e--main-action-str (str &optional func-or-shortcut)
"Highlight the first occurrence of [.] in STR.
@ -246,8 +239,10 @@ character of the keyboard shortcut
(current-time-string baseline-t)
"Never"))))
(defun mu4e--main-redraw-buffer ()
"Redraw the main buffer."
(defun mu4e--main-redraw ()
"Redraw the main buffer if there is one.
Otherwise, do nothing."
(when (buffer-live-p (get-buffer mu4e-main-buffer-name))
(with-current-buffer mu4e-main-buffer-name
(let* ((inhibit-read-only t)
(pos (point))
@ -278,10 +273,7 @@ character of the keyboard shortcut
"\n"
(propertize " Misc\n\n" 'face 'mu4e-title-face)
(mu4e--main-action-str "\t* [;]Switch context\n"
(lambda()(interactive)
(mu4e-context-switch)(revert-buffer)))
(mu4e--main-action-str "\t* [;]Switch context\n" #'mu4e-context-switch)
(mu4e--main-action-str "\t* [U]pdate email & database\n"
#'mu4e-update-mail-and-index)
;; show the queue functions if `smtpmail-queue-dir' is defined
@ -314,7 +306,8 @@ character of the keyboard shortcut
"of mu's addresses; add it with 'mu init
--my-address='") user-mail-address)))
(mu4e-main-mode)
(goto-char pos))))
(goto-char pos)))))
(defun mu4e--main-view-queue ()
"Display queue-related actions in the main view."
@ -346,24 +339,17 @@ character of the keyboard shortcut
(declare-function mu4e--start "mu4e")
(defun mu4e--main-view (&optional refresh)
(defun mu4e--main-view ()
"(Re)create the mu4e main-view, and switch to it.
With non-nil REFRESH, refresh queries and baseline first.
If `mu4e-split-view' equals \='single-window, show a mu4e menu
instead."
(if (eq mu4e-split-view 'single-window)
(mu4e--main-menu)
(let ((buf (get-buffer-create mu4e-main-buffer-name))
(inhibit-read-only t))
;; `mu4e--main-view' is called from `mu4e--start', so don't call it a
;; second time here i.e. do not refresh unless specified explicitly with
;; REFRESH arg.
(when refresh
(mu4e--query-items-refresh 'reset-baseline))
(with-current-buffer buf
(mu4e--main-redraw-buffer))
(mu4e--main-redraw))
(mu4e-display-buffer buf t)))
(goto-char (point-min)))
@ -381,7 +367,7 @@ instead."
(if smtpmail-queue-mail "queued" "sent directly")))
(unless (or (eq mu4e-split-view 'single-window)
(not (buffer-live-p (get-buffer mu4e-main-buffer-name))))
(mu4e--main-redraw-buffer)))
(mu4e--main-redraw)))
(defun mu4e--main-menu ()
"The mu4e main menu in the mini-buffer."

View File

@ -152,16 +152,17 @@ Otherwise, check requirements, then start mu4e. When successful, invoke
(mu4e--context-autoswitch nil mu4e-context-policy))
(setq mu4e-pong-func
(lambda (info) (mu4e--pong-handler info func)))
;; show some notification?
(when mu4e-notification-support
(add-hook 'mu4e-query-items-updated-hook #'mu4e--notification))
;; modeline support
(when mu4e-modeline-support
(mu4e--modeline-register #'mu4e--bookmarks-modeline-item 'global)
(mu4e-modeline-mode)
(add-hook 'mu4e-query-items-updated-hook
#'mu4e--modeline-update))
(add-hook 'mu4e-query-items-updated-hook #'mu4e--modeline-update))
(mu4e-modeline-mode (if mu4e-modeline-support 1 -1))
(when mu4e-notification-support
(add-hook 'mu4e-query-items-updated-hook
#'mu4e--notification))
;; redraw main buffer if there is one.
(add-hook 'mu4e-query-items-updated-hook #'mu4e--main-redraw)
(mu4e--server-ping)
;; maybe request the list of contacts, automatically refreshed after
;; reindexing
@ -173,10 +174,9 @@ Otherwise, check requirements, then start mu4e. When successful, invoke
(cancel-timer mu4e--update-timer)
(setq mu4e--update-timer nil))
(mu4e-clear-caches)
(remove-hook 'mu4e-query-items-updated-hook
#'mu4e--modeline-update)
(remove-hook 'mu4e-query-items-updated-hook
#'mu4e--notification)
(remove-hook 'mu4e-query-items-updated-hook #'mu4e--main-redraw)
(remove-hook 'mu4e-query-items-updated-hook #'mu4e--modeline-update)
(remove-hook 'mu4e-query-items-updated-hook #'mu4e--notification)
(mu4e-kill-update-mail)
(mu4e-modeline-mode -1)
(mu4e--server-kill)