Skip to content

Commit

Permalink
Allow customizing faces for queries and non-highlighted channels
Browse files Browse the repository at this point in the history
At this point, we have a possibility to customize the color of a channel (in the
tracking segment of a modeline) where somebody mentioned our name. We use the
same face as for printing our name in the message itself
(`circe-highlight-nick-face`).

This is IMHO not sufficient because new personal messages are as important as
mentions in a channel and they can be easily missed when shown in the
default (for me gray) color. I am adding a support for this.

While I am at it, I am adding a possibility to customize a color of a channel,
that doesn't mention our name but has some new activity in it.

I understand that `tracking-add-buffer` allows adding buffers to
`tracking-buffers` with face and we may utilize this feature. I believe it makes
sense for what whatever it is currently used but I would prefer to have a
possibility to apply faces when rendering (in opposite to assigning a face when
some activity happens), hence `tracking-get-face`.

By default, I am setting the `circe-tracking-channel-face` and
`circe-tracking-query-face` to `nil` and therefore they are not going
to be customized and a backward-compatibility is going to be kept for
everybody who doesn't care about this feature. Personally, I am
putting the following lines to my config.

    (setq tracking-get-face-function #'circe-tracking-get-face)
    (set-face-attribute 'circe-tracking-channel-face nil :foreground my/white)
    (set-face-attribute 'circe-tracking-query-face nil :foreground my/blue)
  • Loading branch information
FrostyX committed May 24, 2024
1 parent 9d703f4 commit 104e863
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
24 changes: 24 additions & 0 deletions circe.el
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ See the {topic-diff} parameter to `circe-format-server-topic'."
See `circe-fool-list'."
:group 'circe)

(defface circe-tracking-channel-face
nil
"The face used by circe-tracking to show channels with activity in modeline."
:group 'circe)

(defface circe-tracking-query-face
nil
"The face used by circe-tracking to show query buffers with activity in
modeline."
:group 'circe)

;;;;;;;;;;;;;;;;;;;
;;;; Variables ;;;;
;;;;;;;;;;;;;;;;;;;
Expand Down Expand Up @@ -1556,6 +1567,19 @@ PATTERNS should be the list of regular expressions."
(throw 'return t)))
nil)))

(defun circe-tracking-get-face (buffer)
"Return face for a given buffer. If the buffer has already some face
specified, use it. This covers channels where our name was mentioned. Otherwise
decide whether the buffer is for a channel, query or else and use a face based
on this."
(with-current-buffer buffer
(cond ((get-text-property 0 'face buffer))
((eq major-mode 'circe-channel-mode)
'circe-tracking-channel-face)
((eq major-mode 'circe-query-mode)
'circe-tracking-query-face)
(t (tracking-get-face buffer)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Nick Highlighting ;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
15 changes: 14 additions & 1 deletion tracking.el
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ If set to nil, all buffers will be shown."
(integer :tag "Maximum"))
:group 'tracking)

(defcustom tracking-get-face-function #'tracking-get-face
"Function that returns face for a given buffer. It defaults to
`tracking-get-face' which simply returns any face that is stored in
`tracking-buffers'. Circe users may set this variable to
`circe-tracking-get-face' instead."
:type 'function
:group 'tracking)

;;; Internal variables
(defvar tracking-buffers nil
"The list of currently tracked buffers.")
Expand Down Expand Up @@ -361,7 +369,7 @@ only return that many entries, ending with '+n'."
(while buffer-names
(push `(:propertize
,(car shortened-names)
face ,(get-text-property 0 'face (car buffer-names))
face ,(funcall tracking-get-face-function (car buffer-names))
keymap ,(let ((map (make-sparse-keymap)))
(define-key map [mode-line down-mouse-1]
`(lambda ()
Expand Down Expand Up @@ -447,5 +455,10 @@ This returns STRING with the new face."
(propertize string 'face candidate))))
string)))

(defun tracking-get-face (buffer)
"Return face for a given buffer. If the buffer has already some face
specified, use it. Otherwise, return `nil'."
(get-text-property 0 'face buffer))

(provide 'tracking)
;;; tracking.el ends here

0 comments on commit 104e863

Please # to comment.