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: Thu, 11 May 2023 22:08:20 +0800 Message-ID: References: <83ttwk6vq4.fsf@gnu.org> Reply-To: Ruijie Yu Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2110"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.11.3; emacs 30.0.50 Cc: Eli Zaretskii , drew.adams@oracle.com To: 63410@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu May 11 16:09: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 1px6yv-0000JI-78 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 11 May 2023 16:09:21 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1px6yi-0007Fu-UL; Thu, 11 May 2023 10:09:09 -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 1px6yh-0007EW-OT for bug-gnu-emacs@gnu.org; Thu, 11 May 2023 10:09:07 -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 1px6yc-0003qp-EP for bug-gnu-emacs@gnu.org; Thu, 11 May 2023 10:09:07 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1px6yc-0001vI-1x for bug-gnu-emacs@gnu.org; Thu, 11 May 2023 10:09: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: Thu, 11 May 2023 14:09: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.16838141247362 (code B ref 63410); Thu, 11 May 2023 14:09:02 +0000 Original-Received: (at 63410) by debbugs.gnu.org; 11 May 2023 14:08:44 +0000 Original-Received: from localhost ([127.0.0.1]:53091 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1px6yJ-0001uf-MX for submit@debbugs.gnu.org; Thu, 11 May 2023 10:08:44 -0400 Original-Received: from netyu.xyz ([152.44.41.246]:44034 helo=mail.netyu.xyz) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1px6yE-0001uR-DA for 63410@debbugs.gnu.org; Thu, 11 May 2023 10:08:42 -0400 Original-Received: from fw.net.yu.netyu.xyz ( [222.248.4.98]) by netyu.xyz (OpenSMTPD) with ESMTPSA id b44ad50d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 11 May 2023 14:08:36 +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:261573 Archived-At: --=-=-= Content-Type: text/plain Ruijie Yu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" writes: > In that case, I had my semi-parallel second proposal: provide a command > that checks for a group of variables and see if types of all variables > within the group (or its subgroups) are correct. Regarding the second proposal: I have quickly hacked together a functional example of type checking, see the attachment. If we think this should be integrated into Emacs, I can make some minor edits and propose a patch. In that case, I would probably put the functions somewhere in cus-edit.el or custom.el. Note that at the moment it depends on the internal function `custom--standard-value', which is a one-line function accessing a property of the symbol. --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=cfg-check-defcustom.el ;;; cfg-check-defcustom.el --- Ensure type-strictness of defcustom ;;; Commentary: ;;; Code: (autoload 'customize-read-group "cus-edit") (autoload 'custom-variable-prompt "cus-edit") (defun ccd (variable) "Check the standard value of VARIABLE is of the correct type." (interactive (custom-variable-prompt)) (custom-load-symbol variable) (when-let ((type (get variable 'custom-type))) (let ((value (custom--standard-value variable))) (unless (widget-apply (widget-convert type) :match value) (warn "Type mismatch on `%s': value `%S'; type %s" variable value type))))) (defun ccd--vars-in-group (group &optional recursive) "Return a list of all variable symbols contained in GROUP. When RECURSIVE is non-nil, the list contains variables in subgroups recursively." (when-let (((symbolp group)) (gp (get group 'custom-group))) (let* ((filter (lambda (s) (mapcar #'car (seq-filter (lambda (c) (eq s (nth 1 c))) gp)))) (child (funcall filter 'custom-variable)) (subgroup (and recursive (funcall filter 'custom-group)))) (nconc child (mapcan #'ccd--vars-in-group-r subgroup))))) (defun ccd--vars-in-group-r (group) "Shorthand for \\(cfg-check-defcustom--vars-in-group GROUP t)." (ccd--vars-in-group group t)) (defun ccd-group (group &optional recursive) "Check all variables within GROUP. When RECURSIVE is non-nil, check the group recursively. See also `cfg-check-defcustom'." (interactive (list (customize-read-group) current-prefix-arg)) (mapc #'ccd (ccd--vars-in-group (intern group) recursive))) (provide 'cfg-check-defcustom) ;;; cfg-check-defcustom.el ends here. ;; Local Variables: ;; read-symbol-shorthands: (("ccd" . "cfg-check-defcustom")) ;; End: --=-=-= Content-Type: text/plain Also, note that I added the symbol into the warning text because the goal of this command is to mass-check an entire group, whereas `setopt' did not mention the variable symbol name. Not sure if `setopt' should show the symbol in trouble, but I understand if we don't want to do that. -- Best, RY --=-=-=--