>From 9466b7ebb1ac4a8316f764e76cc57406d15d0f18 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Mon, 11 Dec 2023 01:30:48 -0800 Subject: [PATCH 3/3] [5.6] Add erc-track integration to erc-nicks * lisp/erc/erc-button.el (erc-button-add-button): Use `erc--merge-prop' instead of `erc-button-add-face' to apply button faces. Hold off on deprecating the latter because it provides unique functionality for nesting faces. * lisp/erc/erc-nicks.el (erc-nicks-track-faces): New option. (erc-nicks--highlight-button): Add faces to `erc-track' "normal" table. (erc-nicks-mode, erc-nicks-enable, erc-nicks-disable): Add and remove `track' integration. (erc-nicks--reject-uninterned-faces): New function to remove faces created by `nicks' from buttonized speakers and mentions. Conform to `erc-track--face-reject-function' interface. (erc-nicks--setup-track-integration): New function. (erc-nicks--track-nick-face-as-normal): New function to add newly created face and known likely combination working store of "normal" faces maintained by `track'. --- lisp/erc/erc-button.el | 4 ++-- lisp/erc/erc-nicks.el | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lisp/erc/erc-button.el b/lisp/erc/erc-button.el index e1c10be53f6..e72ceb705de 100644 --- a/lisp/erc/erc-button.el +++ b/lisp/erc/erc-button.el @@ -535,9 +535,9 @@ erc-button-add-button (move-marker pos (point)))))) (if nick-p (when erc-button-nickname-face - (erc-button-add-face from to erc-button-nickname-face)) + (erc--merge-prop from to 'font-lock-face erc-button-nickname-face)) (when erc-button-face - (erc-button-add-face from to erc-button-face))) + (erc--merge-prop from to 'font-lock-face erc-button-face))) (add-text-properties from to (nconc (and erc-button-mouse-face diff --git a/lisp/erc/erc-nicks.el b/lisp/erc/erc-nicks.el index fcd3afdbbc4..3043ad37f78 100644 --- a/lisp/erc/erc-nicks.el +++ b/lisp/erc/erc-nicks.el @@ -173,6 +173,10 @@ erc-nicks-key-suffix-format like \"@%-012n\"." :type 'string) +(defcustom erc-nicks-track-faces t + "Show nick faces in the `track' module's portion of the mode line." + :type 'boolean) + (defvar erc-nicks--max-skip-search 3 ; make this an option? "Max number of faces to visit when testing `erc-nicks-skip-faces'.") @@ -518,6 +522,8 @@ erc-nicks--highlight-button 'font-lock-face)) (nick (erc-server-user-nickname (erc-button--nick-user nick-object))) (out (erc-nicks--highlight nick face))) + (when erc-nicks-track-faces + (erc-nicks--track-nick-face-as-normal out)) (setf (erc-button--nick-nickname-face nick-object) out)) nick-object) @@ -561,6 +567,9 @@ nicks erc-nicks--face-table (make-hash-table :test #'equal))) (setf (alist-get "Edit face" erc-button--nick-popup-alist nil nil #'equal) #'erc-nicks-customize-face) + (unless erc-nicks-track-faces + (erc-nicks--setup-track-integration) + (add-hook 'erc-track-mode #'erc-nicks--setup-track-integration 50 t)) (advice-add 'widget-create-child-and-convert :filter-args #'erc-nicks--redirect-face-widget-link)) ((kill-local-variable 'erc-nicks--face-table) @@ -572,6 +581,8 @@ nicks (kill-local-variable 'erc-nicks--downcased-skip-nicks) (when (fboundp 'erc-button--phantom-users-mode) (erc-button--phantom-users-mode -1)) + (remove-function (local 'erc-track--face-reject-function) + #'erc-nicks--reject-uninterned-faces) (remove-function (local 'erc-button--modify-nick-function) #'erc-nicks--highlight-button) (setf (alist-get "Edit face" @@ -693,6 +704,28 @@ erc-nicks--colors-from-faces (color (face-foreground face))) (push color out))))) +(defun erc-nicks--reject-uninterned-faces (candidate) + "Remove own faces from CANDIDATE if it's a combination of faces." + (while-let ((next (car-safe candidate)) + ((facep next)) + ((not (intern-soft next)))) + (setq candidate (cdr candidate))) + (if (and (consp candidate) (not (cdr candidate))) (car candidate) candidate)) + +(defun erc-nicks--setup-track-integration () + "Restore traditional \"alternating normal\" face functionality to mode-line." + (cl-assert (not erc-nicks-track-faces)) + (when (bound-and-true-p erc-track-mode) + (add-function :override (local 'erc-track--face-reject-function) + #'erc-nicks--reject-uninterned-faces))) + +(defun erc-nicks--track-nick-face-as-normal (face) + "Add FACE to local hash table maintained by `track' module." + (when (bound-and-true-p erc-track--normal-faces) + (puthash `(,@(ensure-list face) erc-default-face) t + erc-track--normal-faces) + (puthash face t erc-track--normal-faces))) + (provide 'erc-nicks) ;;; erc-nicks.el ends here -- 2.42.0