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#59937: 28.2; Bad defcustom behavior Date: Sun, 11 Dec 2022 08:08:50 -0300 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17391"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Cc: "59937@debbugs.gnu.org" <59937@debbugs.gnu.org> To: Drew Adams Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Dec 11 12:10:23 2022 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 1p4KDu-0004M6-N4 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 11 Dec 2022 12:10:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p4KDd-0007NK-6w; Sun, 11 Dec 2022 06:10:05 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p4KDb-0007N8-EJ for bug-gnu-emacs@gnu.org; Sun, 11 Dec 2022 06:10:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p4KDb-0005SL-0K for bug-gnu-emacs@gnu.org; Sun, 11 Dec 2022 06:10:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p4KDa-0000VR-GE for bug-gnu-emacs@gnu.org; Sun, 11 Dec 2022 06:10:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Mauro Aranda Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 11 Dec 2022 11:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59937 X-GNU-PR-Package: emacs Original-Received: via spool by 59937-submit@debbugs.gnu.org id=B59937.16707569441917 (code B ref 59937); Sun, 11 Dec 2022 11:10:02 +0000 Original-Received: (at 59937) by debbugs.gnu.org; 11 Dec 2022 11:09:04 +0000 Original-Received: from localhost ([127.0.0.1]:46333 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p4KCd-0000Ur-MU for submit@debbugs.gnu.org; Sun, 11 Dec 2022 06:09:04 -0500 Original-Received: from mail-oa1-f47.google.com ([209.85.160.47]:36566) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p4KCa-0000UU-CH for 59937@debbugs.gnu.org; Sun, 11 Dec 2022 06:09:02 -0500 Original-Received: by mail-oa1-f47.google.com with SMTP id 586e51a60fabf-14449b7814bso5288980fac.3 for <59937@debbugs.gnu.org>; Sun, 11 Dec 2022 03:09:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=QrZC8Qlgv3BJMqLYNThItRl6eXASEUZWGLS7UckmGVI=; b=WxifpjzIJvBa2IBiMfTkChGBgTEvf1bBIjupWu95br+6xnO1FqoTkKMlABij5ppovY W/GiBdUYqNcq5ci8sU6XCXXzrILy6kvnUF6EPbX8JL+BQ6kOtP+JLxjJO0/8Yh+mCjRB 4ttobNSoqWBnotfNz7R/BrJHX+0bNPMOoWMOLrnfA0udOG3ozhDP+ejqCsbiCl4pB1p8 puDWCgIPSgf/g6GAjtsimHTBLfXMzN0ZthKuvXsBYKlbY/GwJbQid6J32TVRZrapmW2m SUkZeMDm0XbeTU//4hcyE5xwRh7g8tiQ9Y0GJcB432OW80YpsnMTJ4AI8BE3J04B/99c NsLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QrZC8Qlgv3BJMqLYNThItRl6eXASEUZWGLS7UckmGVI=; b=L/GCEMZ8HxcqihOho+pBUaty9C5Kjikm8URzMKSAyvUke2FfyzOsfdGW3gTyJ+u0kW 5Cf0hbOjf14Foe8CyT53NONM2h1CMGHTTyKExYLfDa+lTgbZWmcOf/d4zI2lohIXlBS9 UoXqReyLh1tuSEdwCb6FA2m+bjWfY0hxhX7lz7avzHkNk0kYP2sae/ku9UoQ+yYDA23g tvIg8WuR4tcRoPSjLsXm7oySxC6fBDP6gdHz1uW96ovTKhTiG2XgYcb5Xa449GGdF81o l5+FYNguS876XirldbgPo7lgdmNXHHRYa/rDDsdw2cyruAwrCgUWyISLbkYN5tnYR3A0 TLNQ== X-Gm-Message-State: ANoB5pnPxonMS2/DrL0Eu8wDVl4xloa5gCPPvFNptS6jg2wnZfR0QGR7 plRMfoIw1uARiCLAtrR9Pds= X-Google-Smtp-Source: AA0mqf5HXJ6gALjyl6oc9KfvMaOOzxz5HOcDeZcu2Pm08xdV3xB/kA0VFA1g87UfbzfwuMX9gqUITw== X-Received: by 2002:a05:6870:9123:b0:144:d2bd:f6ac with SMTP id o35-20020a056870912300b00144d2bdf6acmr6913909oae.43.1670756934497; Sun, 11 Dec 2022 03:08:54 -0800 (PST) Original-Received: from [192.168.0.234] ([181.228.28.240]) by smtp.gmail.com with ESMTPSA id e14-20020a056870d10e00b00144e18d8525sm3565652oac.25.2022.12.11.03.08.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 11 Dec 2022 03:08:53 -0800 (PST) Content-Language: en-US In-Reply-To: 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:250595 Archived-At: Drew Adams writes: >> The moment you add a match alternative that won't match the default >> value of a restricted-sexp widget (which is nil), then you should change >> the default value for the restricted-sexp widget. > > I don't even see how/where that widget gets a default > value of nil.  I see `:match-alternatives '(functionp)', > and I see `:value 'ignore'.  I admit that I don't really > understand the code that implements `restricted-sexp'. I think you're looking at the function widget, not at the restricted-sexp widget. M-x widget-browse RET restricted-sexp shows some information about the restricted-sexp widget.  Since there's no :value in that buffer, to find out what could it be you have to navigate to the parent widget, the sexp widget.  That buffer will show: :value nil somewhere, saying the default value for this and derived widgets is nil, unless the code overrides it (by passing a different :value). > (And I'd think that I shouldn't really need to understand it.) I agree.  Below I'll try to focus on the behavior and not on the implementation. >>  > (defcustom myvar () >>  >   "..." >>  >   :group 'emacs >>  >   :type '(alist :key-type (string :tag "Alist key (string):") >>  >                 :value-type >>  >                 (plist :key-type >>  >                        (restricted-sexp :match-alternatives (keywordp) >>  >                                         :tag "Plist key (keyword)") >>  >                        :options (:x :y :z) >>  >                        :value-type (repeat string)))) >>  > >>  > In this case the default value is nil, but the defcustom also >>  > specifies the type of plist values as keywordp.  I think this >>  > definition should work fine. >> >> You're looking at a different default value. >> The warning comes from Widget, and says that the default >> value for the restricted-sexp widget is not >> correct.  It's not talking about the default value >> for the user option. > > Note that in bug #25152 I expressed my disagreement > with closing the bug - IMO, it's not fixed. > > I don't understand how a defcustom should be bothering > with (working around) a default value for the widget > that's defined for `restricted-sexp'. > > The default value of the option is the only default > value that should matter, no?  If the initial (i.e. > default) value of the option is nil, then the alist > is nil, which means it has no elements, which means > there are no plists. Once again, I think you're focusing on a different default value. The warning shows up when trying to insert a new element, right?  At that moment, the user asked for a widget to edit, and like every other widget, it gets created with a default value.  That value should be a valid one. If it helps, take these two examples: (defcustom foo nil   "..."   :type '(repeat (function))) Click INS and you'll see a new editable field with the value ignore. That's the default value for the function widget.  You can check it with M-x widget-browse RET function Now take a look at this: (defcustom foo nil   "..."   :type '(repeat (restricted-sexp                   :match-alternatives (functionp)))) Click INS and you'll get the warning.  The default value for the restricted-sexp widget is nil, as I said, and of course: (functionp nil) => nil > So it's impossible to even speak about applying some > condition to a plist element.  Such a test (which is > what `restricted-sexp' defines) is never - can never > be, logically - applied to any plist element because > no such elements exist in this default case. > To me, this is just, well, a bug.  A bug in the > definition of widget `restricted-sexp', I guess (?). > > But a priori I'd think the bug is not in the definition > of `restricted-sexp' but in the definition of anything > that uses it.  To me, widget `restricted-sexp' just > shouldn't apply at all in a context such as described in > this bug: there's _nothing to check_ with a predicate > that's used to check each list element - there are no > elements. The elements begin to exist the moment the user asks to insert a new element with INS.  I think this is as it should be.  The restricted-sexp widget works fine given a valid default value according to the :match-alternatives or :match passed when defining it. As I said in Bug#25152, 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’. If you're asking it to be valid only with keywords, then the definition should specify something that: (keywordp SOMETHING) => t > To me, `null' as a predicate doesn't apply either. > This isn't about testing whether some plist element > is nil.  Nothing about the plist should be checked, > because there's no plist!  There's certainly not a > plist with nil elements - now should predicate `null' > help here (but it does!)? As I said, when the user clicks INS, then there is a plist: the one being edited. > And I can't tell whether you think there is a bug > or not.  The duplicate bugs were closed (by Lars), > after you tried to improve things by providing a > warning.  Though I suppose it was good to provide > the warning, I don't see that the bug is fixed at all. I do think the warning should be there.  The defcustom writer can see it when testing the defcustom, or a user can report it to the developer. With regards to the restricted-sexp widget implementation, I do think it is a bug, but I didn't see a safe way to fix it back then.  I'll try to take another look, but I'm no smarter than I was :-(. > And I'm (still) afraid that any user (including the > person writing the defcustom and testing it) won't > (1) understand what's going on and (2) be able to > figure out how to fix the `restricted-sexp' to work > around the problem.  Does always adding `null' take > care of it? If people think the warning message is not good enough, I'm certain someone can think of a way to improve it; I couldn't. > I just now tried the _two_ alternative workarounds > for `restricted-sexp' you showed in the context of > bug #25152: (1) add `:value ignore' or (2) add > predicate `null' to the list of predicates. > > In the case of the example in this bug (#59937) > it looks like #1 doesn't work - you get the same > warning etc.  But #2 works. Try to pass a valid default value for the restricted-sexp widget. If you're asking it to only match keywords, then any keyword does the trick. >> Examples 2-4 get the same warning once the user clicks the INS button. >> If you specify a valid default value for the restricted-sexp widget, >> then the warning is gone.  See also bugs #15689, #25152. > > Expecting a defcustom definer to understand this > and figure out what a "valid default value for > the restricted-sexp widget" might be, is a bridge > too far, IMO. I don't think so.  The defcustom definer is specifying the matching alternatives, he/she should be able to think of a valid default value. Maybe having some examples in the documentation could help here. I could write one if you and others think it could be helpful. > At my present, poor state of understanding this, > about all I could tell someone is to add `null' > as a predicate.  I couldn't explain why or how > that works.  I can't see how/why any of the > predicates would/should get called if the value > of the option is (). > > Anyway, I'm _grateful_ to you for pointing this > out (again), and for pointing to bugs #15689 and > #25152.  You're definitely the king of widgets, > and we're very lucky to have you involved.  Thx. Thanks, but I do not think I'm worthy of that title. > I am curious whether you think there's actually > a bug or not.  It's hard for me to believe that > we should expect _anyone_ defining a defcustom > (let alone anyone using Customize) to understand > the `restricted-sexp' widget, what it requires > wrt its "default value", and how to adjust a > defcustom to give it what it needs, to DTRT. I think a better behavior would be to avoid the prompting altogether (there should be no prompt at that moment, for starters).  But again, this situation arises when there is a bug on the defcustom :type, so I'd be happier if people can help with improving the warning message.