aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Kangas2020-12-10 22:36:18 +0100
committerStefan Kangas2020-12-28 06:26:52 +0100
commit6b8bb47ac085700740feaad24a591a8bbec3a71c (patch)
tree79f8f4358698977a88d26a02e7df5122b671f776
parent0ebea8ffbfb7b9b1bd92f30011df0875b54eb663 (diff)
downloademacs-6b8bb47ac085700740feaad24a591a8bbec3a71c.tar.gz
emacs-6b8bb47ac085700740feaad24a591a8bbec3a71c.zip
Fill some auto-generated docstrings
* lisp/emacs-lisp/easy-mmode.el (define-minor-mode) (define-globalized-minor-mode): Fill auto-generated documentation strings. (Bug#44858) * lisp/subr.el (internal--fill-string-single-line) (internal--format-docstring-line): New functions.
-rw-r--r--lisp/emacs-lisp/derived.el42
-rw-r--r--lisp/emacs-lisp/easy-mmode.el39
-rw-r--r--lisp/subr.el18
3 files changed, 61 insertions, 38 deletions
diff --git a/lisp/emacs-lisp/derived.el b/lisp/emacs-lisp/derived.el
index 6a11f1c3949..dee507269b2 100644
--- a/lisp/emacs-lisp/derived.el
+++ b/lisp/emacs-lisp/derived.el
@@ -306,11 +306,13 @@ No problems result if this variable is not bound.
306 ;; Use a default docstring. 306 ;; Use a default docstring.
307 (setq docstring 307 (setq docstring
308 (if (null parent) 308 (if (null parent)
309 ;; FIXME filling. 309 (concat
310 (format "Major-mode.\nUses keymap `%s'%s%s." map 310 "Major-mode.\n"
311 (if abbrev (format "%s abbrev table `%s'" 311 (internal--format-docstring-line
312 (if syntax "," " and") abbrev) "") 312 "Uses keymap `%s'%s%s." map
313 (if syntax (format " and syntax-table `%s'" syntax) "")) 313 (if abbrev (format "%s abbrev table `%s'"
314 (if syntax "," " and") abbrev) "")
315 (if syntax (format " and syntax-table `%s'" syntax) "")))
314 (format "Major mode derived from `%s' by `define-derived-mode'. 316 (format "Major mode derived from `%s' by `define-derived-mode'.
315It inherits all of the parent's attributes, but has its own keymap%s: 317It inherits all of the parent's attributes, but has its own keymap%s:
316 318
@@ -336,20 +338,22 @@ which more-or-less shadow%s %s's corresponding table%s."
336 (unless (string-match (regexp-quote (symbol-name hook)) docstring) 338 (unless (string-match (regexp-quote (symbol-name hook)) docstring)
337 ;; Make sure the docstring mentions the mode's hook. 339 ;; Make sure the docstring mentions the mode's hook.
338 (setq docstring 340 (setq docstring
339 (concat docstring 341 (concat docstring "\n\n"
340 (if (null parent) 342 (internal--format-docstring-line
341 "\n\nThis mode " 343 "%s%s%s"
342 (concat 344 (if (null parent)
343 "\n\nIn addition to any hooks its parent mode " 345 "This mode "
344 (if (string-match (format "[`‘]%s['’]" 346 (concat
345 (regexp-quote 347 "In addition to any hooks its parent mode "
346 (symbol-name parent))) 348 (if (string-match (format "[`‘]%s['’]"
347 docstring) 349 (regexp-quote
348 nil 350 (symbol-name parent)))
349 (format "`%s' " parent)) 351 docstring)
350 "might have run,\nthis mode ")) 352 nil
351 (format "runs the hook `%s'" hook) 353 (format "`%s' " parent))
352 ", as the final or penultimate step\nduring initialization."))) 354 "might have run, this mode "))
355 (format "runs the hook `%s'" hook)
356 ", as the final or penultimate step during initialization."))))
353 357
354 (unless (string-match "\\\\[{[]" docstring) 358 (unless (string-match "\\\\[{[]" docstring)
355 ;; And don't forget to put the mode's keymap. 359 ;; And don't forget to put the mode's keymap.
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el
index 261f2508af7..1344c3391bf 100644
--- a/lisp/emacs-lisp/easy-mmode.el
+++ b/lisp/emacs-lisp/easy-mmode.el
@@ -278,8 +278,10 @@ For example, you could write
278 ((not globalp) 278 ((not globalp)
279 `(progn 279 `(progn
280 :autoload-end 280 :autoload-end
281 (defvar ,mode ,init-value ,(format "Non-nil if %s is enabled. 281 (defvar ,mode ,init-value
282Use the command `%s' to change this variable." pretty-name mode)) 282 ,(concat (format "Non-nil if %s is enabled.\n" pretty-name)
283 (internal--format-docstring-line
284 "Use the command `%s' to change this variable." mode)))
283 (make-variable-buffer-local ',mode))) 285 (make-variable-buffer-local ',mode)))
284 (t 286 (t
285 (let ((base-doc-string 287 (let ((base-doc-string
@@ -455,24 +457,23 @@ on if the hook has explicitly disabled it.
455 (make-variable-buffer-local ',MODE-major-mode)) 457 (make-variable-buffer-local ',MODE-major-mode))
456 ;; The actual global minor-mode 458 ;; The actual global minor-mode
457 (define-minor-mode ,global-mode 459 (define-minor-mode ,global-mode
458 ;; Very short lines to avoid too long lines in the generated 460 ,(concat (format "Toggle %s in all buffers.\n" pretty-name)
459 ;; doc string. 461 (internal--format-docstring-line
460 ,(format "Toggle %s in all buffers. 462 "With prefix ARG, enable %s if ARG is positive; otherwise, \
461With prefix ARG, enable %s if ARG is positive; 463disable it. If called from Lisp, enable the mode if ARG is omitted or nil.\n\n"
462otherwise, disable it. If called from Lisp, enable the mode if 464 pretty-global-name)
463ARG is omitted or nil. 465 (internal--format-docstring-line
464 466 "%s is enabled in all buffers where `%s' would do it.\n\n"
465%s is enabled in all buffers where 467 pretty-name turn-on)
466`%s' would do it. 468 (internal--format-docstring-line
467 469 "See `%s' for more information on %s."
468See `%s' for more information on 470 mode pretty-name)
469%s.%s"
470 pretty-name pretty-global-name
471 pretty-name turn-on mode pretty-name
472 (if predicate 471 (if predicate
473 (format "\n\n`%s' is used to control which modes 472 (concat
474this minor mode is used in." 473 "\n\n"
475 MODE-predicate) 474 (internal--format-docstring-line
475 "`%s' is used to control which modes this minor mode is used in."
476 MODE-predicate))
476 "")) 477 ""))
477 :global t ,@group ,@(nreverse extra-keywords) 478 :global t ,@group ,@(nreverse extra-keywords)
478 479
diff --git a/lisp/subr.el b/lisp/subr.el
index 725722cbee1..384dbb25cf8 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -5973,4 +5973,22 @@ seconds."
5973 ;; Continue running. 5973 ;; Continue running.
5974 nil))) 5974 nil)))
5975 5975
5976(defun internal--fill-string-single-line (str)
5977 "Fill string STR to `fill-column'.
5978This is intended for very simple filling while bootstrapping
5979Emacs itself, and does not support all the customization options
5980of fill.el (for example `fill-region')."
5981 (if (< (string-width str) fill-column)
5982 str
5983 (let ((fst (substring str 0 fill-column))
5984 (lst (substring str fill-column)))
5985 (if (string-match ".*\\( \\(.+\\)\\)$" fst)
5986 (setq fst (replace-match "\n\\2" nil nil fst 1)))
5987 (concat fst (internal--fill-string-single-line lst)))))
5988
5989(defun internal--format-docstring-line (string &rest objects)
5990 "Format a documentation string out of STRING and OBJECTS.
5991This is intended for internal use only."
5992 (internal--fill-string-single-line (apply #'format string objects)))
5993
5976;;; subr.el ends here 5994;;; subr.el ends here