unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Kangas <stefan@marxist.se>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 44858@debbugs.gnu.org
Subject: bug#44858: [PATCH] Make byte-compiler warn about wide docstrings
Date: Thu, 10 Dec 2020 15:53:13 -0600	[thread overview]
Message-ID: <CADwFkm=V26PS9g+GYyZwMNjusmZcHB-RfHh5vfLn8p9-4KHa5Q@mail.gmail.com> (raw)
In-Reply-To: <CADwFkm=pXm4PDHGXgHY+xX1BT0DGESar1EWZBcSZsA2c3gF9Mg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 284 bytes --]

Stefan Kangas <stefan@marxist.se> writes:

> 2. Avoid wide docstrings in define-minor-mode.

And here's a patch also for define-derived-mode.

It seems like we still need to fix cl-defun, cl-defstruct,
define-globalized-minor-mode and perhaps a few others.
So I'll work on that next.

[-- Attachment #2: 0004-Fill-docstrings-in-define-derived-mode.patch --]
[-- Type: text/x-diff, Size: 4063 bytes --]

From 50f2a3cce5de966599952fdd1e6ea05913a950b1 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefan@marxist.se>
Date: Thu, 10 Dec 2020 22:36:18 +0100
Subject: [PATCH] Fill docstrings in define-derived-mode

* lisp/subr.el (internal--fill-string): New function.
* lisp/emacs-lisp/derived.el (derived-mode-make-docstring): Fill
docstrings.
---
 lisp/emacs-lisp/derived.el | 42 +++++++++++++++++++++-----------------
 lisp/subr.el               | 13 ++++++++++++
 2 files changed, 36 insertions(+), 19 deletions(-)

diff --git a/lisp/emacs-lisp/derived.el b/lisp/emacs-lisp/derived.el
index 6a11f1c394..00a6c12b10 100644
--- a/lisp/emacs-lisp/derived.el
+++ b/lisp/emacs-lisp/derived.el
@@ -306,11 +306,13 @@ derived-mode-make-docstring
       ;; Use a default docstring.
       (setq docstring
 	    (if (null parent)
-		;; FIXME filling.
-		(format "Major-mode.\nUses keymap `%s'%s%s." map
-			(if abbrev (format "%s abbrev table `%s'"
-					   (if syntax "," " and") abbrev) "")
-			(if syntax (format " and syntax-table `%s'" syntax) ""))
+                (concat
+                 "Major-mode.\n"
+                 (internal--fill-string
+                  (format "Uses keymap `%s'%s%s." map
+                          (if abbrev (format "%s abbrev table `%s'"
+                                             (if syntax "," " and") abbrev) "")
+                          (if syntax (format " and syntax-table `%s'" syntax) ""))))
 	      (format "Major mode derived from `%s' by `define-derived-mode'.
 It inherits all of the parent's attributes, but has its own keymap%s:
 
@@ -336,20 +338,22 @@ derived-mode-make-docstring
     (unless (string-match (regexp-quote (symbol-name hook)) docstring)
       ;; Make sure the docstring mentions the mode's hook.
       (setq docstring
-	    (concat docstring
-		    (if (null parent)
-			"\n\nThis mode "
-		      (concat
-		       "\n\nIn addition to any hooks its parent mode "
-		       (if (string-match (format "[`‘]%s['’]"
-                                                 (regexp-quote
-						  (symbol-name parent)))
-					 docstring)
-                           nil
-			 (format "`%s' " parent))
-		       "might have run,\nthis mode "))
-		    (format "runs the hook `%s'" hook)
-		    ", as the final or penultimate step\nduring initialization.")))
+            (concat docstring "\n\n"
+                    (internal--fill-string
+                     (concat
+                      (if (null parent)
+                          "This mode "
+                        (concat
+                         "In addition to any hooks its parent mode "
+                         (if (string-match (format "[`‘]%s['’]"
+                                                   (regexp-quote
+                                                    (symbol-name parent)))
+                                           docstring)
+                             nil
+                           (format "`%s' " parent))
+                         "might have run, this mode "))
+                      (format "runs the hook `%s'" hook)
+                      ", as the final or penultimate step during initialization.")))))
 
     (unless (string-match "\\\\[{[]" docstring)
       ;; And don't forget to put the mode's keymap.
diff --git a/lisp/subr.el b/lisp/subr.el
index c28807f694..4d10b70db7 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -5927,4 +5927,17 @@ run-hook-query-error-with-timeout
      ;; Continue running.
      nil)))
 
+(defun internal--fill-string (str)
+  "Fill string STR to `fill-column'.
+This is intended for very simple filling while bootstrapping
+Emacs itself, and does not support all the customization options
+of fill.el (for example `fill-region')."
+  (if (< (length str) fill-column)
+      str
+    (let ((fst (substring str 0 fill-column))
+          (lst (substring str fill-column)))
+      (if (string-match ".*\\( \\(.+\\)\\)$" fst)
+          (setq fst (replace-match "\n\\2" nil nil fst 1)))
+      (concat fst (internal--fill-string lst)))))
+
 ;;; subr.el ends here
-- 
2.29.2


  reply	other threads:[~2020-12-10 21:53 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-25  1:36 bug#44858: [PATCH] Make byte-compiler warn about wide docstrings Stefan Kangas
2020-11-26 10:49 ` Lars Ingebrigtsen
2020-11-26 12:46   ` Stefan Kangas
2020-11-26 12:53     ` Lars Ingebrigtsen
2020-12-10 20:59       ` Stefan Kangas
2020-12-10 21:53         ` Stefan Kangas [this message]
2020-12-11  8:16           ` Eli Zaretskii
2020-12-11 20:03             ` Stefan Kangas
2020-12-11  7:33         ` Eli Zaretskii
2020-12-11 20:36           ` Stefan Kangas
2020-12-19 11:22             ` Eli Zaretskii
2020-12-19 16:50               ` Stefan Kangas
2020-12-19 17:14                 ` Eli Zaretskii
2020-12-29  1:27                   ` Basil L. Contovounesios
2020-12-29  2:16                     ` Lars Ingebrigtsen
2020-12-19 17:18                 ` Lars Ingebrigtsen
2020-12-19 23:48                   ` Stefan Kangas
2020-12-11  7:53         ` Eli Zaretskii
2020-12-19 23:55           ` Stefan Kangas
2020-12-20 17:53             ` Lars Ingebrigtsen
2020-12-28  5:18               ` Stefan Kangas
2020-12-11 15:13         ` Lars Ingebrigtsen
2020-12-30 12:07       ` Stefan Kangas
2020-12-31  4:42         ` Lars Ingebrigtsen
2020-11-26 14:19 ` Eli Zaretskii
2020-11-27  8:37   ` Lars Ingebrigtsen
2020-11-27 11:15     ` Stefan Kangas
2020-11-27 12:44       ` Eli Zaretskii
2020-12-06 11:09         ` Stefan Kangas
2020-12-06 11:19           ` Eli Zaretskii
2020-12-06 16:54           ` Drew Adams
2020-11-27 18:36     ` Drew Adams
2020-11-27 18:55       ` Drew Adams
2020-12-03 20:18 ` Tomas Nordin
2020-12-11 20:14   ` Stefan Kangas
2021-09-24 17:25 ` Stefan Kangas
2021-09-25  1:07   ` Lars Ingebrigtsen
2021-09-26 11:38     ` Stefan Kangas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADwFkm=V26PS9g+GYyZwMNjusmZcHB-RfHh5vfLn8p9-4KHa5Q@mail.gmail.com' \
    --to=stefan@marxist.se \
    --cc=44858@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).