diff options
Diffstat (limited to 'mu4e/mu4e-context.el')
| -rw-r--r-- | mu4e/mu4e-context.el | 56 |
1 files changed, 37 insertions, 19 deletions
diff --git a/mu4e/mu4e-context.el b/mu4e/mu4e-context.el index 4282834..300c53e 100644 --- a/mu4e/mu4e-context.el +++ b/mu4e/mu4e-context.el @@ -27,11 +27,10 @@ ;;; Code: -(require 'cl-lib) -(require 'mu4e-utils) +(require 'mu4e-helpers) -(defvar smtpmail-smtp-user) -(defvar mu4e-view-date-format) + +;;; Configuration (defvar mu4e-contexts nil "The list of `mu4e-context' objects describing mu4e's contexts.") @@ -39,16 +38,23 @@ (defvar mu4e-context-changed-hook nil "Hook run just *after* the context changed.") -(defvar mu4e~context-current nil - "The current context; for internal use. -Use `mu4e-context-switch' to change it.") +(defface mu4e-context-face + '((t :inherit mu4e-title-face :weight bold)) + "Face for displaying the context in the modeline." + :group 'mu4e-faces) + +(defvar mu4e--context-current nil + "The current context. +Internal; use `mu4e-context-switch' to change it.") + + (defun mu4e-context-current (&optional output) "Get the currently active context, or nil if there is none. When OUTPUT is non-nil, echo the name of the current context or none." (interactive "p") - (let ((ctx mu4e~context-current)) + (let ((ctx mu4e--context-current)) (when output (mu4e-message "Current context: %s" (if ctx (mu4e-context-name ctx) "<none>"))) @@ -58,7 +64,7 @@ none." "Propertized string with the current context name. An empty string \"\" if there is none." (if (mu4e-context-current) - (concat "[" (propertize (mu4e~quote-for-modeline + (concat "[" (propertize (mu4e-quote-for-modeline (mu4e-context-name (mu4e-context-current))) 'face 'mu4e-context-face) "]") "")) @@ -83,7 +89,7 @@ An empty string \"\" if there is none." vars) ;; alist of variables. -(defun mu4e~context-ask-user (prompt) +(defun mu4e--context-ask-user (prompt) "Let user choose some context based on its name with PROMPT." (when mu4e-contexts (let* ((names (cl-map 'list (lambda (context) @@ -108,13 +114,13 @@ non-nil." (context (if name (cdr-safe (assoc name names)) - (mu4e~context-ask-user "Switch to context: ")))) + (mu4e--context-ask-user "Switch to context: ")))) (unless context (mu4e-error "No such context")) ;; if new context is same as old one one switch with FORCE is set. (when (or force (not (eq context (mu4e-context-current)))) (when (and (mu4e-context-current) - (mu4e-context-leave-func mu4e~context-current)) - (funcall (mu4e-context-leave-func mu4e~context-current))) + (mu4e-context-leave-func mu4e--context-current)) + (funcall (mu4e-context-leave-func mu4e--context-current))) ;; enter the new context (when (mu4e-context-enter-func context) (funcall (mu4e-context-enter-func context))) @@ -122,14 +128,14 @@ non-nil." (mapc (lambda (cell) (set (car cell) (cdr cell))) (mu4e-context-vars context))) - (setq mu4e~context-current context) + (setq mu4e--context-current context) (run-hooks 'mu4e-context-changed-hook) (mu4e-message "Switched context to %s" (mu4e-context-name context)) (force-mode-line-update)) context)) -(defun mu4e~context-autoswitch (&optional msg policy) +(defun mu4e--context-autoswitch (&optional msg policy) "Automatically switch to some context. When contexts are defined but there is no context yet, switch to @@ -161,7 +167,7 @@ match, POLICY determines what to do: - otherwise, return nil. Effectively, this leaves the current context as it is." (when mu4e-contexts (if (eq policy 'always-ask) - (mu4e~context-ask-user "Select context: ") + (mu4e--context-ask-user "Select context: ") (or ;; is there a matching one? (cl-find-if (lambda (context) (when (mu4e-context-match-func context) @@ -170,9 +176,9 @@ match, POLICY determines what to do: ;; no context found yet; consult policy (cl-case policy (pick-first (car mu4e-contexts)) - (ask (mu4e~context-ask-user "Select context: ")) + (ask (mu4e--context-ask-user "Select context: ")) (ask-if-none (or (mu4e-context-current) - (mu4e~context-ask-user "Select context: "))) + (mu4e--context-ask-user "Select context: "))) (otherwise nil)))))) (defun mu4e-context-in-modeline () @@ -182,6 +188,18 @@ global-mode-line." (make-local-variable 'global-mode-string) '(:eval (mu4e-context-label)))) -;;; _ +(define-minor-mode mu4e-context-minor-mode + "Mode for switching the mu4e context." + :global nil + :init-value nil ;; disabled by default + :group 'mu4e + :lighter "" + :keymap + (let ((map (make-sparse-keymap))) + (define-key map (kbd";") #'mu4e-context-switch) + map) + (mu4e-context-in-modeline)) + +;;; (provide 'mu4e-context) ;;; mu4e-context.el ends here |
