From b6b6691ea3ea9d07d4fb3bade372fb9c383146e0 Mon Sep 17 00:00:00 2001 From: Sean Farley Date: Fri, 1 Feb 2019 15:55:14 -0800 Subject: [PATCH] irc: add new segment to display the unread buffers This includes a configuration variable that allows the user to customize the display of the name. The segment is only displayed in the 'special modeline due to space. Later, we'll add a irc notification for the 'main modeline. --- doom-modeline-core.el | 5 +++++ doom-modeline-segments.el | 40 +++++++++++++++++++++++++++++++++++++++ doom-modeline.el | 2 +- 3 files changed, 46 insertions(+), 1 deletion(-) 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 a67d615..80b6f04 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,44 @@ 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) " "))) + (provide 'doom-modeline-segments) ;;; doom-modeline-segments.el ends here diff --git a/doom-modeline.el b/doom-modeline.el index f4fe081..c462b43 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -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)