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: Fri, 23 Oct 2020 09:59:45 -0300 Message-ID: References: <45d48716-1ac9-4cb3-9c64-042dddee4e77@default> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="000000000000668eb605b2562823" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19677"; 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 Fri Oct 23 15:02:32 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 1kVwiF-00053X-Ha for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 23 Oct 2020 15:02:31 +0200 Original-Received: from localhost ([::1]:51344 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVwiE-0001Gc-J6 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 23 Oct 2020 09:02:30 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48914) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVwgp-0000L8-A5 for bug-gnu-emacs@gnu.org; Fri, 23 Oct 2020 09:01:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:44743) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kVwgo-0006zI-2j for bug-gnu-emacs@gnu.org; Fri, 23 Oct 2020 09:01:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kVwgo-0003PM-2Z for bug-gnu-emacs@gnu.org; Fri, 23 Oct 2020 09:01:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mauro Aranda Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 23 Oct 2020 13:01: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.160345800712943 (code B ref 25152); Fri, 23 Oct 2020 13:01:02 +0000 Original-Received: (at 25152) by debbugs.gnu.org; 23 Oct 2020 13:00:07 +0000 Original-Received: from localhost ([127.0.0.1]:56285 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kVwfu-0003Mg-W1 for submit@debbugs.gnu.org; Fri, 23 Oct 2020 09:00:07 -0400 Original-Received: from mail-wm1-f49.google.com ([209.85.128.49]:55228) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kVwfs-0003La-5i for 25152@debbugs.gnu.org; Fri, 23 Oct 2020 09:00:06 -0400 Original-Received: by mail-wm1-f49.google.com with SMTP id w23so272941wmi.4 for <25152@debbugs.gnu.org>; Fri, 23 Oct 2020 06:00:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=128fMBF6nX673UWJejJnQcohczcf3GwYMc5rq8BoaII=; b=hdBLlGPBU/eJhu7Wh/sZH3zSwD3Yg8HxoQWq9W6BQQdGQQVUHCz4Dr3aoMq9uY784x txz5Kp0TP1eh4iY87FMDqZ1t06TdZRxAC4bcHN9MW1dK8P4xYY28ClnZRpHhM622FDes pvzQfSmRAcll26AEQDssvuWTE3C31J3sMvJa6BZ2QarL/HdOKHYwhA84ZAx1tBwm6Ecq rOS1rxFQIOnoK+sWTlC390Jy2r2/cNASVcPrrIv379NgF6kVPY8h2/IdN6z6bqXz4n+h 9bl/C43lEnKKai/KFuq9MNw0DqUY58WaSV3eqDbQgVqmw6KoRCS5R33KnUu9Z4jKeJfO Jjpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=128fMBF6nX673UWJejJnQcohczcf3GwYMc5rq8BoaII=; b=ZhZ3qq+LjV9m7LKnTbHJwdnl9FvvOn/7BKhJdKXZm33p03GNTZ+b1o9AZNehbyn41X 79388FNmGfBow6LQw8eBqMJveOt7cAPBjjYUdDZf7BCM6Td7EVmowRBoKiDRX2jQpGYv i7S1o5OeUwhmuVTkMP63lKK4xFJVpOma7I4e4ClcMOUq6SQ0tOCOO0/qI4Zc23jmQ+V6 B4QAS+iiNoAknm7ryeGMJcju+wbx30gLqKb2mjzs53/B1/LOX7dTQIitis/oS5MhvHaE O2dNace9ebZI0KDN6QGl78fmDiEQdtoyjEeGQDVxOZ+R/RfZ00M3Hkih7ugPME7ExsBI iRjQ== X-Gm-Message-State: AOAM531xX12MZXGwwDaWgUccrKV4/OrMPYrqCJhndg1lK2HIQ5p4GhhL T9VGMDGhTFnql6DXOeHDki+sVQdg2Gp38J7+Cig= X-Google-Smtp-Source: ABdhPJzMUZaVR54o1M2Fsu+zEhArHmKJ1ZqXWwGNCoYf1itt1DHB1thJAg/Vzliigqk8FbCTJwbSrTsdIu9MluGo5vA= X-Received: by 2002:a1c:dc43:: with SMTP id t64mr2265372wmg.6.1603457998285; Fri, 23 Oct 2020 05:59:58 -0700 (PDT) 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" Xref: news.gmane.io gmane.emacs.bugs:191372 Archived-At: --000000000000668eb605b2562823 Content-Type: multipart/alternative; boundary="000000000000668eb405b2562821" --000000000000668eb405b2562821 Content-Type: text/plain; charset="UTF-8" Mauro Aranda writes: > Drew Adams writes: > >>> 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. > > I think it makes sense, but I'm not sure where would be the right place > to do it. Coming back to this, perhaps a good place to warn about a bad default value is where we find it for the first time. So I attach a patch that makes the restricted-sexp widget warn (but not error out) if the internal value is not a string. So, for the defcustom in the recipe: (defcustom bar `(ignore) "..." :type '(repeat (restricted-sexp :match-alternatives (functionp))) :group 'emacs) When the user clicks the INS button, the following warning pops up: Warning (widget-bad-default-value): A widget of type restricted-sexp has a bad default value. value: nil match function: widget-restricted-sexp-match match-alternatives: (functionp) which I hope conveys good enough information to fix the mistake. I made it just a warning, because this mistake doesn't always result in a messed up buffer. But it can be changed to an error, of course. --000000000000668eb405b2562821 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Mauro Aranda <maurooaranda@gmail.com> writes:

