From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.bugs Subject: bug#26910: 26.0.50; Enhancement request: type-checking in customize-set-variable Date: Sat, 13 May 2017 10:50:44 -0700 (PDT) Message-ID: <29d980da-ffd1-4b9c-9c6b-418de1d7db9f@default> References: <87h90pxg9a.fsf@hri.res.in> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1494697872 32709 195.159.176.226 (13 May 2017 17:51:12 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 13 May 2017 17:51:12 +0000 (UTC) To: "N. Raghavendra" , 26910@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat May 13 19:51:08 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d9bC7-0008Lz-M8 for geb-bug-gnu-emacs@m.gmane.org; Sat, 13 May 2017 19:51:07 +0200 Original-Received: from localhost ([::1]:58458 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d9bCB-0004Bh-LA for geb-bug-gnu-emacs@m.gmane.org; Sat, 13 May 2017 13:51:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58904) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d9bC5-0004BZ-GU for bug-gnu-emacs@gnu.org; Sat, 13 May 2017 13:51:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d9bC2-0001LR-Ae for bug-gnu-emacs@gnu.org; Sat, 13 May 2017 13:51:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:40549) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d9bC2-0001Kt-35 for bug-gnu-emacs@gnu.org; Sat, 13 May 2017 13:51:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1d9bC1-0006EH-RJ for bug-gnu-emacs@gnu.org; Sat, 13 May 2017 13:51: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, 13 May 2017 17:51:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 26910 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 26910-submit@debbugs.gnu.org id=B26910.149469785823936 (code B ref 26910); Sat, 13 May 2017 17:51:01 +0000 Original-Received: (at 26910) by debbugs.gnu.org; 13 May 2017 17:50:58 +0000 Original-Received: from localhost ([127.0.0.1]:43226 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d9bBy-0006Dz-8q for submit@debbugs.gnu.org; Sat, 13 May 2017 13:50:58 -0400 Original-Received: from userp1040.oracle.com ([156.151.31.81]:20923) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d9bBw-0006Dm-7B for 26910@debbugs.gnu.org; Sat, 13 May 2017 13:50:56 -0400 Original-Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v4DHomcU006082 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 13 May 2017 17:50:49 GMT Original-Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.13.8/8.14.4) with ESMTP id v4DHolNt006637 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 13 May 2017 17:50:48 GMT Original-Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id v4DHojLi032444; Sat, 13 May 2017 17:50:45 GMT In-Reply-To: <87h90pxg9a.fsf@hri.res.in> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 12.0.6767.5000 (x86)] X-Source-IP: aserv0021.oracle.com [141.146.126.233] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:132482 Archived-At: > I request the addition of an optional argument to > customize-set-variable, so that, e.g., > (customize-set-variable OPTION VALUE "This is a comment." t) > generates an error if VALUE is not of the type specified by > (defcustom OPTION ...), +1 Should it raise an error or just show a message and be ignored (not set the value)? How about having the new optional argument specify the behavior? Non-nil means type-check. The particular non-nil value: * `no-error' means if type-check fails just show a message (and do not set value). * any other non-nil value means raise an error (defun customize-set-variable (variable value &optional comment type-checki= ng) "... Non-nil optional arg TYPE-CHECKING means type-check VALUE and set the option value only if the type is appropriate. If TYPE-CHECKING is `no-error' then display a message about the incorrect type, but do not raise an error. Any other non-nil value means raise an error." ...) > and otherwise does everything that > (customize-set-variable OPTION VALUE "This is a comment.") > does now. Sounds good to me. > I also request a similar addition to `custom-set-variables'. I think this one is impossible, since `custom-set-variables' has only an &rest parameter: the args are not wrapped in an explicit list. We cannot add an optional parameter after the &rest parameter. In addition, `custom-set-variables' accepts an _expression_, without evaluating it (by default) for each variable. Unless the optional NOW element is present - in that case we could type-check the resulting value. This also means that we would need to provide such control separately for each variable passed to `custom-set-variables'. We could do that by allowing NOW to take one or more special non-nil values, to mean type-check after evaluating. Probably we would want to allow two such special type-checking values: If NOW is present and non-nil, then also evaluate EXP and set the default value for the SYMBOL to the value of EXP. If NOW is the symbol `type-check' then raise an error if the result of evaluating EXP is not of an appropriate type. If NOW is the symbol `type-check-no-error' then type-check the value of EXP but just show a message, instead of raising an error, when the value has an inappropriate type. What about also having another function, similar to `custom-set-variables', but which accepts an explicit list of (SYMBOL EXP [NOW [REQUEST [COMMENT]]]) entries plus an optional TYPE-CHECKING arg that has the effect of providing a default type-checking behavior for all entries that have non-nil NOW. Without non-nil arg TYPE-CHECKING it would behave just like (apply 'custom-set-variables VARLIST), where VARLIST is the explicit list of variable specs. Maybe something like this: (defun custom-set-varlist (varlist &optional type-checking) "Invoke `custom-set-variables' on the settings in list VARLIST. Each such setting has the form of an argument acceptable to `custom-set-variables'. Non-nil optional arg TYPE-CHECKING means type-check each VARLIST entry that has a non-nil NOW element, and set the option value only if the type is appropriate. The value of TYPE-CHECKING determines the default type-checking behavior: a value of `no-error' means display messages about the incorrect types, but do not raise an error. Any other non-nil value means raise an error. The default type-checking behavior can be overridden for any given variable by its NOW element. If NOW is `type-check' or `type-check-no-error' then it overrides the value of arg TYPE-CHECKING for that variable. If NOW is any other non-nil value then the value of TYPE-CHECKING determines the behavior." ...)