Subject: bug#59937: 28.2; Bad defcustom behavior

From: Mauro Aranda <[email-masked]>
Date: Sun, 16 Jul 2023 20:00:40 -0300

Hi Drew,

I'm sorry it took me so long to actually take a look at this.  I had to
reread the conversation to put myself back into topic.

As I said in https://debbugs.gnu.org/cgi/bugreport.cgi?bug=59937#26
I was looking for a way to:
1. Being able to create the restricted-sexp widget, even if the default
value for it isn't valid.
2. Being able to do it without prompting the user.

That's what the attached patch does.  AFAIU, we both agreed that that
approach was a good enough fix for this bug, so that the behavior of
certain defcustoms is less confusing.  We didn't really agree back then
about the warning, and I'm guessing that we still disagree on that, so I
didn't change anything about the warning.
From 12969e3b8b40c5af39209993c0a31e6b3bcb4a10 Mon Sep 17 00:00:00 2001
From: Mauro Aranda <[email-masked]>
Date: Sun, 16 Jul 2023 19:46:54 -0300
Subject: [PATCH] Avoid prompting when creating a restricted-sexp widget

* lisp/wid-edit.el (restricted-sexp): Turn value into a string before
reading.
(widget-field-value-create): Guard against value being nil, so the
field can be created even if the widget has a bad default value.
(Bug#59937)
---
 lisp/wid-edit.el | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el
index 234f3d9b74d..aaec2360db8 100644
--- a/lisp/wid-edit.el
+++ b/lisp/wid-edit.el
@@ -2127,7 +2127,8 @@ widget-field-value-create
 	;; `widget-setup' is called.
 	(overlay (cons (make-marker) (make-marker))))
     (widget-put widget :field-overlay overlay)
-    (insert value)
+    (when value
+      (insert value))
     (and size
 	 (< (length value) size)
 	 (insert-char ?\s (- size (length value))))
@@ -3655,7 +3656,9 @@ 'restricted-sexp
                            value
                            (widget-get widget :match)
                            (widget-get widget :match-alternatives))
-                          :warning))
+                          :warning)
+                         ;; Make sure we will `read' a string.
+                         (setq value (prin1-to-string value)))
                        (read value)))
 
 (defun widget-restricted-sexp-match (widget value)
-- 
2.34.1