From fb42a253bdcbdc9f8af5f934cab4aa24d5b541bd Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Wed, 2 Oct 2024 02:28:52 +0200 Subject: [PATCH] Warn about bad defcustom :local keyword at compile time * lisp/emacs-lisp/bytecomp.el (bytecomp--custom-declare): Warn about invalid values for the defcustom :local keyword. * test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-test-defcustom-local): New test. --- lisp/emacs-lisp/bytecomp.el | 8 +++++++- test/lisp/emacs-lisp/bytecomp-tests.el | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 5ed058e0a14..72953502f51 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -5467,7 +5467,13 @@ FORM is used to provide location, `bytecomp--cus-function' and (when (and name byte-compile-current-file ; only when compiling a whole file (eq fun 'custom-declare-group)) - (setq byte-compile-current-group name)))) + (setq byte-compile-current-group name)) + + ;; Check :local + (when-let ((val (and (eq fun 'custom-declare-variable) + (plist-get keyword-args :local))) + (_ (not (memq val '(t permanent permanent-only))))) + (bytecomp--cus-warn form ":local keyword does not accept %S" val)))) (byte-compile-normal-call form)) diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el index ca9849f351b..69918e9c0c3 100644 --- a/test/lisp/emacs-lisp/bytecomp-tests.el +++ b/test/lisp/emacs-lisp/bytecomp-tests.el @@ -1985,6 +1985,14 @@ EXPECTED-POINT BINDINGS (MODES \\='\\='(ruby-mode js-mode python-mode)) \ (dc 'integerp)) )) +(ert-deftest bytecomp-test-defcustom-local () + (cl-flet ((dc (local) `(defcustom mytest nil "doc" :type 'sexp :local ',local :group 'test))) + (bytecomp--with-warning-test + (rx ":local keyword does not accept 'symbol") (dc 'symbol)) + (bytecomp--with-warning-test + (rx ":local keyword does not accept \"string\"") (dc "string")) + )) + (ert-deftest bytecomp-test-defface-spec () (cl-flet ((df (spec) `(defface mytest ',spec "doc" :group 'test))) (bytecomp--with-warning-test