unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#73911: Issue with `widget-specify-button'
@ 2024-10-20 13:01 David Ponce via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; only message in thread
From: David Ponce via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-10-20 13:01 UTC (permalink / raw)
  To: 73911

[-- Attachment #1: Type: text/plain, Size: 2382 bytes --]

Hello,

I found that `widget-specify-button' produces unexpected result when
button prefix string has a space (and maybe others) display
properties.

To illustrate the issue with emacs -Q, evaluate the below code in the
*scratch* buffer:

(require 'wid-edit)
(let* ((thin-space (propertize " " 'display '(space :width 0.5)))
        (widget-push-button-prefix thin-space)
        (widget-push-button-suffix thin-space))
   (widget-create 'push-button
		 :notify #'ignore
		 :button-face '( ;;:background "lightgrey"
				 :box t)
		 ;;:suppress-face t
		 "OK")
   (insert "\n"))

I found that the culprit is the invisible space that
`widget-specify-button' puts at the beginning of the button (no idea
why) using a 'before-string overlay property, at line 467:

(overlay-put overlay 'before-string #(" " 0 1 (invisible t)))

Giving this invisible space the same face property as the rest of the
button fixed the issue for me.  This is what I propose in the below
patch.  With this fix the above test will give the expected result.

Thanks

diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el
index 1d47f80b0dd..fd1747d3562 100644
--- a/lisp/wid-edit.el
+++ b/lisp/wid-edit.el
@@ -460,17 +460,20 @@ widget-specify-button
    "Specify button for WIDGET between FROM and TO."
    (let ((overlay (make-overlay from to nil t nil))
  	(follow-link (widget-get widget :follow-link))
-	(help-echo (widget-get widget :help-echo)))
+	(help-echo (widget-get widget :help-echo))
+	(face (unless (widget-get widget :suppress-face)
+		(widget-apply widget :button-face-get))))
      (widget-put widget :button-overlay overlay)
      (when (functionp help-echo)
        (setq help-echo 'widget-mouse-help))
-    (overlay-put overlay 'before-string #(" " 0 1 (invisible t)))
+    (overlay-put overlay 'before-string
+                 (propertize " " 'invisible t 'face face))
      (overlay-put overlay 'button widget)
      (overlay-put overlay 'keymap (widget-get widget :keymap))
      (overlay-put overlay 'evaporate t)
      ;; We want to avoid the face with image buttons.
-    (unless (widget-get widget :suppress-face)
-      (overlay-put overlay 'face (widget-apply widget :button-face-get))
+    (when face
+      (overlay-put overlay 'face face)
        (overlay-put overlay 'mouse-face
  		   ;; Make new list structure for the mouse-face value
  		   ;; so that different widgets will have

[-- Attachment #2: wid-edit.el.patch --]
[-- Type: text/x-patch, Size: 1331 bytes --]

diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el
index 1d47f80b0dd..fd1747d3562 100644
--- a/lisp/wid-edit.el
+++ b/lisp/wid-edit.el
@@ -460,17 +460,20 @@ widget-specify-button
   "Specify button for WIDGET between FROM and TO."
   (let ((overlay (make-overlay from to nil t nil))
 	(follow-link (widget-get widget :follow-link))
-	(help-echo (widget-get widget :help-echo)))
+	(help-echo (widget-get widget :help-echo))
+	(face (unless (widget-get widget :suppress-face)
+		(widget-apply widget :button-face-get))))
     (widget-put widget :button-overlay overlay)
     (when (functionp help-echo)
       (setq help-echo 'widget-mouse-help))
-    (overlay-put overlay 'before-string #(" " 0 1 (invisible t)))
+    (overlay-put overlay 'before-string
+                 (propertize " " 'invisible t 'face face))
     (overlay-put overlay 'button widget)
     (overlay-put overlay 'keymap (widget-get widget :keymap))
     (overlay-put overlay 'evaporate t)
     ;; We want to avoid the face with image buttons.
-    (unless (widget-get widget :suppress-face)
-      (overlay-put overlay 'face (widget-apply widget :button-face-get))
+    (when face
+      (overlay-put overlay 'face face)
       (overlay-put overlay 'mouse-face
 		   ;; Make new list structure for the mouse-face value
 		   ;; so that different widgets will have

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-10-20 13:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-20 13:01 bug#73911: Issue with `widget-specify-button' David Ponce via Bug reports for GNU Emacs, the Swiss army knife of text editors

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).