From 1919146b940dde0c7a3ae96400dbfd5f5669f6d0 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Thu, 30 Apr 2020 22:43:25 +0300 Subject: [PATCH] mu4e: centralize mode-line context setting code Add mu4e-context-in-modeline to handle all setting of context in the mode-line, to address some corner-cases with the current setup. --- mu4e/mu4e-compose.el | 3 +-- mu4e/mu4e-context.el | 7 +++++++ mu4e/mu4e-headers.el | 5 +++-- mu4e/mu4e-main.el | 10 +++------- mu4e/mu4e-view.el | 5 +---- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/mu4e/mu4e-compose.el b/mu4e/mu4e-compose.el index 47697e4a..2490e3c2 100644 --- a/mu4e/mu4e-compose.el +++ b/mu4e/mu4e-compose.el @@ -443,8 +443,7 @@ buffers; lets remap its faces so it uses the ones for mu4e." \\{message-mode-map}." (progn (use-local-map mu4e-compose-mode-map) - (make-local-variable 'global-mode-string) - (add-to-list 'global-mode-string '(:eval (mu4e-context-label))) + (mu4e-context-in-modeline) (set (make-local-variable 'message-signature) mu4e-compose-signature) ;; set this to allow mu4e to work when gnus-agent is unplugged in gnus (set (make-local-variable 'message-send-mail-real-function) nil) diff --git a/mu4e/mu4e-context.el b/mu4e/mu4e-context.el index 1c33dac3..23606516 100644 --- a/mu4e/mu4e-context.el +++ b/mu4e/mu4e-context.el @@ -284,6 +284,13 @@ match, POLICY determines what to do: (mu4e~context-ask-user "Select context: "))) (otherwise nil)))))) +(defun mu4e-context-in-modeline () + "Display the mu4e-context (if any) in a (buffer-specific) +global-mode-line." + (add-to-list + (make-local-variable 'global-mode-string) + '(:eval (mu4e-context-label)))) + ;;; _ (provide 'mu4e-context) ;;; mu4e-context.el ends here diff --git a/mu4e/mu4e-headers.el b/mu4e/mu4e-headers.el index 4b226a35..f1353351 100644 --- a/mu4e/mu4e-headers.el +++ b/mu4e/mu4e-headers.el @@ -1086,9 +1086,10 @@ no user-interaction ongoing." (use-local-map mu4e-headers-mode-map) (make-local-variable 'mu4e~headers-proc) (make-local-variable 'mu4e~highlighted-docid) - (make-local-variable 'global-mode-string) (set (make-local-variable 'hl-line-face) 'mu4e-header-highlight-face) + (mu4e-context-in-modeline) + ;; 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 @@ -1233,6 +1234,7 @@ the query history stack." (setq mode-name "mu4e-headers" mu4e~headers-last-query rewritten-expr) + (make-local-variable 'global-mode-string) (add-to-list 'global-mode-string '(:eval (concat @@ -1240,7 +1242,6 @@ the query history stack." (mu4e~quote-for-modeline mu4e~headers-last-query) 'face 'mu4e-modeline-face) " " - (mu4e-context-label) (if (and mu4e-display-update-status-in-modeline (buffer-live-p mu4e~update-buffer) (process-live-p (get-buffer-process diff --git a/mu4e/mu4e-main.el b/mu4e/mu4e-main.el index e96b27ae..39275d98 100644 --- a/mu4e/mu4e-main.el +++ b/mu4e/mu4e-main.el @@ -80,10 +80,7 @@ with SPC and therefore is not visible in buffer list.") \\{mu4e-main-mode-map}." (setq truncate-lines t overwrite-mode 'overwrite-mode-binary) - - ;; show context in mode-string - (make-local-variable 'global-mode-string) - (add-to-list 'global-mode-string '(:eval (mu4e-context-label))) + (mu4e-context-in-modeline) (set (make-local-variable 'revert-buffer-function) #'mu4e~main-view-real)) @@ -225,7 +222,7 @@ When REFRESH is non nil refresh infos from server." (mu4e~key-val "personal addresses" (if addrs (mapconcat #'identity addrs ", " ) "none")))) (if mu4e-main-buffer-hide-personal-addresses "" - (when (and addrs user-mail-address (not (member user-mail-address addrs))) + (when (and user-mail-address (not (member user-mail-address addrs))) (mu4e-message (concat "Note: `user-mail-address' ('%s') is not part " "of mu's addresses; add it with 'mu init --my-address='") @@ -276,8 +273,7 @@ When REFRESH is non nil refresh infos from server." (switch-to-buffer buf) (with-current-buffer buf (mu4e~main-view-real-1 refresh)) - (goto-char (point-min))) - (add-to-list 'global-mode-string '(:eval (mu4e-context-label))))) + (goto-char (point-min))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Interactive functions diff --git a/mu4e/mu4e-view.el b/mu4e/mu4e-view.el index 47871a15..185fa35e 100644 --- a/mu4e/mu4e-view.el +++ b/mu4e/mu4e-view.el @@ -989,9 +989,7 @@ FUNC should be a function taking two arguments: (defun mu4e~view-mode-body () "Body of the mode-function." (use-local-map mu4e-view-mode-map) - ;; show context in mode-string - (make-local-variable 'global-mode-string) - (add-to-list 'global-mode-string '(:eval (mu4e-context-label))) + (mu4e-context-in-modeline) (setq buffer-undo-list t);; don't record undo info ;; autopair mode gives error when pressing RET ;; turn it off @@ -1840,7 +1838,6 @@ other windows." (define-derived-mode mu4e-loading-mode special-mode "mu4e:loading" (use-local-map mu4e-loading-mode-map) - (make-local-variable 'global-mode-string) (let ((inhibit-read-only t)) (erase-buffer) (insert (propertize "Loading message..."