diff options
| author | Damien Cassou | 2023-09-12 08:28:37 +0200 |
|---|---|---|
| committer | Stefan Kangas | 2023-09-13 16:34:45 +0200 |
| commit | 1f7113e68988fa0bcbdeca5ae364cba8d6db3637 (patch) | |
| tree | 5b71e005c00ba9dae01448ae7e69d4f04780dbb7 | |
| parent | f045750fa5e94659e96bab85d1d05ddf65a4c557 (diff) | |
| download | emacs-1f7113e68988fa0bcbdeca5ae364cba8d6db3637.tar.gz emacs-1f7113e68988fa0bcbdeca5ae364cba8d6db3637.zip | |
Shorten docstrings generated by cl-defstruct
* lisp/emacs-lisp/cl-macs.el (cl-defstruct): Split the first line of
generated docstrings if either the struct name or a field name is very
long. This reduces the likelihood of "docstring wider than 80
characters" errors. (Bug#65790)
| -rw-r--r-- | lisp/emacs-lisp/cl-macs.el | 44 | ||||
| -rw-r--r-- | test/lisp/emacs-lisp/bytecomp-tests.el | 17 |
2 files changed, 48 insertions, 13 deletions
diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el index dc17f992660..ef00f9e4fe4 100644 --- a/lisp/emacs-lisp/cl-macs.el +++ b/lisp/emacs-lisp/cl-macs.el | |||
| @@ -3187,18 +3187,27 @@ To see the documentation for a defined struct type, use | |||
| 3187 | ;; The arg "cl-x" is referenced by name in e.g. pred-form | 3187 | ;; The arg "cl-x" is referenced by name in e.g. pred-form |
| 3188 | ;; and pred-check, so changing it is not straightforward. | 3188 | ;; and pred-check, so changing it is not straightforward. |
| 3189 | (push `(,defsym ,accessor (cl-x) | 3189 | (push `(,defsym ,accessor (cl-x) |
| 3190 | ,(concat | 3190 | ,(let ((long-docstring |
| 3191 | ;; NB. This will produce incorrect results | 3191 | (format "Access slot \"%s\" of `%s' struct CL-X." slot name))) |
| 3192 | ;; in some cases, as our coding conventions | 3192 | (concat |
| 3193 | ;; says that the first line must be a full | 3193 | ;; NB. This will produce incorrect results |
| 3194 | ;; sentence. However, if we don't word wrap | 3194 | ;; in some cases, as our coding conventions |
| 3195 | ;; we will have byte-compiler warnings about | 3195 | ;; says that the first line must be a full |
| 3196 | ;; overly long docstrings. So we can't have | 3196 | ;; sentence. However, if we don't word |
| 3197 | ;; a perfect result here, and choose to avoid | 3197 | ;; wrap we will have byte-compiler warnings |
| 3198 | ;; the byte-compiler warnings. | 3198 | ;; about overly long docstrings. So we |
| 3199 | (internal--format-docstring-line | 3199 | ;; can't have a perfect result here, and |
| 3200 | "Access slot \"%s\" of `%s' struct CL-X." slot name) | 3200 | ;; choose to avoid the byte-compiler |
| 3201 | (if doc (concat "\n" doc) "")) | 3201 | ;; warnings. |
| 3202 | (if (>= (length long-docstring) byte-compile-docstring-max-column) | ||
| 3203 | (concat | ||
| 3204 | (internal--format-docstring-line | ||
| 3205 | "Access slot \"%s\" of CL-X." slot) | ||
| 3206 | "\n" | ||
| 3207 | (internal--format-docstring-line | ||
| 3208 | "Struct CL-X is a `%s'." name)) | ||
| 3209 | (internal--format-docstring-line long-docstring)) | ||
| 3210 | (if doc (concat "\n" doc) ""))) | ||
| 3202 | (declare (side-effect-free t)) | 3211 | (declare (side-effect-free t)) |
| 3203 | ,access-body) | 3212 | ,access-body) |
| 3204 | forms) | 3213 | forms) |
| @@ -3274,7 +3283,16 @@ To see the documentation for a defined struct type, use | |||
| 3274 | (push `(,cldefsym ,cname | 3283 | (push `(,cldefsym ,cname |
| 3275 | (&cl-defs (nil ,@descs) ,@args) | 3284 | (&cl-defs (nil ,@descs) ,@args) |
| 3276 | ,(if (stringp doc) doc | 3285 | ,(if (stringp doc) doc |
| 3277 | (format "Constructor for objects of type `%s'." name)) | 3286 | ;; NB. This will produce incorrect results in |
| 3287 | ;; some cases, as our coding conventions says that | ||
| 3288 | ;; the first line must be a full sentence. | ||
| 3289 | ;; However, if we don't word wrap we will have | ||
| 3290 | ;; byte-compiler warnings about overly long | ||
| 3291 | ;; docstrings. So we can't have a perfect result | ||
| 3292 | ;; here, and choose to avoid the byte-compiler | ||
| 3293 | ;; warnings. | ||
| 3294 | (internal--format-docstring-line | ||
| 3295 | "Constructor for objects of type `%s'." name)) | ||
| 3278 | ,@(if (cl--safe-expr-p `(progn ,@(mapcar #'cl-second descs))) | 3296 | ,@(if (cl--safe-expr-p `(progn ,@(mapcar #'cl-second descs))) |
| 3279 | '((declare (side-effect-free t)))) | 3297 | '((declare (side-effect-free t)))) |
| 3280 | (,con-fun ,@make)) | 3298 | (,con-fun ,@make)) |
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el index 102616c9bb7..03aed5263b6 100644 --- a/test/lisp/emacs-lisp/bytecomp-tests.el +++ b/test/lisp/emacs-lisp/bytecomp-tests.el | |||
| @@ -983,6 +983,23 @@ byte-compiled. Run with dynamic binding." | |||
| 983 | `(cl-defsubst long-name-with-more-than-80-characters-yes-this-is-a-very-long-name-but-why-not!! () | 983 | `(cl-defsubst long-name-with-more-than-80-characters-yes-this-is-a-very-long-name-but-why-not!! () |
| 984 | "Do something."))) | 984 | "Do something."))) |
| 985 | 985 | ||
| 986 | (ert-deftest bytecomp-warn-wide-docstring/cl-defstruct () | ||
| 987 | (bytecomp--without-warning-test | ||
| 988 | `(cl-defstruct short-name | ||
| 989 | field)) | ||
| 990 | (bytecomp--without-warning-test | ||
| 991 | `(cl-defstruct short-name | ||
| 992 | long-name-with-less-80-characters-but-still-quite-a-bit)) | ||
| 993 | (bytecomp--without-warning-test | ||
| 994 | `(cl-defstruct long-name-with-less-80-characters-but-still-quite-a-bit | ||
| 995 | field)) | ||
| 996 | (bytecomp--with-warning-test "wider than.*characters" | ||
| 997 | `(cl-defstruct short-name | ||
| 998 | long-name-with-more-than-80-characters-yes-this-is-a-very-long-name-but-why-not!!)) | ||
| 999 | (bytecomp--with-warning-test "wider than.*characters" | ||
| 1000 | `(cl-defstruct long-name-with-more-than-80-characters-yes-this-is-a-very-long-name-but-why-not!! | ||
| 1001 | field))) | ||
| 1002 | |||
| 986 | (ert-deftest bytecomp-warn-quoted-condition () | 1003 | (ert-deftest bytecomp-warn-quoted-condition () |
| 987 | (bytecomp--with-warning-test | 1004 | (bytecomp--with-warning-test |
| 988 | "Warning: `condition-case' condition should not be quoted: 'arith-error" | 1005 | "Warning: `condition-case' condition should not be quoted: 'arith-error" |