From 4f56d58d75b0dbc542091c8652af6e692486b035 Mon Sep 17 00:00:00 2001 From: Jakub Kadlcik Date: Tue, 12 Jan 2021 21:45:40 +0100 Subject: [PATCH] Allow customizing faces for queries and non-highlighted channels 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) --- circe.el | 24 ++++++++++++++++++++++++ tracking.el | 15 ++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/circe.el b/circe.el index 3668b8ec..c64e5343 100644 --- a/circe.el +++ b/circe.el @@ -109,6 +109,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 ;;;; ;;;;;;;;;;;;;;;;;;; @@ -1489,6 +1500,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) + (tracking-get-face nil)))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; Nick Highlighting ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/tracking.el b/tracking.el index 0985ca03..788beeb7 100644 --- a/tracking.el +++ b/tracking.el @@ -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.") @@ -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 () @@ -446,5 +454,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