Optionally add argument description in minor mode DOC (bug#10754)

Add a paragraph to minor mode's docstring documenting the mode's ARG
usage if the supplied docstring doesn't already contain the word "ARG".

* easy-mmode.el (easy-mmode--arg-docstring): New const.
(easy-mmode--arg-docstring): New function.
(define-minor-mode): Use them.

Remove argument documentation from all minor modes.
This commit is contained in:
John Shahid 2018-07-01 23:34:53 -04:00 committed by Stefan Monnier
parent fd5bf49139
commit ee3e432300
134 changed files with 136 additions and 619 deletions

View file

@ -1237,9 +1237,6 @@ TEXT, START, END and UNFIXABLE conform to
;;;###autoload
(define-minor-mode checkdoc-minor-mode
"Toggle automatic docstring checking (Checkdoc minor mode).
With a prefix argument ARG, enable Checkdoc minor mode if ARG is
positive, and disable it otherwise. If called from Lisp, enable
the mode if ARG is omitted or nil.
In Checkdoc minor mode, the usual bindings for `eval-defun' which is
bound to \\<checkdoc-minor-mode-map>\\[checkdoc-eval-defun] and `checkdoc-eval-current-buffer' are overridden to include

View file

@ -81,6 +81,26 @@ replacing its case-insensitive matches with the literal string in LIGHTER."
;; space.)
(replace-regexp-in-string (regexp-quote lighter) lighter name t t))))
(defconst easy-mmode--arg-docstring
"
If called interactively, enable %s if ARG is positive, and
disable it if ARG is zero or negative. If called from Lisp,
also enable the mode if ARG is omitted or nil, and toggle it
if ARG is `toggle'; disable the mode otherwise.")
(defun easy-mmode--mode-docstring (doc mode-pretty-name keymap-sym)
(let ((doc (or doc (format "Toggle %s on or off.
\\{%s}" mode-pretty-name keymap-sym))))
(if (string-match-p "\\bARG\\b" doc)
doc
(let ((argdoc (format easy-mmode--arg-docstring
mode-pretty-name)))
(replace-regexp-in-string "\\(\n\n\\|\\'\\)\\(.\\|\n\\)*\\'"
(concat argdoc "\\1")
doc nil nil 1)))))
;;;###autoload
(defalias 'easy-mmode-define-minor-mode 'define-minor-mode)
;;;###autoload
@ -101,7 +121,9 @@ non-positive integer, and enables the mode otherwise (including
if the argument is omitted or nil or a positive integer).
If DOC is nil, give the mode command a basic doc-string
documenting what its argument does.
documenting what its argument does. If the word \"ARG\" does not
appear in DOC, a paragraph is added to DOC explaining
usage of the mode argument.
Optional INIT-VALUE is the initial value of the mode's variable.
Optional LIGHTER is displayed in the mode line when the mode is on.
@ -270,12 +292,7 @@ or call the function `%s'."))))
;; The actual function.
(defun ,modefun (&optional arg ,@extra-args)
,(or doc
(format (concat "Toggle %s on or off.
With a prefix argument ARG, enable %s if ARG is
positive, and disable it otherwise. If called from Lisp, enable
the mode if ARG is omitted or nil, and toggle it if ARG is `toggle'.
\\{%s}") pretty-name pretty-name keymap-sym))
,(easy-mmode--mode-docstring doc pretty-name keymap-sym)
;; Use `toggle' rather than (if ,mode 0 1) so that using
;; repeat-command still does the toggling correctly.
(interactive (list (or current-prefix-arg 'toggle)))

View file

@ -177,9 +177,6 @@ printed after commands contained in this obarray."
;;;###autoload
(define-minor-mode eldoc-mode
"Toggle echo area display of Lisp objects at point (ElDoc mode).
With a prefix argument ARG, enable ElDoc mode if ARG is positive,
and disable it otherwise. If called from Lisp, enable ElDoc mode
if ARG is omitted or nil.
ElDoc mode is a buffer-local minor mode. When enabled, the echo
area displays information about a function or variable in the