mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-26 23:31:55 -08:00
Warn about quoted symbols in defcustom choice/other forms
* lisp/emacs-lisp/bytecomp.el (byte-compile--suspicious-defcustom-choice): New function (bug#16271). (byte-compile-nogroup-warn): Use it to warn about forms like (choice (const :tag "foo" 'bar)).
This commit is contained in:
parent
5a12148503
commit
231cf5ee2b
3 changed files with 47 additions and 4 deletions
13
etc/NEWS
13
etc/NEWS
|
|
@ -1767,6 +1767,19 @@ functions.
|
||||||
|
|
||||||
* Lisp Changes in Emacs 29.1
|
* Lisp Changes in Emacs 29.1
|
||||||
|
|
||||||
|
** Byte compilation
|
||||||
|
|
||||||
|
---
|
||||||
|
*** Byte compilation will now warn about some malformed 'defcustom' types.
|
||||||
|
It's very common to write 'defcustom' types on the form:
|
||||||
|
|
||||||
|
:type '(choice (const :tag "foo" 'bar))
|
||||||
|
|
||||||
|
I.e., double-quoting the 'bar', which is almost never the correct
|
||||||
|
value. The byte compiler will now issue a warning if it encounters
|
||||||
|
these forms.
|
||||||
|
|
||||||
|
|
||||||
+++
|
+++
|
||||||
*** 'restore-buffer-modified-p' can now alter buffer auto-save state.
|
*** 'restore-buffer-modified-p' can now alter buffer auto-save state.
|
||||||
With a FLAG value of 'autosaved', it will mark the buffer as having
|
With a FLAG value of 'autosaved', it will mark the buffer as having
|
||||||
|
|
|
||||||
|
|
@ -1562,15 +1562,39 @@ extra args."
|
||||||
(dolist (elt '(format message error))
|
(dolist (elt '(format message error))
|
||||||
(put elt 'byte-compile-format-like t))
|
(put elt 'byte-compile-format-like t))
|
||||||
|
|
||||||
|
(defun byte-compile--suspicious-defcustom-choice (type)
|
||||||
|
"Say whether defcustom TYPE looks odd."
|
||||||
|
;; Check whether there's anything like (choice (const :tag "foo" ;; 'bar)).
|
||||||
|
;; We don't actually follow the syntax for defcustom types, but this
|
||||||
|
;; should be good enough.
|
||||||
|
(catch 'found
|
||||||
|
(if (and (consp type)
|
||||||
|
(proper-list-p type))
|
||||||
|
(if (memq (car type) '(const other))
|
||||||
|
(when (assq 'quote type)
|
||||||
|
(throw 'found t))
|
||||||
|
(when (memq t (mapcar #'byte-compile--suspicious-defcustom-choice
|
||||||
|
type))
|
||||||
|
(throw 'found t)))
|
||||||
|
nil)))
|
||||||
|
|
||||||
;; Warn if a custom definition fails to specify :group, or :type.
|
;; Warn if a custom definition fails to specify :group, or :type.
|
||||||
(defun byte-compile-nogroup-warn (form)
|
(defun byte-compile-nogroup-warn (form)
|
||||||
(let ((keyword-args (cdr (cdr (cdr (cdr form)))))
|
(let ((keyword-args (cdr (cdr (cdr (cdr form)))))
|
||||||
(name (cadr form)))
|
(name (cadr form)))
|
||||||
(when (eq (car-safe name) 'quote)
|
(when (eq (car-safe name) 'quote)
|
||||||
(or (not (eq (car form) 'custom-declare-variable))
|
(when (eq (car form) 'custom-declare-variable)
|
||||||
(plist-get keyword-args :type)
|
(let ((type (plist-get keyword-args :type)))
|
||||||
(byte-compile-warn-x (cadr name)
|
(cond
|
||||||
"defcustom for `%s' fails to specify type" (cadr name)))
|
((not type)
|
||||||
|
(byte-compile-warn-x (cadr name)
|
||||||
|
"defcustom for `%s' fails to specify type"
|
||||||
|
(cadr name)))
|
||||||
|
((byte-compile--suspicious-defcustom-choice type)
|
||||||
|
(byte-compile-warn-x
|
||||||
|
(cadr name)
|
||||||
|
"defcustom for `%s' has syntactically odd type `%s'"
|
||||||
|
(cadr name) type)))))
|
||||||
(if (and (memq (car form) '(custom-declare-face custom-declare-variable))
|
(if (and (memq (car form) '(custom-declare-face custom-declare-variable))
|
||||||
byte-compile-current-group)
|
byte-compile-current-group)
|
||||||
;; The group will be provided implicitly.
|
;; The group will be provided implicitly.
|
||||||
|
|
|
||||||
|
|
@ -1538,6 +1538,12 @@ EXPECTED-POINT BINDINGS (MODES \\='\\='(ruby-mode js-mode python-mode)) \
|
||||||
(TEST-IN-COMMENTS t) (TEST-IN-STRINGS t) (TEST-IN-CODE t) \
|
(TEST-IN-COMMENTS t) (TEST-IN-STRINGS t) (TEST-IN-CODE t) \
|
||||||
(FIXTURE-FN \\='#\\='electric-pair-mode))" fill-column)))
|
(FIXTURE-FN \\='#\\='electric-pair-mode))" fill-column)))
|
||||||
|
|
||||||
|
(defun test-bytecomp-defgroup-choice ()
|
||||||
|
(should-not (byte-compile--suspicious-defcustom-choice 'integer))
|
||||||
|
(should-not (byte-compile--suspicious-defcustom-choice
|
||||||
|
'(choice (const :tag "foo" bar))))
|
||||||
|
(should (byte-compile--suspicious-defcustom-choice
|
||||||
|
'(choice (const :tag "foo" 'bar)))))
|
||||||
|
|
||||||
;; Local Variables:
|
;; Local Variables:
|
||||||
;; no-byte-compile: t
|
;; no-byte-compile: t
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue