From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.bugs Subject: bug#25152: 25.1; Customize: errors for `restricted-sexp' in `repeat' Date: Sat, 5 Sep 2020 07:46:42 -0700 (PDT) Message-ID: <45d48716-1ac9-4cb3-9c64-042dddee4e77@default> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20340"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 25152@debbugs.gnu.org To: Mauro Aranda Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Sep 05 16:49: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 1kEZV7-00058Q-9c for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 05 Sep 2020 16:49:09 +0200 Original-Received: from localhost ([::1]:53770 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kEZV6-0004O7-Ac for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 05 Sep 2020 10:49:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37602) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kEZV0-0004M1-3M for bug-gnu-emacs@gnu.org; Sat, 05 Sep 2020 10:49:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:60476) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kEZUz-0006aL-Pd for bug-gnu-emacs@gnu.org; Sat, 05 Sep 2020 10:49:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kEZUz-0001Lr-NL for bug-gnu-emacs@gnu.org; Sat, 05 Sep 2020 10:49:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Drew Adams Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 05 Sep 2020 14:49:01 +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.15993173325180 (code B ref 25152); Sat, 05 Sep 2020 14:49:01 +0000 Original-Received: (at 25152) by debbugs.gnu.org; 5 Sep 2020 14:48:52 +0000 Original-Received: from localhost ([127.0.0.1]:43789 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kEZUq-0001LU-CX for submit@debbugs.gnu.org; Sat, 05 Sep 2020 10:48:52 -0400 Original-Received: from userp2120.oracle.com ([156.151.31.85]:59024) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kEZUp-0001LH-Ew for 25152@debbugs.gnu.org; Sat, 05 Sep 2020 10:48:51 -0400 Original-Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 085EjxC3113587; Sat, 5 Sep 2020 14:48:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : sender : to : cc : subject : references : in-reply-to : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=5o2eI20+c3E/nUp9BjzJ2acsmbNrkZQWUUKE+G8ejYg=; b=Qfe/5iEY5KLPGoGKL/uxmJTsK7bNRoLZYm9jbo0aLlMH7LI8Pp93kl2pU0X+nFtNYH49 jiO1vdg21vddpIoceznO2I0LYp9nXxRp4LO8zNx7ne6az+Pnj2j5byUKhTN9l/QBYN+7 vxmPXzcD4WFZTfu4CjPHMFZbqHx8sqwKQNj0ixY5DVfpvOOaKHVDmdJQxYrC5kc7Pwox ywKjwtoivFOpusMDsblswWbcucYZ5FqWejXpLTxmYa2nM/HmzGh24WjtXbSNy7MgKJAF wp896E2beKtGr46sFkuhBNaMZou1QWR9oY29Xs+3zc3RWZQLokoZlLJ16LebdhpIqNVx Cw== Original-Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 33c3amh8a5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 05 Sep 2020 14:48:45 +0000 Original-Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 085EjYNU009232; Sat, 5 Sep 2020 14:46:44 GMT Original-Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3030.oracle.com with ESMTP id 33c0q93vjt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 05 Sep 2020 14:46:44 +0000 Original-Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 085EkhE7006424; Sat, 5 Sep 2020 14:46:43 GMT In-Reply-To: X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 16.0.5044.0 (x86)] X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9734 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 adultscore=0 bulkscore=0 mlxscore=0 phishscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009050144 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9735 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 priorityscore=1501 clxscore=1011 bulkscore=0 malwarescore=0 lowpriorityscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 mlxscore=0 impostorscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009050142 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:187252 Archived-At: >> emacs -Q >> >> (defcustom bar >> =C2=A0 `(ignore) >> =C2=A0 "..." >> =C2=A0 :type >> =C2=A0 '(repeat (restricted-sexp :match-alternatives (functionp))) >> =C2=A0 :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.=C2=A0 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.=C2=A0 It does not want user inpu= t > (by reading it from the minibuffer), it just wants to take the widget > value and return 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 string.=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 > widget-restricted-sexp-match. > > So, why doesn't the value of the widget 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-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 >=C2=A0 =C2=A0 =C2=A0Provide a default 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=A0essential to specify a valid default with =E2=80=98:va= lue=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 >=C2=A0 `(ignore) >=C2=A0 "..." >=C2=A0 :type >=C2=A0 '(repeat (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 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 >=C2=A0 `(ignore) >=C2=A0 "..." >=C2=A0 :type >=C2=A0 '(repeat (restricted-sexp :match-alternatives (functionp null))) >=C2=A0 :group 'emacs)=20 > > 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.