Improve filling of Emacs Lisp doc strings

* lisp/emacs-lisp/lisp-mode.el (lisp-fill-paragraph): When filling
a Lisp string, try to avoid filling bits that follow it
(bug#28937).
This commit is contained in:
Lars Ingebrigtsen 2021-02-04 16:12:41 +01:00
parent e1d54bb638
commit 9bf367e184

View 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))