aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Kangas2021-09-24 19:10:46 +0200
committerStefan Kangas2021-09-24 19:11:11 +0200
commit35c459fd88cbf8dbd71fa81437ff78c1ee84aaa4 (patch)
tree2e1185c0053c9604d994a100f04e83f56ead1caf
parent60edb5da34c2cdf1e156cbf48fe3d426894bcc99 (diff)
downloademacs-scratch/bug-44858.tar.gz
emacs-scratch/bug-44858.zip
Warn about overly long docstring in lambdascratch/bug-44858
* lisp/emacs-lisp/bytecomp.el (byte-compile-docstring-length-warn): Warn about overly long docstring in lambda. (Bug#44858) (byte-compile--wide-docstring-p): Improve comment. * test/lisp/emacs-lisp/bytecomp-tests.el ("warn-wide-docstring-defun.el"): Update to test for the above new warning.
-rw-r--r--lisp/emacs-lisp/bytecomp.el22
-rw-r--r--test/lisp/emacs-lisp/bytecomp-tests.el3
2 files changed, 9 insertions, 16 deletions
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index a3a370134be..091fba44a59 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -1666,7 +1666,10 @@ URLs."
1666 (seq "(" (* (not ")")) ")"))) 1666 (seq "(" (* (not ")")) ")")))
1667 ")"))) 1667 ")")))
1668 "" 1668 ""
1669 ;; Heuristic: assume these substitutions are of some length N. 1669 ;; Heuristic: We assume that these `subsititute-command-keys'
1670 ;; substitutions are of some length N (more precisely, N=1). We
1671 ;; can't reliably do these replacements, since the value of the
1672 ;; keymaps in general can't be known at compile time.
1670 (replace-regexp-in-string 1673 (replace-regexp-in-string
1671 (rx "\\" (or (seq "[" (* (not "]")) "]"))) 1674 (rx "\\" (or (seq "[" (* (not "]")) "]")))
1672 (make-string byte-compile--wide-docstring-substitution-len ?x) 1675 (make-string byte-compile--wide-docstring-substitution-len ?x)
@@ -1686,13 +1689,6 @@ value, it will override this variable."
1686 "Warn if documentation string of FORM is too wide. 1689 "Warn if documentation string of FORM is too wide.
1687It is too wide if it has any lines longer than the largest of 1690It is too wide if it has any lines longer than the largest of
1688`fill-column' and `byte-compile-docstring-max-column'." 1691`fill-column' and `byte-compile-docstring-max-column'."
1689 ;; This has some limitations that it would be nice to fix:
1690 ;; 1. We don't try to handle defuns. It is somewhat tricky to get
1691 ;; it right since `defun' is a macro. Also, some macros
1692 ;; themselves produce defuns (e.g. `define-derived-mode').
1693 ;; 2. We assume that any `subsititute-command-keys' command replacement has a
1694 ;; given length. We can't reliably do these replacements, since the value
1695 ;; of the keymaps in general can't be known at compile time.
1696 (when (byte-compile-warning-enabled-p 'docstrings) 1692 (when (byte-compile-warning-enabled-p 'docstrings)
1697 (let ((col (max byte-compile-docstring-max-column fill-column)) 1693 (let ((col (max byte-compile-docstring-max-column fill-column))
1698 kind name docs) 1694 kind name docs)
@@ -1703,12 +1699,10 @@ It is too wide if it has any lines longer than the largest of
1703 (setq kind (nth 0 form)) 1699 (setq kind (nth 0 form))
1704 (setq name (nth 1 form)) 1700 (setq name (nth 1 form))
1705 (setq docs (nth 3 form))) 1701 (setq docs (nth 3 form)))
1706 ;; Here is how one could add lambda's here: 1702 ('lambda
1707 ;; ('lambda 1703 (setq kind "") ; can't be "function", unfortunately
1708 ;; (setq kind "") ; can't be "function", unfortunately 1704 (setq docs (and (stringp (nth 2 form))
1709 ;; (setq docs (and (stringp (nth 2 form)) 1705 (nth 2 form)))))
1710 ;; (nth 2 form))))
1711 )
1712 (when (and (consp name) (eq (car name) 'quote)) 1706 (when (and (consp name) (eq (car name) 'quote))
1713 (setq name (cadr name))) 1707 (setq name (cadr name)))
1714 (setq name (if name (format " `%s'" name) "")) 1708 (setq name (if name (format " `%s'" name) ""))
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el
index a76038938f5..4f32e8fcc36 100644
--- a/test/lisp/emacs-lisp/bytecomp-tests.el
+++ b/test/lisp/emacs-lisp/bytecomp-tests.el
@@ -892,10 +892,9 @@ byte-compiled. Run with dynamic binding."
892 "warn-wide-docstring-define-obsolete-variable-alias.el" 892 "warn-wide-docstring-define-obsolete-variable-alias.el"
893 "defvaralias .foo. docstring wider than .* characters") 893 "defvaralias .foo. docstring wider than .* characters")
894 894
895;; TODO: We don't yet issue warnings for defuns.
896(bytecomp--define-warning-file-test 895(bytecomp--define-warning-file-test
897 "warn-wide-docstring-defun.el" 896 "warn-wide-docstring-defun.el"
898 "wider than .* characters" 'reverse) 897 "wider than .* characters")
899 898
900(bytecomp--define-warning-file-test 899(bytecomp--define-warning-file-test
901 "warn-wide-docstring-defvar.el" 900 "warn-wide-docstring-defvar.el"