all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Mauro Aranda <maurooaranda@gmail.com>
Cc: 25152@debbugs.gnu.org
Subject: bug#25152: 25.1; Customize: errors for `restricted-sexp' in `repeat'
Date: Sat, 5 Sep 2020 07:46:42 -0700 (PDT)	[thread overview]
Message-ID: <45d48716-1ac9-4cb3-9c64-042dddee4e77@default> (raw)
In-Reply-To: <CABczVwdg=3dF=OrWVATVRjbFU=xWYfn4oczxZTnZ351Nne3AkA@mail.gmail.com>

>> emacs -Q
>>
>> (defcustom bar
>>   `(ignore)
>>   "..."
>>   :type
>>   '(repeat (restricted-sexp :match-alternatives (functionp)))
>>   :group 'emacs)
>>
>> M-x customize-option bar
>>
>> 1. Click the INS button, to insert a new element in the list.
>> 2. At the prompt "Lisp expression: ", hit `C-g'.
>
> You shouldn't be prompted, because the widget library is not ready to
> take user input at this stage (the stage being the creation of the
> widget).
>
> The prompt comes from the function :value-to-external of the sexp
> widget, which is called in the process of creating the widget.  The
>:value-to-external function calls read with the value of the widget,
> like this: (read value)
>
> It does that assuming value is a string.  It does not want user input
> (by reading it from the minibuffer), it just wants to take the widget
> value and return it in the "external" format.  The function
>:value-to-internal is the one that should print the value of the widget
> to a string.  But it only does that if the value matches the widget, as
> with the function :match, which in the defcustom posted in the recipe is
> widget-restricted-sexp-match.
>
> So, why doesn't the value of the widget satisfy
> widget-restricted-sexp-match, at the widget creation stage?  That's
> because :match-alternatives is '(functionp), and the default value of
> the widget is nil.  Because of that, widget-restricted-sexp-match
> returns nil, and we store the value intact (i.e., not in the "internal"
> format), and we end up evaluating (read nil), resulting in the prompt
> and losing badly.
>
> But, the Elisp manual says:
> ‘:value DEFAULT’
>     Provide a default value.
>
>     If ‘nil’ is not a valid value for the alternative, then it is
>     essential to specify a valid default with ‘:value’.
>
> So the defcustom provided is lacking the essential :value DEFAULT thing.
> If we compare the behavior with the following defcustom:
> (defcustom bar
>  `(ignore)
>  "..."
>  :type
>  '(repeat (restricted-sexp :match-alternatives (functionp)
>                            :value ignore))
>  :group 'emacs)
>
> And in the customization buffer we click the INS button, then there's no
> prompt: creation of the widget happens with no problem.
>
> Another defcustom, that makes nil a valid value:
> (defcustom bar
>  `(ignore)
>  "..."
>  :type
>  '(repeat (restricted-sexp :match-alternatives (functionp null)))
>  :group 'emacs) 
>
> Again, click the INS button: no problem.
>
>
> To sum it up, the prompt is an unfortunate mistake, and maybe we could
> protect against that, but I think the real problem comes from the
> defcustom, which fails to provide a valid default value.

Thanks for this explanation.  Makes sense.

Can we somehow help users by raising an error when they
do this?  Seems like a simple mistake to make.





  reply	other threads:[~2020-09-05 14:46 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-09 18:10 bug#25152: 25.1; Customize: errors for `restricted-sexp' in `repeat' Drew Adams
2016-12-10  4:24 ` npostavs
2016-12-10  4:39   ` Drew Adams
2020-09-05 11:57 ` Mauro Aranda
2020-09-05 14:46   ` Drew Adams [this message]
2020-09-05 16:53     ` Mauro Aranda
2020-10-23 12:59       ` Mauro Aranda
2020-10-23 16:47         ` Drew Adams
2020-10-24 12:33           ` Mauro Aranda
2020-10-24 20:16             ` Drew Adams
2020-10-24 19:41         ` Lars Ingebrigtsen
2020-10-24 20:23           ` Drew Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45d48716-1ac9-4cb3-9c64-042dddee4e77@default \
    --to=drew.adams@oracle.com \
    --cc=25152@debbugs.gnu.org \
    --cc=maurooaranda@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.