]> git.eshelyaron.com Git - emacs.git/commitdiff
Clarify the purpose of internal--format-docstring-line
authorStefan Kangas <stefan@marxist.se>
Sat, 2 Oct 2021 19:56:22 +0000 (21:56 +0200)
committerStefan Kangas <stefan@marxist.se>
Sat, 2 Oct 2021 23:59:52 +0000 (01:59 +0200)
* test/lisp/subr-tests.el (subr-test-internal--format-docstring-line):
* lisp/subr.el (internal--format-docstring-line): Make it more clear
that this function is not intended for the first line of a docstring.
* lisp/emacs-lisp/cl-macs.el (cl-defstruct): Add comment explaining
why we use 'internal--format-docstring-line'.
Problem pointed out by Stefan Monnier <monnier@iro.umontreal.ca>.

lisp/emacs-lisp/cl-macs.el
lisp/subr.el
test/lisp/subr-tests.el

index 527720c6e8dff93f8342330c9860a934c977909f..1852471bcbbf1fce5ea651e59897d3584f2b7008 100644 (file)
@@ -3087,6 +3087,14 @@ To see the documentation for a defined struct type, use
              ;; and pred-check, so changing it is not straightforward.
              (push `(,defsym ,accessor (cl-x)
                        ,(concat
+                         ;; NB.  This will produce incorrect results
+                         ;; in some cases, as our coding conventions
+                         ;; says that the first line must be a full
+                         ;; sentence.  However, if we don't word wrap
+                         ;; we will have byte-compiler warnings about
+                         ;; overly long docstrings.  So we can't have
+                         ;; a perfect result here, and choose to avoid
+                         ;; the byte-compiler warnings.
                          (internal--format-docstring-line
                           "Access slot \"%s\" of `%s' struct CL-X." slot name)
                          (if doc (concat "\n" doc) ""))
index 1d2980802e04e6c5e88595de7e05369710ea9b6f..a8fb52c909872bb7086485da0b61f47c0284a396 100644 (file)
@@ -6437,7 +6437,9 @@ of fill.el (for example `fill-region')."
 (defun internal--format-docstring-line (string &rest objects)
   "Format a single line from a documentation string out of STRING and OBJECTS.
 Signal an error if STRING contains a newline.
-This is intended for internal use only."
+This is intended for internal use only.  Avoid using this for the
+first line of a docstring; the first line should be a complete
+sentence (see Info node `(elisp) Documentation Tips')."
   (when (string-match "\n" string)
     (error "Unable to fill string containing newline: %S" string))
   (internal--fill-string-single-line (apply #'format string objects)))
index ed9a3d01498bd72377255f4ee4b5278c4af61a24..0da1ae968736d2273dd23e2c586564ad5b3cd09e 100644 (file)
@@ -769,15 +769,14 @@ See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19350."
 
 (ert-deftest subr-test-internal--format-docstring-line ()
   (should
-   (string= (let ((fill-column 60))
+   (string= (let ((fill-column 70))
               (internal--format-docstring-line
-               "Emacs is the advanced, extensible, customizable, \
-self-documenting editor.  This manual describes how to edit with Emacs and \
-some of the ways to customize it; it corresponds to GNU Emacs version 28.1."))
-            "Emacs is the advanced, extensible, customizable,
-self-documenting editor.  This manual describes how to edit
-with Emacs and some of the ways to customize it; it
-corresponds to GNU Emacs version 28.1.")))
+               "In addition to any hooks its parent mode might have run, this \
+mode runs the hook ‘foo-bar-baz-very-long-name-indeed-mode-hook’, as the final \
+or penultimate step during initialization."))
+            "In addition to any hooks its parent mode might have run, this mode
+runs the hook ‘foo-bar-baz-very-long-name-indeed-mode-hook’, as the
+final or penultimate step during initialization.")))
 
 (ert-deftest test-ensure-list ()
   (should (equal (ensure-list nil) nil))