Subject: bug#63838: 28.2; 'wid-edit.el' problems with 'integer' (and 'sexp') widgets.

From: Mauro Aranda <[email-masked]>
Date: Sun, 16 Jul 2023 08:50:28 -0300

Marco Antoniotti <[email-masked]> writes:

 > Hi

Thanks for the bug report!

 > The issue is with the following code that tries to use the Widget
 > library.  The slots of the widget are actually not necessary to see the
 > problem.
 >
 >  (widget-create 'integer
 >                 :help-echo "Enter an integer..."
 >                 :notify (lambda (w1 &rest ws)
 >                            (ignore ws)
 >                            (message "WIFT: IF: %s"
 >                                     (widget-value w1)
 >                            ))
 >                 :size 4
 >   )

The :notify value is kind of necessary, right? I mean, the bug doesn't
manifest as long as code doesn't try to access the value of a
restricted-sexp widget while its empty.

 > Specializing the widget with a hack like the function below fixes the
 > problem, but a
 > good solution may need some more work to get all the corner cases.
 > Note that setting a "widget buffer" in overwrite mode goes a long way to
 > mitigate these problems: maybe having widget-setup switch to it would
 > be another good thing to do.

I don't think we want to do that.

 >  :value-to-external
 >   (lambda (widget value)
 >     ;; Lifted, and fixed, from `:value-to-external' in
 >     ;; `restricted-sexp'.
 >
 >     (unless (stringp value)
 >       (display-warning
 >        'widget-bad-default-value
 >        (format-message
 >         "\nA widget of type %S has a bad default value.
 > value: %S
 > match function: %S
 > match-alternatives: %S"
 >         (widget-type widget)
 >         value
 >         (widget-get widget :match)
 >         (widget-get widget :match-alternatives))
 >        :warning))
 >     (if (and (stringp value) (string-equal "" value))
 >         ;; Oooops, we cannot just `read'.
 >         (widget-get widget :default-value)
 >       (read value))
 >     )

I don't think this is a good place to do this.  And there's no
:default-value property in the widget library, just :value.

I think it'd be much better if we specialize the :value-get function for
the restricted-sexp widget, defaulting to return :value when the widget
is empty.