From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mauro Aranda Newsgroups: gmane.emacs.bugs Subject: bug#25152: 25.1; Customize: errors for `restricted-sexp' in `repeat' Date: Sat, 5 Sep 2020 08:57:06 -0300 Message-ID: References: <037e3a81-b339-4440-ad7c-5ae9e1006050@default> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000eb351705ae8fafdb" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29207"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 25152@debbugs.gnu.org To: Drew Adams Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Sep 05 13:58:11 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kEWpe-0007UQ-PI for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 05 Sep 2020 13:58:10 +0200 Original-Received: from localhost ([::1]:56158 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kEWpd-0003vG-Re for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 05 Sep 2020 07:58:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34662) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kEWpX-0003v2-Dc for bug-gnu-emacs@gnu.org; Sat, 05 Sep 2020 07:58:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:58351) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kEWpW-000404-GL for bug-gnu-emacs@gnu.org; Sat, 05 Sep 2020 07:58:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kEWpW-0006d4-FQ for bug-gnu-emacs@gnu.org; Sat, 05 Sep 2020 07:58:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <037e3a81-b339-4440-ad7c-5ae9e1006050@default> Resent-From: Mauro Aranda Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 05 Sep 2020 11:58:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25152 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed Original-Received: via spool by 25152-submit@debbugs.gnu.org id=B25152.159930704625436 (code B ref 25152); Sat, 05 Sep 2020 11:58:02 +0000 Original-Received: (at 25152) by debbugs.gnu.org; 5 Sep 2020 11:57:26 +0000 Original-Received: from localhost ([127.0.0.1]:41664 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kEWow-0006cC-5Q for submit@debbugs.gnu.org; Sat, 05 Sep 2020 07:57:26 -0400 Original-Received: from mail-wm1-f50.google.com ([209.85.128.50]:50755) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kEWou-0006by-Gk for 25152@debbugs.gnu.org; Sat, 05 Sep 2020 07:57:24 -0400 Original-Received: by mail-wm1-f50.google.com with SMTP id e17so9111484wme.0 for <25152@debbugs.gnu.org>; Sat, 05 Sep 2020 04:57:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to:cc; bh=HvKSNesVcdR6VjG55pFqw0TECbPFqRZmXt4e1+KxBh4=; b=Dsq8XT0glPL5R8WKQZtAJrv+AZVQhtzBG3tEsGuRkJUWhFzOMw+gT7APigoH6aWAOX RT0XyaUABlRhDKKx07GQVAOzdR9LT1wkXqeNUcrsZBAQ8HJTbbw8Mk8+YNqNb3rVHUYh 6S49QaLoIDZkyXIfj/o2uEC0LTGlDZpoP7UaORqWwiFFPOT9XAXLypxCkRD84GoFrnnt XtfVa+qwT9L06d7K42Pu8vuen/eO/iwbjMJt/1fbG+p7KiegDc/nQopVDczYwrKY/PrM CEe9DOLVKWRJUFx3iK4rbGmGyASjljPAOIEPhnLw2N1so6Dqqn+pg4E0T+czEmM2BnAV 47nQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=HvKSNesVcdR6VjG55pFqw0TECbPFqRZmXt4e1+KxBh4=; b=VSLFZ+iBO4tN+yNm7PhPvyNSiPaQICKzFudi7V9AA2XThXBkPRMocti2AEhC7S2WGS KRbjQYyUz2rOS70XsZ1Z8k4wFQptNXmJnjjp8aUYom5nXfODd6CBLMVq80p9t4pI3dm3 EuCai7Zvt4rpIcBm1TqoresZ7Ri7SzWRq9JCs1CJkOGpiOrx7b2exW2R3BZrhtBcBW0a KD6A94lC2PfnGIPAVj2yOyTtVEt2fGhdxfez4WB5YhBUReBQcEMDldcuaqAumymuo8Cl zi7QgveQzEQCzqYVax/Ott6DT4poo5eoO6ERZBg6GxAAZ+EnRhKcdjYz5PiwdD1aQndh 6wIg== X-Gm-Message-State: AOAM533Hd40gq/UvfEL7khmwPqpJuc3RgFB+TxFXnYDfnFHjHGrZcl9a z2eVDN+35LYEbPVSFpKPqCwGkh45oYUafvXH+d8= X-Google-Smtp-Source: ABdhPJysaRtWetyyDlLd0UfoKl1tit9JAy55L+22Odu9aY11pc80zL8Phs4DZ3YdKjNy0AOgQmKFHKCMWy4J06qUfJw= X-Received: by 2002:a05:600c:230c:: with SMTP id 12mr11281561wmo.23.1599307038535; Sat, 05 Sep 2020 04:57:18 -0700 (PDT) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:187209 Archived-At: --000000000000eb351705ae8fafdb Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Drew Adams writes: > 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: =E2=80=98:value DEFAULT=E2=80=99 Provide a default value. If =E2=80=98nil=E2=80=99 is not a valid value for the alternative, the= n it is essential to specify a valid default with =E2=80=98:value=E2=80=99. 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. --000000000000eb351705ae8fafdb Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Drew Adams <dr= ew.adams@oracle.com> writes:

> emacs -Q
>
> (d= efcustom bar
> =C2=A0 `(ignore)
> =C2=A0 "..."
>= ; =C2=A0 :type
> =C2=A0 '(repeat (restricted-sexp :match-alternat= ives (functionp)))
> =C2=A0 :group 'emacs)
>
> M-x cu= stomize-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 t= he creation of the
widget).

The prompt comes from the function :v= alue-to-external of the sexp
widget, which is called in the process of c= reating the widget.=C2=A0 The
:value-to-external function calls read wit= h the value of the widget,
like this: (read value)

It does that a= ssuming value is a string.=C2=A0 It does not want user input
(by reading= it from the minibuffer), it just wants to take the widget
value and ret= urn it in the "external" format.=C2=A0 The function
:value-to-= internal is the one that should print the value of the widget
to a strin= g.=C2=A0 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
widg= et-restricted-sexp-match.

So, why doesn't the value of the widge= t satisfy
widget-restricted-sexp-match, at the widget creation stage?=C2= =A0 That's
because :match-alternatives is '(functionp), and the = default value of
the widget is nil.=C2=A0 Because of that, widget-restri= cted-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 s= ays:
=E2=80=98:value DEFAULT=E2=80=99
=C2=A0 =C2=A0 =C2=A0Provide a d= efault value.

=C2=A0 =C2=A0 =C2=A0If =E2=80=98nil=E2=80=99 is not a = valid value for the alternative, then it is
=C2=A0 =C2=A0 =C2=A0essentia= l to specify a valid default with =E2=80=98:value=E2=80=99.

So the d= efcustom provided is lacking the essential :value DEFAULT thing.
If we c= ompare the behavior with the following defcustom:
(defcustom bar
=C2= =A0 `(ignore)
=C2=A0 "..."
=C2=A0 :type
=C2=A0 '(rep= eat (restricted-sexp :match-alternatives (functionp)
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 :value ignore))
=C2=A0 :group 'emacs)

And in the custo= mization buffer we click the INS button, then there's no
prompt: cre= ation of the widget happens with no problem.

Another defcustom, that= makes nil a valid value:
(defcustom bar
=C2=A0 `(ignore)
=C2=A0 &= quot;..."
=C2=A0 :type
=C2=A0 '(repeat (restricted-sexp :mat= ch-alternatives (functionp null)))
=C2=A0 :group 'emacs)

Agai= n, 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.
--000000000000eb351705ae8fafdb--