diff options
Diffstat (limited to 'lisp/emacs-lisp/bytecomp.el')
-rw-r--r-- | lisp/emacs-lisp/bytecomp.el | 77 |
1 files changed, 74 insertions, 3 deletions
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 3f050d1b799..566a3fdf99c 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -299,7 +299,7 @@ The information is logged to `byte-compile-log-buffer'." '(redefine callargs free-vars unresolved obsolete noruntime interactive-only make-local mapcar constants suspicious lexical lexical-dynamic - docstrings) + docstrings not-unused) "The list of warning types used when `byte-compile-warnings' is t.") (defcustom byte-compile-warnings t "List of warnings that the byte-compiler should issue (t for all). @@ -321,6 +321,7 @@ Elements of the list may be: lexically bound variable declared dynamic elsewhere make-local calls to `make-variable-buffer-local' that may be incorrect. mapcar mapcar called for effect. + not-unused warning about using variables with symbol names starting with _. constants let-binding of, or assignment to, constants/nonvariables. docstrings docstrings that are too wide (longer than `byte-compile-docstring-max-column' or @@ -1671,9 +1672,14 @@ URLs." ;; known at compile time. So instead, we assume that these ;; substitutions are of some length N. (replace-regexp-in-string - (rx "\\" (or (seq "[" (* (not "]")) "]"))) + (rx "\\[" (* (not "]")) "]") (make-string byte-compile--wide-docstring-substitution-len ?x) - docstring)))) + ;; For literal key sequence substitutions (e.g. "\\`C-h'"), just + ;; remove the markup as `substitute-command-keys' would. + (replace-regexp-in-string + (rx "\\`" (group (* (not "'"))) "'") + "\\1" + docstring))))) (defcustom byte-compile-docstring-max-column 80 "Recommended maximum width of doc string lines. @@ -5042,6 +5048,71 @@ binding slots have been popped." nil)) (_ (byte-compile-keep-pending form)))) + + + +;; Key syntax warnings. + +(mapc + (lambda (elem) + (put (car elem) 'byte-hunk-handler + (lambda (form) + (dolist (idx (cdr elem)) + (let ((key (elt form idx))) + (when (or (vectorp key) + (and (stringp key) + (not (key-valid-p key)))) + (byte-compile-warn "Invalid `kbd' syntax: %S" key)))) + form))) + ;; Functions and the place(s) for the key definition(s). + '((keymap-set 2) + (keymap-global-set 1) + (keymap-local-set 1) + (keymap-unset 2) + (keymap-global-unset 1) + (keymap-local-unset 1) + (keymap-substitute 2 3) + (keymap-set-after 2) + (key-translate 1 2) + (keymap-lookup 2) + (keymap-global-lookup 1) + (keymap-local-lookup 1))) + +(put 'define-keymap 'byte-hunk-handler #'byte-compile-define-keymap) +(defun byte-compile-define-keymap (form) + (let ((result nil) + (orig-form form)) + (push (pop form) result) + (while (and form + (keywordp (car form)) + (not (eq (car form) :menu))) + (unless (memq (car form) + '(:full :keymap :parent :suppress :name :prefix)) + (byte-compile-warn "Invalid keyword: %s" (car form))) + (push (pop form) result) + (when (null form) + (byte-compile-warn "Uneven number of keywords in %S" form)) + (push (pop form) result)) + ;; Bindings. + (while form + (let ((key (pop form))) + (when (stringp key) + (unless (key-valid-p key) + (byte-compile-warn "Invalid `kbd' syntax: %S" key))) + ;; No improvement. + (push key result)) + (when (null form) + (byte-compile-warn "Uneven number of key bindings in %S" form)) + (push (pop form) result)) + orig-form)) + +(put 'define-keymap--define 'byte-hunk-handler + #'byte-compile-define-keymap--define) +(defun byte-compile-define-keymap--define (form) + (when (consp (nth 1 form)) + (byte-compile-define-keymap (nth 1 form))) + form) + ;;; tags |