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

From: Kévin Le Gouguec <[email-masked]>
Date: Thu, 20 Feb 2025 22:50:33 +0100

Mauro Aranda <[email-masked]> writes:

>>> I think we'd like something similar for buttonize-region, so I wonder if
>>> it's not better to do the change inside button--properties, though.
>>
>> ACK to improve buttonize-region too.  button--properties does not have
>> access to the information needed to get the fallback help-echo tho
>> (STRING for buttonize, START END for buttonize-region), are you thinking
>> of passing that fallback as a new argument, or have I missed something?
>
> I was thinking in not overwriting the help-echo property if the
> help-echo argument is nil.

💡 Gotcha.  Much cleaner than the original patch - that
(get-text-property 0 …) was not very elegant.

> Currently, button--properties forces a value for the help-echo property.
> So it would be like: If it's nil,  don't add the help-echo property to
> the property list at all, leaving a previous help-echo property
> untouched.

How does the attached look?

>From 692ebd5cd291b90eb6d9324efc454c6b1cf04e87 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?K=C3=A9vin=20Le=20Gouguec?= <[email-masked]>
Date: Thu, 20 Feb 2025 22:37:13 +0100
Subject: [PATCH] Prevent button.el from clearing help-echo strings

In order to fix one of the issues discussed in bug#61413, i.e.
'buttonize' clobbering the help-echo property set by
'icon-string'.

This is a reasonable interpretation of the button.el
docstrings - "if HELP-ECHO, use that as the `help-echo'
property"; conversely, if not HELP-ECHO, then do not do
anything, preserving existing values for that property.

* lisp/button.el (button--properties): Only add a help-echo
property if HELP-ECHO is non-nil.
* test/lisp/button-tests.el (button--preserve-help-echo):
Validate this change.
---
 lisp/button.el            | 20 +++++++++++---------
 test/lisp/button-tests.el | 14 ++++++++++++++
 2 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/lisp/button.el b/lisp/button.el
index 674de1bb4fa..f0f3c60ee0e 100644
--- a/lisp/button.el
+++ b/lisp/button.el
@@ -652,15 +652,17 @@ buttonize
     string))
 
 (defun button--properties (callback data help-echo)
-  (list 'font-lock-face 'button
-        'mouse-face 'highlight
-        'help-echo help-echo
-        'button t
-        'follow-link t
-        'category t
-        'button-data data
-        'keymap button-map
-        'action callback))
+  (append
+   (list 'font-lock-face 'button
+         'mouse-face 'highlight
+         'button t
+         'follow-link t
+         'category t
+         'button-data data
+         'keymap button-map
+         'action callback)
+   (and help-echo
+        (list 'help-echo help-echo))))
 
 (defun buttonize-region (start end callback &optional data help-echo)
   "Make the region between START and END into a button.
diff --git a/test/lisp/button-tests.el b/test/lisp/button-tests.el
index 7f6a5bd52cd..83782236de3 100644
--- a/test/lisp/button-tests.el
+++ b/test/lisp/button-tests.el
@@ -101,4 +101,18 @@ button--help-echo-function
       (setq button (insert-button "overlay" 'help-echo help))
       (should (equal (button--help-echo button) "overlay: x")))))
 
+(ert-deftest button--preserve-help-echo ()
+  "Ensure buttonizing functions preserve existing `help-echo' properties."
+  ;; buttonize.
+  (let* ((string (propertize "button text" 'help-echo "help text"))
+         (button (buttonize string #'ignore)))
+    (should (equal (get-text-property 0 'help-echo button)
+                   "help text")))
+  ;; buttonize-region.
+  (with-temp-buffer
+    (insert (propertize "button text" 'help-echo "help text"))
+    (buttonize-region (point-min) (point) #'ignore)
+    (should (equal (get-text-property (point-min) 'help-echo)
+                   "help text"))))
+
 ;;; button-tests.el ends here
-- 
2.48.1