emacs-diffs
[Top][All Lists]
Advanced

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

master 44da8dd 2/6: Improve filling of generated docstring lines


From: Stefan Kangas
Subject: master 44da8dd 2/6: Improve filling of generated docstring lines
Date: Sun, 26 Sep 2021 07:35:07 -0400 (EDT)

branch: master
commit 44da8dd3e4a1e961eb7bbfdf9b1d2abad429ac3c
Author: Stefan Kangas <stefan@marxist.se>
Commit: Stefan Kangas <stefan@marxist.se>

    Improve filling of generated docstring lines
    
    * lisp/subr.el (internal--fill-string-single-line): Improve filling to
    use full width.  Fix bug where line was not wrapped correctly.
---
 lisp/subr.el | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/lisp/subr.el b/lisp/subr.el
index fd1ceb9..8cb79b2 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -6419,12 +6419,19 @@ seconds."
 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 (< (string-width str) fill-column)
+  (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)))
+    (let* ((limit (min fill-column (length str)))
+           (fst (substring str 0 limit))
+           (lst (substring str limit)))
+      (cond ((string-match "\\( \\)$" fst)
+             (setq fst (replace-match "\n" nil nil fst 1)))
+            ((string-match "^ \\(.*\\)" lst)
+             (setq fst (concat fst "\n"))
+             (setq lst (match-string 1 lst)))
+            ((string-match ".*\\( \\(.+\\)\\)$" fst)
+             (setq lst (concat (match-string 2 fst) lst))
+             (setq fst (replace-match "\n" nil nil fst 1))))
       (concat fst (internal--fill-string-single-line lst)))))
 
 (defun internal--format-docstring-line (string &rest objects)



reply via email to

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