Subject: Re: bug#61413: [PATCH] Make warnings show a "warning" emoji instead of a stop-sign

From: Kévin Le Gouguec <[email-masked]>
Date: Sat, 15 Feb 2025 23:40:10 +0100

Kévin Le Gouguec <[email-masked]> writes:

> 'buttonize' clobbers the help-echo property added by 'icon-string' ☹️
> That does make the current emoji extra-obscure, since hovering over it
> gives no clue as to what it does!
>
> Solutions:
>
> (a) display-warning could retrieve the property from the string returned
> by icon-string, then spoon-feeding it back to buttonize,
> (b) buttonize could check whether its STRING argument has a help-echo
> property before clobbering it with nil,
> (c) we invent a sentinel value for buttonize's HELP-ECHO argument to
> mean "psst, STRING already has the right help-echo property; use that".

See attached patches.  No intuition which is best; I guess (a) is the
least disruptive - no change in the semantics of 'buttonize'.

I wonder how critical we think finding a new graphical representation
for that button feels now, considering that once this is fixed,
mouse-hovering & C-h . will let users now what that button is for.

diff --git a/lisp/emacs-lisp/warnings.el b/lisp/emacs-lisp/warnings.el
index 8a5c73ebd3a..4a2231e229d 100644
--- a/lisp/emacs-lisp/warnings.el
+++ b/lisp/emacs-lisp/warnings.el
@@ -319,9 +319,10 @@ display-warning
               ;; Don't output the button when doing batch compilation
               ;; and similar.
               (unless (or noninteractive (eq type 'bytecomp))
-                (insert (buttonize (icon-string 'warnings-suppress)
-                                   #'warnings-suppress type)
-                        " "))
+                (let* ((string (icon-string 'warnings-suppress))
+                       (help-echo (get-text-property 0 'help-echo string)))
+                (insert (buttonize string #'warnings-suppress type help-echo)
+                        " ")))
 	      (if warning-prefix-function
 		  (setq level-info (funcall warning-prefix-function
 					    level level-info)))
diff --git a/lisp/button.el b/lisp/button.el
index 674de1bb4fa..81e36a956c0 100644
--- a/lisp/button.el
+++ b/lisp/button.el
@@ -641,12 +641,16 @@ buttonize
 function argument.  If DATA isn't present (or is nil), the button
 itself will be used instead as the function argument.
 
-If HELP-ECHO, use that as the `help-echo' property.
+If HELP-ECHO is non-nil, use that as the `help-echo' property.  If it is
+nil, use the `help-echo' property of STRING as a fallback.
 
 Also see `buttonize-region'."
   (let ((string
          (apply #'propertize string
-                (button--properties callback data help-echo))))
+                (button--properties
+                 callback data
+                 (or help-echo
+                     (get-text-property 0 'help-echo string))))))
     ;; Add the face to the end so that it can be overridden.
     (add-face-text-property 0 (length string) 'button t string)
     string))
diff --git a/lisp/button.el b/lisp/button.el
index 674de1bb4fa..64227a678cd 100644
--- a/lisp/button.el
+++ b/lisp/button.el
@@ -641,12 +641,17 @@ buttonize
 function argument.  If DATA isn't present (or is nil), the button
 itself will be used instead as the function argument.
 
-If HELP-ECHO, use that as the `help-echo' property.
+If HELP-ECHO is non-nil, use that as the `help-echo' property; as a
+special case, if it is the symbol `preserve', use the `help-echo'
+property of STRING.
 
 Also see `buttonize-region'."
-  (let ((string
-         (apply #'propertize string
-                (button--properties callback data help-echo))))
+  (let* ((help-echo (if (eq help-echo 'preserve)
+                        (get-text-property 0 'help-echo string)
+                      help-echo))
+         (string
+          (apply #'propertize string
+                 (button--properties callback data help-echo))))
     ;; Add the face to the end so that it can be overridden.
     (add-face-text-property 0 (length string) 'button t string)
     string))
diff --git a/lisp/emacs-lisp/warnings.el b/lisp/emacs-lisp/warnings.el
index 8a5c73ebd3a..2bb5bc6cb46 100644
--- a/lisp/emacs-lisp/warnings.el
+++ b/lisp/emacs-lisp/warnings.el
@@ -320,7 +320,7 @@ display-warning
               ;; and similar.
               (unless (or noninteractive (eq type 'bytecomp))
                 (insert (buttonize (icon-string 'warnings-suppress)
-                                   #'warnings-suppress type)
+                                   #'warnings-suppress type 'preserve)
                         " "))
 	      (if warning-prefix-function
 		  (setq level-info (funcall warning-prefix-function