mu4e: add new segment that shows unread emails

This commit is contained in:
Sean Farley 2019-01-28 23:57:41 -08:00
parent 54a5f45182
commit ad73d3d874
3 changed files with 32 additions and 4 deletions

View file

@ -119,6 +119,9 @@ The icons may not be showed correctly in terminal and on Windows.")
(defvar doom-modeline-version t (defvar doom-modeline-version t
"Whether display environment version or not.") "Whether display environment version or not.")
(defvar doom-modeline-mu4e t
"Whether display mu4e notifications or not. Requires `mu4e-alert' package.")
;; ;;
;; Custom faces ;; Custom faces

View file

@ -70,6 +70,7 @@
(defvar text-scale-mode-amount) (defvar text-scale-mode-amount)
(defvar winum-auto-setup-mode-line) (defvar winum-auto-setup-mode-line)
(defvar xah-fly-insert-state-q) (defvar xah-fly-insert-state-q)
(defvar mu4e-alert-mode-line)
(declare-function anzu--reset-status 'anzu) (declare-function anzu--reset-status 'anzu)
(declare-function anzu--where-is-here 'anzu) (declare-function anzu--where-is-here 'anzu)
@ -1497,6 +1498,25 @@ mouse-1: Toggle Debug on Quit"
(eval `(pdf-view-current-page)) (eval `(pdf-view-current-page))
(pdf-cache-number-of-pages)))) (pdf-cache-number-of-pages))))
;;
;; mu4e-alert notifications
;;
(doom-modeline-def-segment mu4e
(when (and doom-modeline-mu4e
(doom-modeline--active)
;; we'll do our own formatting so just need to test for zero
(> mu4e-alert-mode-line 0))
;; remove mu4e-alert's global modeline string setting
(setq global-mode-string (delete '(:eval mu4e-alert-mode-line)
global-mode-string))
(propertize
(number-to-string mu4e-alert-mode-line)
'help-echo (if (= mu4e-alert-mode-line 1)
"You have an unread email"
(format "You have %s unread emails" mu4e-alert-mode-line)))))
(provide 'doom-modeline-segments) (provide 'doom-modeline-segments)
;;; doom-modeline-segments.el ends here ;;; doom-modeline-segments.el ends here

View file

@ -83,7 +83,7 @@
(doom-modeline-def-modeline 'main (doom-modeline-def-modeline 'main
'(bar workspace-number window-number evil-state god-state ryo-modal xah-fly-keys matches buffer-info remote-host buffer-position parrot selection-info) '(bar workspace-number window-number evil-state god-state ryo-modal xah-fly-keys matches buffer-info remote-host buffer-position parrot selection-info)
'(misc-info persp-name lsp github debug minor-modes input-method buffer-encoding major-mode process vcs checker)) '(misc-info persp-name lsp mu4e github debug minor-modes input-method buffer-encoding major-mode process vcs checker))
(doom-modeline-def-modeline 'minimal (doom-modeline-def-modeline 'minimal
'(bar matches " " buffer-info) '(bar matches " " buffer-info)
@ -95,7 +95,7 @@
(doom-modeline-def-modeline 'project (doom-modeline-def-modeline 'project
'(bar " " buffer-default-directory) '(bar " " buffer-default-directory)
'(misc-info github debug " " major-mode " ")) '(misc-info mu4e github debug " " major-mode " "))
(doom-modeline-def-modeline 'media (doom-modeline-def-modeline 'media
'(bar window-number buffer-size buffer-info) '(bar window-number buffer-size buffer-info)
@ -153,6 +153,8 @@ If DEFAULT is non-nil, set the default mode-line for all buffers."
;; ;;
(defvar doom-modeline--default-mode-line mode-line-format) (defvar doom-modeline--default-mode-line mode-line-format)
(defvar mu4e-alert-modeline-formatter)
(declare-function mu4e-alert-default-mode-line-formatter 'mu4e-alert)
;;;###autoload ;;;###autoload
(define-minor-mode doom-modeline-mode (define-minor-mode doom-modeline-mode
@ -174,7 +176,8 @@ If DEFAULT is non-nil, set the default mode-line for all buffers."
(add-hook 'dashboard-mode-hook #'doom-modeline-set-project-modeline) (add-hook 'dashboard-mode-hook #'doom-modeline-set-project-modeline)
(add-hook 'image-mode-hook #'doom-modeline-set-media-modeline) (add-hook 'image-mode-hook #'doom-modeline-set-media-modeline)
(add-hook 'circe-mode-hook #'doom-modeline-set-special-modeline) (add-hook 'circe-mode-hook #'doom-modeline-set-special-modeline)
(add-hook 'pdf-tools-enabled-hook #'doom-modeline-set-pdf-modeline)) (add-hook 'pdf-tools-enabled-hook #'doom-modeline-set-pdf-modeline)
(setq mu4e-alert-modeline-formatter #'identity))
(progn (progn
;; Restore mode-line ;; Restore mode-line
(setq-default mode-line-format doom-modeline--default-mode-line) (setq-default mode-line-format doom-modeline--default-mode-line)
@ -182,7 +185,9 @@ If DEFAULT is non-nil, set the default mode-line for all buffers."
(remove-hook 'dashboard-mode-hook #'doom-modeline-set-project-modeline) (remove-hook 'dashboard-mode-hook #'doom-modeline-set-project-modeline)
(remove-hook 'image-mode-hook #'doom-modeline-set-media-modeline) (remove-hook 'image-mode-hook #'doom-modeline-set-media-modeline)
(remove-hook 'circe-mode-hook #'doom-modeline-set-special-modeline) (remove-hook 'circe-mode-hook #'doom-modeline-set-special-modeline)
(remove-hook 'pdf-tools-enabled-hook #'doom-modeline-set-pdf-modeline)))) (remove-hook 'pdf-tools-enabled-hook #'doom-modeline-set-pdf-modeline)
(setq mu4e-alert-modeline-formatter
#'mu4e-alert-default-mode-line-formatter))))
(provide 'doom-modeline) (provide 'doom-modeline)