From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ruijie Yu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#63410: 30.0.50; [FR] Optionally allow defcustom to check type for standard value Date: Wed, 10 May 2023 22:51:14 +0800 Message-ID: References: Reply-To: Ruijie Yu Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18238"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.11.3; emacs 30.0.50 Cc: "63410@debbugs.gnu.org" <63410@debbugs.gnu.org> To: Drew Adams Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed May 10 16:52:21 2023 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 1pwlAy-0004UB-3f for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 10 May 2023 16:52:20 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pwlAj-00017N-3F; Wed, 10 May 2023 10:52:05 -0400 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 1pwlAh-00016l-62 for bug-gnu-emacs@gnu.org; Wed, 10 May 2023 10:52:03 -0400 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 1pwlAg-0006UP-VC for bug-gnu-emacs@gnu.org; Wed, 10 May 2023 10:52:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pwlAg-00008b-GL for bug-gnu-emacs@gnu.org; Wed, 10 May 2023 10:52:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ruijie Yu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 10 May 2023 14:52:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63410 X-GNU-PR-Package: emacs Original-Received: via spool by 63410-submit@debbugs.gnu.org id=B63410.1683730310503 (code B ref 63410); Wed, 10 May 2023 14:52:02 +0000 Original-Received: (at 63410) by debbugs.gnu.org; 10 May 2023 14:51:50 +0000 Original-Received: from localhost ([127.0.0.1]:48631 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pwlAU-000083-4u for submit@debbugs.gnu.org; Wed, 10 May 2023 10:51:50 -0400 Original-Received: from netyu.xyz ([152.44.41.246]:35240 helo=mail.netyu.xyz) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pwlAO-00007m-SB for 63410@debbugs.gnu.org; Wed, 10 May 2023 10:51:48 -0400 Original-Received: from fw.net.yu.netyu.xyz ( [222.248.4.98]) by netyu.xyz (OpenSMTPD) with ESMTPSA id dc9fa7be (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 10 May 2023 14:51:41 +0000 (UTC) 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:261505 Archived-At: Drew Adams writes: >> Similar to `setopt' introduced in 29, which warns when a variable gets >> assigned a value with an incorrect type, I hope `defcustom' can >> (optionally) check that the standard value of a customizable variable is >> correct. This would help external as well as internal package authors >> to catch errors on the types. > > Not sure I understand. Doesn't it do that already, > showing "mismatch" next to the default value if it > doesn't match the type definition? Yes, it does, but I think it is not "automated" enough, since you would have to go over the variables one at a time. My request is that Emacs should (optionally, maybe behind a defcustom, or configure, or cli flag, etc.) warn you warn a defcustom's standard value does not match its declared type. Since a similar warning is already in place for `setopt', I don't think it is farfetched to request `defcustom' to follow suit. Alternatively, or in addition to the above, maybe provide a function/command that checks types for a group+subgroups, or for all defined customizable variables. Again, this would help package authors to catch typing errors which would otherwise be quite difficult to catch. As I mentioned upthread, using `setopt' directly like the following snippet is unnecessarily expensive: it calls the :set function of a customizable variable, where the only thing we want is to check its type. ```emacs-lisp (defcustom expensive-var t :type 'string :set (lambda (n v) (dotimes (_ 424242) 'expensive) (set n v))) (setopt expensive-var expensive-var) ;; warns the user that the type is correct, but only after spending a ;; long time in the :set function ``` ----- Let me also explain the reason behind this request. I have encountered this scenario multiple times, where when I `setopt' something for a customizable variable according to its docs, I get a warning saying that the type is incorrect. Examples of this scenario include eshell, mu4e, and pyim. Seeing this type of warning would prompt me to examine the entire package in which the warning occurs. I would have to rgrep the entire package, and examine the types of each defcustom one-by-one, fixing all type errors along the way. When I encounter difficult-to-parse types I would do the `(setopt var var)' method to save time and brain cells. And here comes my feature request. We have the warning in `setopt'; we have some visual indication in the customization view; and I want to have one more: to know when a defcustom call defines a wrongly-typed standard value. -- Best, RY