From 192355e54af91ad6e7d1343071a749e1ced29400 Mon Sep 17 00:00:00 2001 From: Maxim Cournoyer Date: Tue, 21 Jan 2025 11:50:44 +0900 Subject: lisp: Introduce a `lisp-fill-paragraph-as-displayed' variable. Starting with Emacs 28, filling strings now happens in a narrowed scope, and looses the leading indentation and can cause the string to extend past the fill-column value. Introduce `lisp-fill-paragraph-as-displayed' as a new variable allowing opting out of this new behavior in specific scenarios (such as when using the Scheme major mode, say). * lisp/emacs-lisp/lisp-mode.el (lisp-fill-paragraph-as-displayed): New variable. (lisp-fill-paragraph): Honor it, by avoiding the logic narrow to strings before applying fill-paragraph. * test/lisp/emacs-lisp/lisp-mode-tests.el (lisp-fill-paragraph-respects-fill-column): Test it. (lisp-fill-paragraph-docstring-boundaries): New test, as a safeguard to avoid regressions. Fixes: bug#56197 --- test/lisp/emacs-lisp/lisp-mode-tests.el | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'test/lisp/emacs-lisp') diff --git a/test/lisp/emacs-lisp/lisp-mode-tests.el b/test/lisp/emacs-lisp/lisp-mode-tests.el index 3a765eab625..96e37114276 100644 --- a/test/lisp/emacs-lisp/lisp-mode-tests.el +++ b/test/lisp/emacs-lisp/lisp-mode-tests.el @@ -308,6 +308,53 @@ Expected initialization file: `%s'\" (indent-region (point-min) (point-max)) (should (equal (buffer-string) orig))))) + +;;; Filling + +(ert-deftest lisp-fill-paragraph-docstring-boundaries () + "Test bug#28937, ensuring filling the docstring filled is properly +bounded." + (with-temp-buffer + (insert "\ +(defun test () + \"This is a test docstring. +Here is some more text.\" + 1 + 2 + 3 + 4 + 5)") + (let ((correct (buffer-string))) + (emacs-lisp-mode) + (search-backward "This is a test docstring") + (fill-paragraph) ;function under test + (should (equal (buffer-string) correct))))) + +(ert-deftest lisp-fill-paragraph-as-displayed () + "Test bug#56197 -- more specifically, validate that a leading indentation +for a string is preserved in the filled string." + (let ((lisp-fill-paragraph-as-displayed t) ;variable under test + ;; The following is a contrived example that demonstrates the + ;; fill-column problem when the string to fill is indented. + (source "\ +'(description \"This is a very long string which is indented by a considerable value, causing it to +protrude from the configured `fill-column' since +lisp-fill-paragraph was refactored in version 28.\")")) + (with-temp-buffer + (insert source) + (emacs-lisp-mode) + (search-backward "This is a very long string") + (fill-paragraph) ;function under test + (goto-char (point-min)) + (message "%s" (buffer-substring-no-properties (point-min) (point-max))) + (let ((i 1) + (lines-count (count-lines (point-min) (point-max)))) + (while (< i lines-count) + (beginning-of-line i) + (end-of-line) + (should (<= (current-column) fill-column)) + (setq i (1+ i))))))) + ;;; Fontification -- cgit v1.2.3