From 28517cf23b5ed65f8a421dddcffec6a0aecd7fe5 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Fri, 13 Jan 2023 05:13:06 -0800 Subject: [PATCH 3/3] [5.6] Allow erc-button-add-face to take an object * lisp/erc/erc-button.el (erc-button--add-nickname-face-function): New internal var. (erc-button-add-button): Call `erc-button--add-nickname-face-function' when it's a function for applying `erc-button-nickname-face'. (erc-button-add-face): Add optional `object' param. (Bug#60933.) --- lisp/erc/erc-button.el | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lisp/erc/erc-button.el b/lisp/erc/erc-button.el index eca3df44892..c94a412eea8 100644 --- a/lisp/erc/erc-button.el +++ b/lisp/erc/erc-button.el @@ -391,6 +391,8 @@ erc-button-remove-old-buttons mouse-face nil keymap nil))) +(defvar erc-button--add-nickname-face-function nil) + (defun erc-button-add-button (from to fun nick-p &optional data regexp) "Create a button between FROM and TO with callback FUN and data DATA. NICK-P specifies if this is a nickname button. @@ -417,7 +419,10 @@ 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)) + (if erc-button--add-nickname-face-function + (funcall erc-button--add-nickname-face-function + from to erc-button-nickname-face) + (erc-button-add-face from to erc-button-nickname-face))) (when erc-button-face (erc-button-add-face from to erc-button-face))) (add-text-properties @@ -429,16 +434,16 @@ erc-button-add-button (list 'rear-nonsticky t) (and data (list 'erc-data data))))) -(defun erc-button-add-face (from to face) +(defun erc-button-add-face (from to face &optional object) "Add FACE to the region between FROM and TO." ;; If we just use `add-text-property', then this will overwrite any ;; face text property already used for the button. It will not be ;; merged correctly. If we use overlays, then redisplay will be ;; very slow with lots of buttons. This is why we manually merge ;; face text properties. - (let ((old (erc-list (get-text-property from 'font-lock-face))) + (let ((old (erc-list (get-text-property from 'font-lock-face object))) (pos from) - (end (next-single-property-change from 'font-lock-face nil to)) + (end (next-single-property-change from 'font-lock-face object to)) new) ;; old is the face at pos, in list form. It is nil if there is no ;; face at pos. If nil, the new face is FACE. If not nil, the @@ -446,10 +451,10 @@ erc-button-add-face ;; where this face changes. (while (< pos to) (setq new (if old (cons face old) face)) - (put-text-property pos end 'font-lock-face new) + (put-text-property pos end 'font-lock-face new object) (setq pos end - old (erc-list (get-text-property pos 'font-lock-face)) - end (next-single-property-change pos 'font-lock-face nil to))))) + old (erc-list (get-text-property pos 'font-lock-face object)) + end (next-single-property-change pos 'font-lock-face object to))))) ;; widget-button-click calls with two args, we ignore the first. ;; Since Emacs runs this directly, rather than with -- 2.39.2