Add irc-buffers segment to the special mode-line.

Close #260.
Remove option: doom-modeline-irc-buffers.
Update special mode-line.
This commit is contained in:
Vincent Zhang 2019-11-19 23:44:19 +08:00
parent 7c0e93d0d9
commit 11d42282f2
3 changed files with 46 additions and 29 deletions

View file

@ -262,9 +262,6 @@ Run `M-x customize-group RET doom-modeline RET` or set the variables.
;; Whether display the irc notifications. It requires `circe' or `erc' package.
(setq doom-modeline-irc t)
;; Whether display the unread irc buffers.
(setq doom-modeline-irc-buffers nil)
;; Function to stylize the irc buffer names.
(setq doom-modeline-irc-stylize 'identity)

View file

@ -2113,11 +2113,11 @@ 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 (and (boundp 'tracking-shorten)
(car (tracking-shorten (list name))))
(and (boundp 'rcirc-short-buffer-name)
(rcirc-short-buffer-name name))
(and (boundp 'erc-track-shorten-function)
(functionp erc-track-shorten-function)
(car (funcall erc-track-shorten-function (list name))))
(and (boundp 'rcirc-short-buffer-name)
(rcirc-short-buffer-name name))
name))
(defun doom-modeline--tracking-buffers (buffers)
@ -2143,37 +2143,53 @@ to be an icon and we don't want to remove that so we just return the original."
(and (boundp 'tracking-mode-line-buffers)
(derived-mode-p 'circe-mode)))
(defun doom-modeline--rcirc-active ()
"Checks if `rcirc' is active"
(and (bound-and-true-p rcirc-track-minor-mode)
(boundp 'rcirc-activity)))
(defun doom-modeline--erc-active ()
"Checks if `erc' is active"
(and (bound-and-true-p erc-track-mode)
(boundp 'erc-modified-channels-alist)))
(defun doom-modeline--rcirc-active ()
"Checks if `rcirc' is active"
(and (bound-and-true-p rcirc-track-minor-mode)
(boundp 'rcirc-activity)))
(defun doom-modeline--get-buffers ()
"Gets the buffers that have activity"
(cond
((doom-modeline--circe-active)
tracking-buffers)
((doom-modeline--rcirc-active)
(mapcar (lambda (b)
(buffer-name b))
rcirc-activity))
((doom-modeline--erc-active)
(mapcar (lambda (l)
(buffer-name (car l)))
erc-modified-channels-alist))))
erc-modified-channels-alist))
((doom-modeline--rcirc-active)
(mapcar (lambda (b)
(buffer-name b))
rcirc-activity))))
;; 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
(doom-modeline--active)
(or (doom-modeline--circe-active)
(doom-modeline--erc-active)
(doom-modeline--rcirc-active)))
(let* ((buffers (doom-modeline--get-buffers))
(number (length buffers)))
(when (> number 0)
(concat
(doom-modeline-spc)
(doom-modeline--tracking-buffers buffers)
(doom-modeline-spc))))))
(doom-modeline-def-segment irc
"A notification icon for any unread irc buffer."
(when (and doom-modeline-irc
(doom-modeline--active)
(or (doom-modeline--circe-active)
(doom-modeline--rcirc-active)
(doom-modeline--erc-active)))
(doom-modeline--erc-active)
(doom-modeline--rcirc-active)))
(let* ((buffers (doom-modeline--get-buffers))
(number (length buffers)))
(when (> number 0)
@ -2197,12 +2213,12 @@ to be an icon and we don't want to remove that so we just return the original."
(cond
((doom-modeline--circe-active)
"mouse-1: Switch to previous unread buffer
mouse-3: Switch to next unread buffer")
((doom-modeline--rcirc-active)
"mouse-1: Switch to server buffer
mouse-3: Switch to next unread buffer")
((doom-modeline--erc-active)
"mouse-1: Switch to buffer
mouse-3: Switch to next unread buffer")
((doom-modeline--rcirc-active)
"mouse-1: Switch to server buffer
mouse-3: Switch to next unread buffer")))
'mouse-face 'mode-line-highlight
'local-map (let ((map (make-sparse-keymap)))
@ -2212,16 +2228,16 @@ mouse-3: Switch to next unread buffer")))
#'tracking-previous-buffer)
(define-key map [mode-line mouse-3]
#'tracking-next-buffer))
((doom-modeline--rcirc-active)
(define-key map [mode-line mouse-1]
#'rcirc-switch-to-server-buffer)
(define-key map [mode-line mouse-3]
#'rcirc-next-active-buffer))
((doom-modeline--erc-active)
(define-key map [mode-line mouse-1]
#'erc-switch-to-buffer)
(define-key map [mode-line mouse-3]
#'erc-track-switch-buffer)))
#'erc-track-switch-buffer))
((doom-modeline--rcirc-active)
(define-key map [mode-line mouse-1]
#'rcirc-switch-to-server-buffer)
(define-key map [mode-line mouse-3]
#'rcirc-next-active-buffer)))
map))
;; Disaplay the unread irc buffers

View file

@ -98,11 +98,11 @@
(doom-modeline-def-modeline 'special
'(bar window-number modals matches buffer-info buffer-position parrot selection-info)
'(objed-state misc-info battery irc debug lsp minor-modes input-method indent-info buffer-encoding major-mode process checker))
'(objed-state misc-info battery irc-buffers debug minor-modes input-method indent-info buffer-encoding major-mode process))
(doom-modeline-def-modeline 'project
'(bar window-number buffer-default-directory)
'(misc-info battery mu4e github debug major-mode process))
'(misc-info battery irc mu4e github debug major-mode process))
(doom-modeline-def-modeline 'package
'(bar window-number package)
@ -126,7 +126,7 @@
(doom-modeline-def-modeline 'timemachine
'(bar window-number matches git-timemachine buffer-position parrot selection-info)
'(misc-info battery mu4e github debug minor-modes indent-info buffer-encoding major-mode))
'(misc-info battery irc mu4e github debug minor-modes indent-info buffer-encoding major-mode))
;;
;; Interfaces
@ -226,6 +226,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 'image-mode-hook #'doom-modeline-set-media-modeline)
(add-hook 'circe-mode-hook #'doom-modeline-set-special-modeline)
(add-hook 'erc-mode-hook #'doom-modeline-set-special-modeline)
(add-hook 'rcirc-mode-hook #'doom-modeline-set-special-modeline)
(add-hook 'pdf-view-mode-hook #'doom-modeline-set-pdf-modeline)
(add-hook 'git-timemachine-mode-hook #'doom-modeline-set-timemachine-modeline)
(add-hook 'paradox-menu-mode-hook #'doom-modeline-set-package-modeline)
@ -245,6 +247,8 @@ 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 'image-mode-hook #'doom-modeline-set-media-modeline)
(remove-hook 'circe-mode-hook #'doom-modeline-set-special-modeline)
(remove-hook 'erc-mode-hook #'doom-modeline-set-special-modeline)
(remove-hook 'rcirc-mode-hook #'doom-modeline-set-special-modeline)
(remove-hook 'pdf-view-mode-hook #'doom-modeline-set-pdf-modeline)
(remove-hook 'git-timemachine-mode-hook #'doom-modeline-set-timemachine-modeline)
(remove-hook 'paradox-menu-mode-hook #'doom-modeline-set-package-modeline)