emacs-diffs
[Top][All Lists]
Advanced

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

master e186af2 2/2: Improve fill-region-as-paragraph when there's a fill


From: Lars Ingebrigtsen
Subject: master e186af2 2/2: Improve fill-region-as-paragraph when there's a fill prefix
Date: Sun, 10 Jan 2021 09:04:55 -0500 (EST)

branch: master
commit e186af261a4ed0fbcf8cbb35374b69582f42f25b
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Improve fill-region-as-paragraph when there's a fill prefix
    
    * lisp/textmodes/fill.el (fill-region-as-paragraph): Try to
    improve how line breaks are set on unbreakable text with a fill
    prefix area that has spaces within (bug#45720).
---
 lisp/textmodes/fill.el            | 11 +++++++++--
 test/lisp/textmodes/fill-tests.el | 31 +++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el
index 3346c55..6681b03 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -743,9 +743,16 @@ space does not end a sentence, so don't break a line 
there."
 
        ;; This is the actual filling loop.
        (goto-char from)
-       (let (linebeg)
+       (let ((first t)
+              linebeg)
          (while (< (point) to)
-           (setq linebeg (point))
+            ;; On the first line, there may be text in the fill prefix
+            ;; zone.  In that case, don't consider that area when
+            ;; trying to find a place to put a line break (bug#45720).
+            (if (not first)
+               (setq linebeg (point))
+              (setq first nil
+                    linebeg (+ (point) (length fill-prefix))))
            (move-to-column (current-fill-column))
            (if (when (< (point) to)
                  ;; Find the position where we'll break the line.
diff --git a/test/lisp/textmodes/fill-tests.el 
b/test/lisp/textmodes/fill-tests.el
index f2c63a9..21efe62 100644
--- a/test/lisp/textmodes/fill-tests.el
+++ b/test/lisp/textmodes/fill-tests.el
@@ -44,6 +44,37 @@
     (fill-paragraph)
     (should (string= (buffer-string) "Abc\nd efg\n(h ijk)."))))
 
+(ert-deftest fill-test-unbreakable-paragraph ()
+  (with-temp-buffer
+    (let ((string "aaa =   baaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"))
+      (insert string)
+      (goto-char (point-min))
+      (search-forward "b")
+      (let* ((pos (point))
+             (beg (line-beginning-position))
+             (end (line-end-position))
+             (fill-prefix (make-string (- pos beg) ?\s))
+             ;; `fill-column' is too small to accomodate the current line
+             (fill-column (- end beg 10)))
+        (fill-region-as-paragraph beg end nil nil pos))
+      (should (equal (buffer-string) string)))))
+
+(ert-deftest fill-test-breakable-paragraph ()
+  (with-temp-buffer
+    (let ((string "aaa =   baaaaaaaa aaaaaaaaaa aaaaaaaaaa\n"))
+      (insert string)
+      (goto-char (point-min))
+      (search-forward "b")
+      (let* ((pos (point))
+             (beg (line-beginning-position))
+             (end (line-end-position))
+             (fill-prefix (make-string (- pos beg) ?\s))
+             ;; `fill-column' is too small to accomodate the current line
+             (fill-column (- end beg 10)))
+        (fill-region-as-paragraph beg end nil nil pos))
+      (should (equal
+               (buffer-string)
+               "aaa =   baaaaaaaa aaaaaaaaaa\n         aaaaaaaaaa\n")))))
 
 (provide 'fill-tests)
 



reply via email to

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