]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid false positives about wide docstrings for key sequences
authorStefan Kangas <stefan@marxist.se>
Mon, 22 Nov 2021 07:08:11 +0000 (08:08 +0100)
committerStefan Kangas <stefan@marxist.se>
Mon, 22 Nov 2021 11:04:19 +0000 (12:04 +0100)
* lisp/emacs-lisp/bytecomp.el (byte-compile--wide-docstring-p):
Ignore literal key sequence substitutions.
* test/lisp/emacs-lisp/bytecomp-resources/warn-wide-docstring-ignore-substitutions.el:
New file.
* test/lisp/emacs-lisp/bytecomp-tests.el
("warn-wide-docstring-ignore-substitutions.el"): New test.

lisp/emacs-lisp/bytecomp.el
test/lisp/emacs-lisp/bytecomp-resources/warn-wide-docstring-ignore-substitutions.el [new file with mode: 0644]
test/lisp/emacs-lisp/bytecomp-tests.el

index 3338c3831713a6423e3cc5f5bf3a8428d6d1dc2c..bd74c79d717bb2c1eee9fb57a1b5cac6c4bbbaac 100644 (file)
@@ -1674,7 +1674,12 @@ URLs."
     (replace-regexp-in-string
      (rx "\\" (or (seq "[" (* (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 "\\" (seq "`" (group (* (not "]"))) "'"))
+      "\\1"
+      docstring)))))
 
 (defcustom byte-compile-docstring-max-column 80
   "Recommended maximum width of doc string lines.
diff --git a/test/lisp/emacs-lisp/bytecomp-resources/warn-wide-docstring-ignore-substitutions.el b/test/lisp/emacs-lisp/bytecomp-resources/warn-wide-docstring-ignore-substitutions.el
new file mode 100644 (file)
index 0000000..37cfe46
--- /dev/null
@@ -0,0 +1,17 @@
+;;; -*- lexical-binding: t -*-
+(defalias 'foo #'ignore
+  "None of this should be considered too wide.
+
+; this should be treated as 60 characters - no warning
+\\[quit-window]\\[quit-window]\\[quit-window]\\[quit-window]\\[quit-window]\\[quit-window]\\[quit-window]\\[quit-window]\\[quit-window]\\[quit-window]\\[quit-window]\\[quit-window]\\[quit-window]\\[quit-window]\\[quit-window]\\[quit-window]\\[quit-window]\\[quit-window]
+
+; 64 * 'x' does not warn
+\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'\\`x'
+
+; keymaps are just ignored
+\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>\\<foo-bar-map>
+
+\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}\\{foo-bar-map}
+
+bar baz foo bar baz foo bar baz foo bar baz foo bar baz foo bar
+")
index dbc0aa3db421947cfd8460c289c3cd72957842d7..816f14a18d5fb89995cd94ec7c562e388827dd46 100644 (file)
@@ -955,6 +955,10 @@ byte-compiled.  Run with dynamic binding."
  "warn-wide-docstring-ignore-override.el"
  "defvar .foo-bar. docstring wider than .* characters" 'reverse)
 
+(bytecomp--define-warning-file-test
+ "warn-wide-docstring-ignore-substitutions.el"
+ "defvar .foo-bar. docstring wider than .* characters" 'reverse)
+
 (bytecomp--define-warning-file-test
  "warn-wide-docstring-ignore.el"
  "defvar .foo-bar. docstring wider than .* characters" 'reverse)