diff --git a/doom-modeline-core.el b/doom-modeline-core.el index 47798a9..849ac00 100644 --- a/doom-modeline-core.el +++ b/doom-modeline-core.el @@ -122,6 +122,11 @@ The icons may not be showed correctly in terminal and on Windows.") (defvar doom-modeline-mu4e t "Whether display mu4e notifications or not. Requires `mu4e-alert' package.") +(defvar doom-modeline-irc t + "Whether display irc notifications or not. Requires `circe' package.") + +(defvar doom-modeline-irc-stylize 'identity + "Function to stylize the irc buffer names.") ;; ;; Custom faces diff --git a/doom-modeline-segments.el b/doom-modeline-segments.el index 8d99f19..7499623 100644 --- a/doom-modeline-segments.el +++ b/doom-modeline-segments.el @@ -71,6 +71,7 @@ (defvar winum-auto-setup-mode-line) (defvar xah-fly-insert-state-q) (defvar mu4e-alert-mode-line) +(defvar tracking-buffers) (declare-function anzu--reset-status 'anzu) (declare-function anzu--where-is-here 'anzu) @@ -130,6 +131,7 @@ (declare-function winum--clear-mode-line 'winum) (declare-function winum--install-mode-line 'winum) (declare-function winum-get-number-string 'winum) +(declare-function tracking-shorten 'tracking) ;; @@ -1519,6 +1521,61 @@ mouse-1: Toggle Debug on Quit" "You have an unread email" (format "You have %s unread emails" mu4e-alert-mode-line))))) + +;; +;; irc notifications +;; + +(defun doom-modeline--shorten-irc (name) + "Wrapper for `tracking-shorten' that only takes one NAME. + +One key difference is that when `tracking-shorten' returns nil we +will instead return the original value of name. This is necessary +in cases where the user has stylized the name to be an icon and +we don't want to remove that so we just return the original." + (or (car (tracking-shorten (list name))) + name)) + +(defun doom-modeline--tracking-buffers (buffers) + "Logic to convert some irc BUFFERS to their font-awesome icon." + (mapconcat + (lambda (b) + (propertize + (doom-modeline--shorten-irc (funcall doom-modeline-irc-stylize b)) + 'face '(:inherit (warning doom-modeline-unread-number)) + 'help-echo b)) + buffers + ;; `space-width' only affects the width of the spaces here, so we can tighten + ;; it to be a bit more compact + (propertize " ยท " 'display '(space-width 0.4)))) + +;; create a modeline segment that contains all the irc tracked buffers +(doom-modeline-def-segment irc-buffers + "The list of shortened, unread irc buffers." + (when (and doom-modeline-irc + (boundp 'tracking-mode-line-buffers) + (doom-modeline--active) + (derived-mode-p 'circe-mode)) + ;; add a space at the end to pad against the following segment + (concat " " (doom-modeline--tracking-buffers tracking-buffers) " "))) + +(doom-modeline-def-segment irc + "A notification icon for any unread irc buffer." + (when (and doom-modeline-irc + (boundp 'tracking-mode-line-buffers) + (> (length tracking-buffers) 0) + (doom-modeline--active)) + (concat + " " + (propertize (doom-modeline-icon-material "sms" + :height 0.9 + :face 'doom-modeline-warning) + 'help-echo (format "IRC Notifications: %s" + (doom-modeline--tracking-buffers + tracking-buffers)) + 'display '(raise -0.17)) + " "))) + (provide 'doom-modeline-segments) ;;; doom-modeline-segments.el ends here diff --git a/doom-modeline.el b/doom-modeline.el index f4fe081..0a12b2b 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -84,7 +84,7 @@ (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) - '(misc-info persp-name lsp mu4e github debug minor-modes input-method buffer-encoding major-mode process vcs checker)) + '(misc-info persp-name lsp irc mu4e github debug minor-modes input-method buffer-encoding major-mode process vcs checker)) (doom-modeline-def-modeline 'minimal '(bar matches " " buffer-info) @@ -92,7 +92,7 @@ (doom-modeline-def-modeline 'special '(bar window-number evil-state god-state ryo-modal xah-fly-keys matches buffer-info-simple buffer-position parrot selection-info) - '(misc-info lsp debug minor-modes input-method buffer-encoding major-mode process checker)) + '(misc-info lsp debug minor-modes input-method irc-buffers buffer-encoding major-mode process checker)) (doom-modeline-def-modeline 'project '(bar " " buffer-default-directory)