[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Filling the docstring generated by define-minor-mode

From: Juanma Barranquero
Subject: Filling the docstring generated by define-minor-mode
Date: Mon, 10 Jun 2019 06:55:14 +0200

Currently, in some cases, define-minor-mode generates parts of a minor
mode's doctring, by using easy-mmode--arg-docstring:

  (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.")

and then adding other references to the minor mode's function or variable.

Minor mode's names are often long and the result is quite ugly. An
easy fix is simply filling the docstring afterwards:

diff --git i/lisp/emacs-lisp/easy-mmode.el w/lisp/emacs-lisp/easy-mmode.el
index be531aab84..23f85a3f4f 100644
--- i/lisp/emacs-lisp/easy-mmode.el
+++ w/lisp/emacs-lisp/easy-mmode.el
@@ -96,9 +96,13 @@ easy-mmode--mode-docstring
     (if (string-match-p "\\bARG\\b" doc)
-      (let ((argdoc (format easy-mmode--arg-docstring
+      (let ((fill-prefix nil) (fill-column 65)
+            (argdoc (format easy-mmode--arg-docstring
-        (replace-regexp-in-string "\\(\n\n\\|\\'\\)\\(.\\|\n\\)*\\'"
-                                  (concat argdoc "\\1")
-                                  doc nil nil 1)))))
+        (with-temp-buffer
+          (insert (replace-regexp-in-string "\\(\n\n\\|\\'\\)\\(.\\|\n\\)*\\'"
+                                            (concat argdoc "\\1")
+                                            doc nil nil 1))
+          (fill-region (point-min) (point-max) 'left t)
+          (buffer-string))))))


In the patch above I've used 65 as fill-column because I think it
gives better results for most minor mode's names than the suggested
60. Other values are of course posible, and can be discussed later if
this is deemed useful.

The following images show the docstring for
`display-fill-column-indicator-mode', as it is right now, and after
auto-filling it to 65 columns.


Attachment: before.png
Description: PNG image

Attachment: after.png
Description: PNG image

reply via email to

[Prev in Thread] Current Thread [Next in Thread]