aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2022-04-02 15:55:29 +0200
committerLars Ingebrigtsen2022-04-02 15:55:38 +0200
commitec464789dfc5179c72e6929ea99a72f508c562b6 (patch)
tree281d2aa7254b351327e0b38165ceff817f45a998
parent9c30276c426e0b67d288b479a9570428673de331 (diff)
downloademacs-ec464789dfc5179c72e6929ea99a72f508c562b6.tar.gz
emacs-ec464789dfc5179c72e6929ea99a72f508c562b6.zip
Put the define-minor-mode boilerplate at the end of the doc strings
* lisp/emacs-lisp/easy-mmode.el (easy-mmode--mode-docstring): Put the boilerplate at the end of the doc string.
-rw-r--r--lisp/emacs-lisp/easy-mmode.el66
1 files changed, 42 insertions, 24 deletions
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el
index 688c76e0c54..6827faab208 100644
--- a/lisp/emacs-lisp/easy-mmode.el
+++ b/lisp/emacs-lisp/easy-mmode.el
@@ -82,9 +82,7 @@ replacing its case-insensitive matches with the literal string in LIGHTER."
82 (replace-regexp-in-string (regexp-quote lighter) lighter name t t)))) 82 (replace-regexp-in-string (regexp-quote lighter) lighter name t t))))
83 83
84(defconst easy-mmode--arg-docstring 84(defconst easy-mmode--arg-docstring
85 " 85 "This is a minor mode. If called interactively, toggle the `%s'
86
87This is a minor mode. If called interactively, toggle the `%s'
88mode. If the prefix argument is positive, enable the mode, and 86mode. If the prefix argument is positive, enable the mode, and
89if it is zero or negative, disable the mode. 87if it is zero or negative, disable the mode.
90 88
@@ -100,27 +98,47 @@ it is disabled.")
100 98
101(defun easy-mmode--mode-docstring (doc mode-pretty-name keymap-sym 99(defun easy-mmode--mode-docstring (doc mode-pretty-name keymap-sym
102 getter) 100 getter)
103 (let ((doc (or doc (format "Toggle %s on or off. 101 ;; If we have a doc string, and it's already complete (which we
104 102 ;; guess at with the simple heuristic below), then just return that
105\\{%s}" mode-pretty-name keymap-sym)))) 103 ;; as is.
106 (if (string-match-p "\\bARG\\b" doc) 104 (if (and doc (string-match-p "\\bARG\\b" doc))
107 doc 105 doc
108 (let* ((fill-prefix nil) 106 ;; Compose a new doc string.
109 (docs-fc (bound-and-true-p emacs-lisp-docstring-fill-column)) 107 (with-temp-buffer
110 (fill-column (if (integerp docs-fc) docs-fc 65)) 108 (let ((lines (if doc
111 (argdoc (format easy-mmode--arg-docstring mode-pretty-name 109 (string-lines doc)
112 ;; Avoid having quotes turn into pretty quotes. 110 (list (format "Toggle %s on or off." mode-pretty-name)))))
113 (string-replace "'" "\\\\='" 111 ;; Insert the first line from the doc string.
114 (format "%S" getter)))) 112 (insert (pop lines))
115 (filled (if (fboundp 'fill-region) 113 ;; Ensure that we have (only) one blank line after the first
116 (with-temp-buffer 114 ;; line.
117 (insert argdoc) 115 (ensure-empty-lines)
118 (fill-region (point-min) (point-max) 'left t) 116 (while (and lines
119 (buffer-string)) 117 (string-empty-p (car lines)))
120 argdoc))) 118 (pop lines))
121 (replace-regexp-in-string "\\(\n\n\\|\\'\\)\\(.\\|\n\\)*\\'" 119 ;; Insert the doc string.
122 (concat filled "\\1") 120 (dolist (line lines)
123 doc nil nil 1))))) 121 (insert line "\n"))
122 (ensure-empty-lines)
123 ;; Insert the boilerplate.
124 (let* ((fill-prefix nil)
125 (docs-fc (bound-and-true-p emacs-lisp-docstring-fill-column))
126 (fill-column (if (integerp docs-fc) docs-fc 65))
127 (argdoc (format easy-mmode--arg-docstring mode-pretty-name
128 ;; Avoid having quotes turn into pretty quotes.
129 (string-replace "'" "\\\\='"
130 (format "%S" getter)))))
131 (let ((start (point)))
132 (insert argdoc)
133 (when (fboundp 'fill-region)
134 (fill-region start (point) 'left t))))
135 ;; Finally, insert the keymap.
136 (when (and (boundp keymap-sym)
137 (or (not doc)
138 (not (string-search "\\{" doc))))
139 (ensure-empty-lines)
140 (insert (format "\\{%s}" keymap-sym)))
141 (buffer-string)))))
124 142
125;;;###autoload 143;;;###autoload
126(defalias 'easy-mmode-define-minor-mode #'define-minor-mode) 144(defalias 'easy-mmode-define-minor-mode #'define-minor-mode)