From b1369b6ad9f9c1a7e8d363dc8c72b503ffd11753 Mon Sep 17 00:00:00 2001 From: Thierry Volpiatto Date: Fri, 21 Feb 2020 08:33:07 +0100 Subject: [PATCH 1/3] Fix mu4e-main revert-buffer-function and use it * mu4e/mu4e-headers.el (mu4e~headers-quit-buffer): Refresh main buffer when done. * mu4e/mu4e-main.el (mu4e-main-mode-map): Don't bind "g" to mu4e, "g" should be bound to revert-buffer (special-mode). (mu4e-main-mode): No need to specify map. (mu4e~main-view-real-1): New. (mu4e~main-redraw-buffer): New. (mu4e~main-view-real): Use them. (mu4e~main-view): Take one more arg REFRESH. (mu4e~main-toggle-mail-sending-mode): revert-buffer when done. --- mu4e/mu4e-headers.el | 2 +- mu4e/mu4e-main.el | 71 ++++++++++++++++++++++++++++---------------- 2 files changed, 47 insertions(+), 26 deletions(-) diff --git a/mu4e/mu4e-headers.el b/mu4e/mu4e-headers.el index 69bdd2ca..aa24e9ed 100644 --- a/mu4e/mu4e-headers.el +++ b/mu4e/mu4e-headers.el @@ -1898,7 +1898,7 @@ other windows." ;; now, all *other* windows should be gone. kill ourselves, and return ;; to the main view (kill-buffer) - (mu4e~main-view)))) + (mu4e~main-view 'refresh)))) ;;; _ (provide 'mu4e-headers) diff --git a/mu4e/mu4e-main.el b/mu4e/mu4e-main.el index 56e7b6a8..a25489a4 100644 --- a/mu4e/mu4e-main.el +++ b/mu4e/mu4e-main.el @@ -63,19 +63,16 @@ (define-key map "A" 'mu4e-about) (define-key map "N" 'mu4e-news) (define-key map "H" 'mu4e-display-manual) - (define-key map "g" 'mu4e) map) "Keymap for the *mu4e-main* buffer.") -(fset 'mu4e-main-mode-map mu4e-main-mode-map) (defvar mu4e-main-mode-abbrev-table nil) (define-derived-mode mu4e-main-mode special-mode "mu4e:main" "Major mode for the mu4e main screen. \\{mu4e-main-mode-map}." - (use-local-map mu4e-main-mode-map) - (setq truncate-lines t) - (setq overwrite-mode 'overwrite-mode-binary) + (setq truncate-lines t + overwrite-mode 'overwrite-mode-binary) ;; show context in mode-string (make-local-variable 'global-mode-string) @@ -158,9 +155,23 @@ clicked." ;; NEW This is the old `mu4e~main-view' function but without ;; buffer switching at the end. (defun mu4e~main-view-real (_ignore-auto _noconfirm) - (let ((buf (get-buffer-create mu4e~main-buffer-name)) - (inhibit-read-only t)) - (with-current-buffer buf + "The revert buffer function for `mu4e-main-mode'." + (mu4e~main-view-real-1 'refresh)) + +(defun mu4e~main-view-real-1 (&optional refresh) + "Create `mu4e~main-buffer-name' and set it up. +When REFRESH is non nil refresh infos from server." + (let ((inhibit-read-only t) + (pos (point))) + ;; Maybe refresh infos from server. + (if refresh + (mu4e~start 'mu4e~main-redraw-buffer) + (mu4e~main-redraw-buffer)))) + +(defun mu4e~main-redraw-buffer () + (with-current-buffer mu4e~main-buffer-name + (let ((inhibit-read-only t) + (pos (point))) (erase-buffer) (insert "* " @@ -202,7 +213,8 @@ clicked." (mu4e~key-val "maildir" (mu4e-root-maildir)) (mu4e~key-val "in store" (format "%d" (plist-get mu4e~server-props :doccount)) "messages")) - (mu4e-main-mode)))) + (mu4e-main-mode) + (goto-char pos)))) (defun mu4e~main-view-queue () "Display queue-related actions in the main view." @@ -232,20 +244,29 @@ clicked." (count-lines (point-min) (point-max))) (error 0))) -(defun mu4e~main-view () - "Create the mu4e main-view, and switch to it." - (if (eq mu4e-split-view 'single-window) - (if (buffer-live-p (mu4e-get-headers-buffer)) - (switch-to-buffer (mu4e-get-headers-buffer)) - (mu4e~main-menu)) - (mu4e~main-view-real nil nil) - (switch-to-buffer mu4e~main-buffer-name) - (goto-char (point-min))) - (add-to-list 'global-mode-string '(:eval (mu4e-context-label)))) +(defun mu4e~main-view (&optional refresh) + "Create the mu4e main-view, and switch to it. -;;; Commands +When REFRESH is non nil refresh infos from server." + (let ((buf (get-buffer-create mu4e~main-buffer-name))) + (if (eq mu4e-split-view 'single-window) + (if (buffer-live-p (mu4e-get-headers-buffer)) + (switch-to-buffer (mu4e-get-headers-buffer)) + (mu4e~main-menu)) + ;; `mu4e~main-view' is called from `mu4e~start', so don't call it + ;; a second time here i.e. do not refresh unless specified + ;; explicitely with REFRESH arg. + (switch-to-buffer buf) + (with-current-buffer buf + (mu4e-main-mode) + (mu4e~main-view-real-1 refresh)) + (goto-char (point-min))) + (add-to-list 'global-mode-string '(:eval (mu4e-context-label))))) -;; NEW Toggle mail sending mode without switching +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Interactive functions +;; NEW +;; Toggle mail sending mode without switching (defun mu4e~main-toggle-mail-sending-mode () "Toggle sending mail mode, either queued or direct." (interactive) @@ -254,10 +275,10 @@ clicked." (setq smtpmail-queue-mail (not smtpmail-queue-mail)) (message (concat "Outgoing mail will now be " (if smtpmail-queue-mail "queued" "sent directly"))) - (unless (eq mu4e-split-view 'single-window) - (let ((curpos (point))) - (mu4e~main-view-real nil nil) - (goto-char curpos)))) + (unless (or (eq mu4e-split-view 'single-window) + (not (buffer-live-p (get-buffer mu4e~main-buffer-name)))) + (with-current-buffer mu4e~main-buffer-name + (revert-buffer)))) (defun mu4e~main-menu () "mu4e main view in the minibuffer." From b301b7663b8bd9128618db7d7c436f550f47d48d Mon Sep 17 00:00:00 2001 From: Thierry Volpiatto Date: Fri, 21 Feb 2020 08:54:16 +0100 Subject: [PATCH 2/3] Don't use mu4e-index-updated-hook in mu4e~start Using mu4e-index-updated-hook in mu4e~start with a lambda is just like adding the call to mu4e-info-handler so do it explicitely which is much cleaner. * mu4e/mu4e-utils.el (mu4e-info-handler): Always refresh main buffer. (mu4e~start): Remove insertion of mu4e-index-updated-hook. --- mu4e/mu4e-utils.el | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/mu4e/mu4e-utils.el b/mu4e/mu4e-utils.el index 09776398..3c056f6d 100644 --- a/mu4e/mu4e-utils.el +++ b/mu4e/mu4e-utils.el @@ -642,7 +642,8 @@ process." (let* ((type (plist-get info :info)) (processed (plist-get info :processed)) (updated (plist-get info :updated)) - (cleaned-up (plist-get info :cleaned-up))) + (cleaned-up (plist-get info :cleaned-up)) + (mainbuf (get-buffer mu4e~main-buffer-name))) (cond ((eq type 'add) t) ;; do nothing ((eq type 'index) @@ -658,7 +659,9 @@ process." (run-hooks 'mu4e-index-updated-hook)) (unless (and (not (string= mu4e~contacts-tstamp "0")) (zerop (plist-get info :updated))) - (mu4e~request-contacts-maybe))))) + (mu4e~request-contacts-maybe)) + (when (and (buffer-live-p mainbuf) (get-buffer-window mainbuf)) + (mu4e~main-view 'refresh))))) ((plist-get info :message) (mu4e-index-message "%s" (plist-get info :message)))))) @@ -800,19 +803,10 @@ context yet, switch to the matching one, or none matches, the first. If mu4e is already running, execute function FUNC (if non-nil). Otherwise, check various requireme`'nts, then start mu4e. When successful, call FUNC (if non-nil) afterwards." - ;; if we're already running, simply go to the main view - (unless (mu4e-running-p) ;; already running? - ;; when it's visible, re-draw the main view when there are changes. - (add-hook 'mu4e-index-updated-hook - (lambda() - (let ((mainbuf (get-buffer mu4e~main-buffer-name))) - (when (and (buffer-live-p mainbuf) (get-buffer-window mainbuf)) - (mu4e~start 'mu4e~main-view)))))) - (setq mu4e-pong-func (lambda (info) (mu4e~pong-handler info func))) (mu4e~proc-ping - (mapcar ;; send it a list of queries we'd like to see read/unread info - ;; for. + (mapcar + ;; send it a list of queries we'd like to see read/unread info for. (lambda(bm) (plist-get bm :query)) (seq-filter (lambda (bm) ;; exclude bookmarks that are not strings, ;; and with these flags. From ec684cc99cbb91af723256a2a5a5dae3d93603d7 Mon Sep 17 00:00:00 2001 From: Thierry Volpiatto Date: Fri, 21 Feb 2020 09:08:48 +0100 Subject: [PATCH 3/3] Update mode-line when changing context * mu4e/mu4e-context.el (mu4e-context-switch): Do it. --- mu4e/mu4e-context.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mu4e/mu4e-context.el b/mu4e/mu4e-context.el index 8eb1bb82..0efab4c2 100644 --- a/mu4e/mu4e-context.el +++ b/mu4e/mu4e-context.el @@ -235,7 +235,8 @@ non-nil." (setq mu4e~context-current context) (run-hooks 'mu4e-context-changed-hook) - (mu4e-message "Switched context to %s" (mu4e-context-name context))) + (mu4e-message "Switched context to %s" (mu4e-context-name context)) + (force-mode-line-update)) context)) (defun mu4e~context-autoswitch (&optional msg policy)