all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ruijie Yu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 63410@debbugs.gnu.org
Cc: Eli Zaretskii <eliz@gnu.org>, drew.adams@oracle.com
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	[thread overview]
Message-ID: <sdvh6sj7ygb.fsf@netyu.xyz> (raw)
In-Reply-To: <sdv7ctfa9ju.fsf@netyu.xyz>

[-- Attachment #1: Type: text/plain, Size: 776 bytes --]


Ruijie Yu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org> 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.


[-- Attachment #2: cfg-check-defcustom.el --]
[-- Type: text/plain, Size: 1827 bytes --]

;;; 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:

[-- Attachment #3: Type: text/plain, Size: 303 bytes --]


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

      reply	other threads:[~2023-05-11 14:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-10  5:22 bug#63410: 30.0.50; [FR] Optionally allow defcustom to check type for standard value Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-10 13:36 ` Drew Adams
2023-05-10 14:51   ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-10 15:40     ` Eli Zaretskii
2023-05-11  2:25       ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-11 14:08         ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sdvh6sj7ygb.fsf@netyu.xyz \
    --to=bug-gnu-emacs@gnu.org \
    --cc=63410@debbugs.gnu.org \
    --cc=drew.adams@oracle.com \
    --cc=eliz@gnu.org \
    --cc=ruijie@netyu.xyz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.