From 9bf367e18486b8f89ff1e0a4c4f4b5b4da4d9a75 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Thu, 4 Feb 2021 16:12:41 +0100 Subject: [PATCH] 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). --- lisp/emacs-lisp/lisp-mode.el | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index 5dda3a8f8e9..f5ce107185a 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el @@ -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)) -- 2.39.2