mirror of
https://github.com/vale981/doom-modeline
synced 2025-03-04 17:01:39 -05:00
Add basic gnus support without any other dependency than gnus
This commit is contained in:
parent
a6f6f25877
commit
3b2df9ab56
4 changed files with 115 additions and 4 deletions
|
@ -47,7 +47,7 @@ The `doom-modeline` was designed for minimalism, and offers:
|
|||
- An indicator for remote host
|
||||
- An indicator for LSP state with `lsp-mode` or `eglot`
|
||||
- An indicator for GitHub notifications
|
||||
- An indicator for unread emails with `mu4e-alert`
|
||||
- An indicator for unread emails with `mu4e-alert` and `gnus`
|
||||
- An indicator for IRC notifications with `circe`, `rcirc` or `erc`
|
||||
- An indicator for buffer position which is compatible with `nyan-mode`
|
||||
- An indicator for party `parrot`
|
||||
|
@ -267,6 +267,12 @@ Run `M-x customize-group RET doom-modeline RET` or set the variables.
|
|||
;; Whether display the mu4e notifications. It requires `mu4e-alert' package.
|
||||
(setq doom-modeline-mu4e t)
|
||||
|
||||
;; Whether display the gnus notifications.
|
||||
(setq doom-modeline-gnus t)
|
||||
|
||||
;; Wheter gnus should automatically be updated and how often (set to nil to disable)
|
||||
(setq doom-modeline-gnus-timer 2)
|
||||
|
||||
;; Whether display the IRC notifications. It requires `circe' or `erc' package.
|
||||
(setq doom-modeline-irc t)
|
||||
|
||||
|
|
|
@ -330,6 +330,20 @@ It requires `mu4e-alert' package."
|
|||
:type 'boolean
|
||||
:group 'doom-modeline)
|
||||
|
||||
(defcustom doom-modeline-gnus nil
|
||||
"Wheter to display notifications from gnus
|
||||
|
||||
It requires `gnus' to be setup"
|
||||
:type 'boolean
|
||||
:group 'doom-modeline)
|
||||
|
||||
(defcustom doom-modeline-gnus-timer 2
|
||||
"The wait time in minutes before gnus fetches mail
|
||||
|
||||
if nil, don't set up a hook"
|
||||
:type 'integer
|
||||
:group 'doom-modeline)
|
||||
|
||||
(defcustom doom-modeline-irc t
|
||||
"Whether display the irc notifications.
|
||||
|
||||
|
|
|
@ -2094,6 +2094,96 @@ mouse-1: Toggle Debug on Quit"
|
|||
:after #'doom-modeline-override-mu4e-alert-modeline)
|
||||
(add-hook 'doom-modeline-mode-hook #'doom-modeline-override-mu4e-alert-modeline)
|
||||
|
||||
;;
|
||||
;; `gnus notifications' notifications
|
||||
;;
|
||||
|
||||
(defvar doom-modeline-gnus-unread-mail 0)
|
||||
(defvar doom-modeline-gnus-started nil
|
||||
"Used to determine if gnus has started")
|
||||
(defun doom-modeline-update-gnus-status (&rest _)
|
||||
"Get the total number of unread news of gnus group."
|
||||
(setq doom-modeline-gnus-unread-mail
|
||||
(when (and (doom-modeline--active)
|
||||
(bound-and-true-p doom-modeline-gnus)
|
||||
(bound-and-true-p doom-modeline-gnus-started))
|
||||
(let ((total-unread-news-number 0))
|
||||
;; (setq total-unread-news-number 0)
|
||||
(mapc (lambda (g)
|
||||
(let* ((group (car g))
|
||||
(unread (gnus-group-unread group)))
|
||||
(when (and (numberp unread)
|
||||
(> unread 0))
|
||||
(setq total-unread-news-number (+ total-unread-news-number unread)))))
|
||||
gnus-newsrc-alist)
|
||||
total-unread-news-number))))
|
||||
|
||||
(doom-modeline-def-segment gnus
|
||||
"Show notifications of any unread emails in `gnus'."
|
||||
(when (and (bound-and-true-p doom-modeline-gnus)
|
||||
(bound-and-true-p doom-modeline-gnus-started))
|
||||
(let ((color (if (= doom-modeline-gnus-unread-mail 0) 'doom-modeline-inactive 'doom-modeline-warning)))
|
||||
(concat
|
||||
(doom-modeline-spc)
|
||||
(propertize
|
||||
(concat
|
||||
(doom-modeline-icon 'material "email" "📧" "#" color
|
||||
:height 1.1 :v-adjust -0.225)
|
||||
(doom-modeline-vspc)
|
||||
(propertize
|
||||
(if (> doom-modeline-gnus-unread-mail doom-modeline-number-limit)
|
||||
(format "%d+" doom-modeline-number-limit)
|
||||
(number-to-string doom-modeline-gnus-unread-mail))
|
||||
'face '(:inherit (doom-modeline-warning doom-modeline-unread-number))))
|
||||
'mouse-face 'mode-line-highlight
|
||||
'help-echo (if (= doom-modeline-gnus-unread-mail 1)
|
||||
"You have an unread email"
|
||||
(format "You have %s unread emails" doom-modeline-gnus-unread-mail)))
|
||||
(doom-modeline-spc)))))
|
||||
|
||||
|
||||
;; Only start to listen to gnus when gnus is actually running
|
||||
(defun doom-modeline-start-gnus-listener ()
|
||||
(when (and (doom-modeline--active)
|
||||
(bound-and-true-p doom-modeline-gnus)
|
||||
(not (bound-and-true-p doom-modeline-gnus-started)))
|
||||
(setq doom-modeline-gnus-started t)
|
||||
;; scan gnus in the background if the timer is higher than 0
|
||||
(doom-modeline-update-gnus-status)
|
||||
(if (> doom-modeline-gnus-timer 0)
|
||||
(gnus-demon-add-handler 'gnus-demon-scan-news doom-modeline-gnus-timer nil))))
|
||||
(add-hook #'gnus-started-hook #'doom-modeline-start-gnus-listener)
|
||||
|
||||
;; Stop the listener if gnus isn't running
|
||||
(defun doom-modeline-stop-gnus-listener ()
|
||||
(setq doom-modeline-gnus-started nil))
|
||||
(add-hook #'gnus-exit-gnus-hook #'doom-modeline-stop-gnus-listener)
|
||||
|
||||
|
||||
;; Update the modeline after changes have been made
|
||||
(add-hook 'gnus-group-update-hook #'doom-modeline-update-gnus-status)
|
||||
(add-hook 'gnus-summary-update-hook #'doom-modeline-update-gnus-status)
|
||||
(add-hook 'gnus-group-update-group-hook #'doom-modeline-update-gnus-status)
|
||||
(add-hook 'gnus-after-getting-new-news-hook #'doom-modeline-update-gnus-status)
|
||||
|
||||
|
||||
(doom-modeline-add-variable-watcher
|
||||
'doom-modeline-icon
|
||||
(lambda (_sym val op _where)
|
||||
(when (eq op 'set)
|
||||
(setq doom-modeline-icon val)
|
||||
(dolist (buf (buffer-list))
|
||||
(with-current-buffer buf
|
||||
doom-modeline-gnus-unread-mail)))))
|
||||
|
||||
(doom-modeline-add-variable-watcher
|
||||
'doom-modeline-unicode-fallback
|
||||
(lambda (_sym val op _where)
|
||||
(when (eq op 'set)
|
||||
(setq doom-modeline-unicode-fallback val)
|
||||
(dolist (buf (buffer-list))
|
||||
(with-current-buffer buf
|
||||
doom-modeline-update-gnus-status)))))
|
||||
|
||||
;;
|
||||
;; IRC notifications
|
||||
|
|
|
@ -54,6 +54,7 @@
|
|||
;; - An indicator for LSP state with lsp-mode or eglot
|
||||
;; - An indicator for github notifications
|
||||
;; - An indicator for unread emails with mu4e-alert
|
||||
;; - An indicator for unread emails with gnus (basically builtin)
|
||||
;; - An indicator for irc notifications with circe, rcirc or erc.
|
||||
;; - An indicator for buffer position which is compatible with nyan-mode
|
||||
;; - An indicator for party parrot
|
||||
|
@ -90,7 +91,7 @@
|
|||
|
||||
(doom-modeline-def-modeline 'main
|
||||
'(bar workspace-name window-number modals matches buffer-info remote-host buffer-position word-count parrot selection-info)
|
||||
'(objed-state misc-info persp-name battery grip irc mu4e github debug lsp minor-modes input-method indent-info buffer-encoding major-mode process vcs checker))
|
||||
'(objed-state misc-info persp-name battery grip irc mu4e gnus github debug lsp minor-modes input-method indent-info buffer-encoding major-mode process vcs checker))
|
||||
|
||||
(doom-modeline-def-modeline 'minimal
|
||||
'(bar matches buffer-info-simple)
|
||||
|
@ -102,11 +103,11 @@
|
|||
|
||||
(doom-modeline-def-modeline 'project
|
||||
'(bar window-number buffer-default-directory)
|
||||
'(misc-info battery irc mu4e github debug major-mode process))
|
||||
'(misc-info battery irc mu4e gnus github debug major-mode process))
|
||||
|
||||
(doom-modeline-def-modeline 'vcs
|
||||
'(bar window-number modals matches buffer-info buffer-position parrot selection-info)
|
||||
'(misc-info battery irc mu4e github debug minor-modes buffer-encoding major-mode process))
|
||||
'(misc-info battery irc mu4e gnus github debug minor-modes buffer-encoding major-mode process))
|
||||
|
||||
(doom-modeline-def-modeline 'package
|
||||
'(bar window-number package)
|
||||
|
|
Loading…
Add table
Reference in a new issue