> Drew Adams <drew.adams@oracle.com> writes:
= >
>>> To sum it up, the prompt is an unfortunate mistake, an= d 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.= =C2=A0 Makes sense.
>>
>> Can we somehow help users by ra= ising an error when they
>> do this?=C2=A0 Seems like a simple mis= take to make.
>
> I think it makes sense, but I'm not sure = where would be the right place
> to do it.

Coming back to this= , perhaps a good place to warn about a bad default
value is where we fin= d it for the first time.=C2=A0 So I attach a patch that
makes the restri= cted-sexp widget warn (but not error out) if the
internal value is = not a string.

So, for the defcustom in the recipe:=
(defcustom bar
=C2=A0 `(ignore)
=C2=A0 "..."
=C2=A0 = :type
=C2=A0 '(repeat (restricted-sexp :match-alternatives (function= p)))
=C2=A0 :group 'emacs)

When the user clicks the INS butto= n, the following warning pops up:
Warning (widget-bad-default-value): A widget of type restricted-sexp has a bad default value.
value: nilmatch function: widget-restricted-sexp-match
match-alternatives: (func= tionp)

which I hope conveys good enough informatio= n to fix the mistake.

I made it just a warning, because this mista= ke doesn't always result in
a messed up buffer.=C2=A0 But it can be = changed to an error, of course.
--000000000000668eb405b2562821-- --000000000000668eb605b2562823 Content-Type: text/x-patch; charset="US-ASCII"; name="0001-Warn-about-a-bad-default-value-in-restricted-sexp-wi.patch" Content-Disposition: attachment; filename="0001-Warn-about-a-bad-default-value-in-restricted-sexp-wi.patch" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_kgm9g4r40 RnJvbSBkY2YxYTdhYzNmNGZlMmU3ZTZkYTgwZDBiMjE5NDc5YzhiNDU0ODU4IE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBNYXVybyBBcmFuZGEgPG1hdXJvb2FyYW5kYUBnbWFpbC5jb20+ CkRhdGU6IEZyaSwgMjMgT2N0IDIwMjAgMDk6MTc6MDQgLTAzMDAKU3ViamVjdDogW1BBVENIXSBX YXJuIGFib3V0IGEgYmFkIGRlZmF1bHQgdmFsdWUgaW4gcmVzdHJpY3RlZC1zZXhwIHdpZGdldAoK KiBsaXNwL3dpZC1lZGl0LmVsIChyZXN0cmljdGVkLXNleHAgd2lkZ2V0KTogTmV3IDp2YWx1ZS10 by1leHRlcm5hbApmdW5jdGlvbi4gIElmIHZhbHVlIGlzIG5vdCBpbiB0aGUgaW50ZXJuYWwgZm9y bWF0LCB0aGVuIHdlIG1pZ2h0IGJlCmRlYWxpbmcgd2l0aCBhIGJhZCBk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SBiYWQgZGVmYXVsdAorICAgICAgICAgICAgICAgICAgICAgICA7OyB2 YWx1ZSwgd2UgbWlnaHQgZW5kIHVwIGNhbGxpbmcgcmVhZCB3aXRoIGEgbmlsCisgICAgICAgICAg ICAgICAgICAgICAgIDs7IGFyZ3VtZW50LCByZXN1bHRpbmcgaW4gYW4gdW5kZXNpcmVkIHByb21w dCB0byB0aGUKKyAgICAgICAgICAgICAgICAgICAgICAgOzsgdXNlci4gIEEgYmFkIGRlZmF1bHQg dmFsdWUgaXMgbm90IGFsd2F5cyBhIGJpZworICAgICAgICAgICAgICAgICAgICAgICA7OyBwcm9i bGVtLCBidXQgbWlnaHQgZW5kIHVwIGluIGEgbWVzc2VkIHVwIGJ1ZmZlciwKKyAgICAgICAgICAg ICAgICAgICAgICAgOzsgc28gZGlzcGxheSBhIHdhcm5pbmcgaGVyZS4gIChCdWcjMjUxNTIpCisg ICAgICAgICAgICAgICAgICAgICAgICh1bmxlc3MgKHN0cmluZ3AgdmFsdWUpCisgICAgICAgICAg ICAgICAgICAgICAgICAgKGRpc3BsYXktd2FybmluZworICAgICAgICAgICAgICAgICAgICAgICAg ICAnd2lkZ2V0LWJhZC1kZWZhdWx0LXZhbHVlCisgICAgICAgICAgICAgICAgICAgICAgICAgIChm b3JtYXQtbWVzc2FnZQorICAgICAgICAgICAgICAgICAgICAgICAgICAgIlxuQSB3aWRnZXQgb2Yg dHlwZSAlUyBoYXMgYSBiYWQgZGVmYXVsdCB2YWx1ZS4KK3ZhbHVlOiAlUworbWF0Y2ggZnVuY3Rp b246ICVTCittYXRjaC1hbHRlcm5hdGl2ZXM6ICVTIgorICAgICAgICAgICAgICAgICAgICAgICAg ICAgKHdpZGdldC10eXBlIHdpZGdldCkKKyAgICAgICAgICAgICAgICAgICAgICAgICAgIHZhbHVl CisgICAgICAgICAgICAgICAgICAgICAgICAgICAod2lkZ2V0LWdldCB3aWRnZXQgOm1hdGNoKQor ICAgICAgICAgICAgICAgICAgICAgICAgICAgKHdpZGdldC1nZXQgd2lkZ2V0IDptYXRjaC1hbHRl cm5hdGl2ZXMpKQorICAgICAgICAgICAgICAgICAgICAgICAgICA6d2FybmluZykpCisgICAgICAg ICAgICAgICAgICAgICAgIChyZWFkIHZhbHVlKSkpCiAKIChkZWZ1biB3aWRnZXQtcmVzdHJpY3Rl ZC1zZXhwLW1hdGNoICh3aWRnZXQgdmFsdWUpCiAgIChsZXQgKChhbHRlcm5hdGl2ZXMgKHdpZGdl dC1nZXQgd2lkZ2V0IDptYXRjaC1hbHRlcm5hdGl2ZXMpKQotLSAKMi4yOC4wCgo= --000000000000668eb605b2562823--