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

From: Kévin Le Gouguec <[email-masked]>
Date: Fri, 21 Feb 2025 00:03:11 +0100

Mauro Aranda <[email-masked]> writes:

> Kévin Le Gouguec <[email-masked]> writes:
>
>> How does the attached look?
>
> I think the change looks good.  I've just realized that the other caller
> of button--properties might need a tweak.
>
> In unbuttonize-region, we should change this call:
> (remove-text-properties start end
>                             (button--properties nil nil nil))
>
> to:
> (remove-text-properties start end
>                             ;; t to ensure help-echo gets reset.
>                             (button--properties nil nil t))

(Thanks, should have caught that button--properties was called by
unbuttonize-region too 🤦)

> But, now we don't know if the help-echo property was effectively added
> by the library or it was already there :-(.  Sadness.

Would the attached address that problem?  (To apply on top of the
previous patch; I'll squash it all if we are happy with it)

diff --git a/lisp/button.el b/lisp/button.el
index f0f3c60ee0e..0d7ea483931 100644
--- a/lisp/button.el
+++ b/lisp/button.el
@@ -662,7 +662,9 @@ button--properties
          'keymap button-map
          'action callback)
    (and help-echo
-        (list 'help-echo help-echo))))
+        (list 'help-echo help-echo
+              ;; Record that button.el is responsible for this property.
+              'help-echo-button t))))
 
 (defun buttonize-region (start end callback &optional data help-echo)
   "Make the region between START and END into a button.
@@ -683,8 +685,13 @@ unbuttonize-region
     (when (overlay-get o 'button)
       (delete-overlay o)))
   (with-silent-modifications
-    (remove-text-properties start end
-                            (button--properties nil nil nil))
+    (remove-text-properties
+     start end
+     (append
+      (button--properties nil nil nil)
+      (and (get-text-property start 'help-echo-button)
+           (list 'help-echo nil
+                 'help-echo-button nil))))
     (add-face-text-property start end
                             'button nil)))
 
diff --git a/test/lisp/button-tests.el b/test/lisp/button-tests.el
index 83782236de3..b784cf02e28 100644
--- a/test/lisp/button-tests.el
+++ b/test/lisp/button-tests.el
@@ -113,6 +113,20 @@ button--preserve-help-echo
     (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"))))
+                   "help text"))
+    ;; unbuttonize-region should not clear the property either.
+    (unbuttonize-region (point-min) (point))
+    (should (equal (get-text-property (point-min) 'help-echo)
+                   "help text")))
+  ;; unbuttonize-region should still clear properties applied with
+  ;; buttonize.
+  (with-temp-buffer
+    (insert "button text")
+    (buttonize-region (point-min) (point) #'ignore nil "help text")
+    (should (equal (get-text-property (point-min) 'help-echo)
+                   "help text"))
+    (unbuttonize-region (point-min) (point))
+    (should (equal (get-text-property (point-min) 'help-echo)
+                   nil))))
 
 ;;; button-tests.el ends here