]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve filling of Emacs Lisp doc strings
authorLars Ingebrigtsen <larsi@gnus.org>
Thu, 4 Feb 2021 15:12:41 +0000 (16:12 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Thu, 4 Feb 2021 15:12:41 +0000 (16:12 +0100)
* lisp/emacs-lisp/lisp-mode.el (lisp-fill-paragraph): When filling
a Lisp string, try to avoid filling bits that follow it
(bug#28937).

lisp/emacs-lisp/lisp-mode.el

index 5dda3a8f8e962983ef054696845b8fa08e2b1ea6..f5ce107185ab8b3900f2e3bce0b15b21dec27cb4 100644 (file)
@@ -1373,7 +1373,24 @@ and initial semicolons."
                                   (derived-mode-p 'emacs-lisp-mode))
                              emacs-lisp-docstring-fill-column
                            fill-column)))
-       (fill-paragraph justify))
+        (save-restriction
+          (save-excursion
+          (let ((ppss (syntax-ppss)))
+            ;; If we're in a string, then narrow (roughly) to that
+            ;; string before filling.  This avoids filling Lisp
+            ;; statements that follow the string.
+            (when (ppss-string-terminator ppss)
+              (goto-char (ppss-comment-or-string-start ppss))
+              (beginning-of-line)
+              ;; The string may be unterminated -- in that case, don't
+              ;; narrow.
+              (when (ignore-errors
+                      (progn
+                        (forward-sexp 1)
+                        t))
+                (narrow-to-region (ppss-comment-or-string-start ppss)
+                                  (point))))
+           (fill-paragraph justify)))))
       ;; Never return nil.
       t))