emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master cda26e6 3/3: Do not split line before width of fill


From: Noam Postavsky
Subject: [Emacs-diffs] master cda26e6 3/3: Do not split line before width of fill-prefix
Date: Wed, 30 Aug 2017 20:42:00 -0400 (EDT)

branch: master
commit cda26e64621d71c6a797f694418d844a621998be
Author: Samuel Freilich <address@hidden>
Commit: Noam Postavsky <address@hidden>

    Do not split line before width of fill-prefix
    
    When auto-filling a paragraph, don't split a line before the width of the
    fill-prefix, creating a subsequent line that is as long or longer 
(Bug#20774).
    * lisp/simple.el (do-auto-fill): Only consider break-points that are later 
in
    the line than the width of the fill-prefix.  This is a more general solution
    than the previous logic, which only skipped over the exact fill-prefix.  The
    fill-prefix doesn't necessarily match the prefix of the first line of a
    paragraph in adaptive-fill-mode.
---
 lisp/simple.el            | 27 ++++++++++++---------------
 test/lisp/simple-tests.el | 14 ++++++++++++++
 2 files changed, 26 insertions(+), 15 deletions(-)

diff --git a/lisp/simple.el b/lisp/simple.el
index 13cfa34..27990bb 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -7151,18 +7151,18 @@ Returns t if it really did any work."
               (setq fill-prefix prefix))))
 
       (while (and (not give-up) (> (current-column) fc))
-       ;; Determine where to split the line.
-       (let* (after-prefix
-              (fill-point
-               (save-excursion
-                 (beginning-of-line)
-                 (setq after-prefix (point))
-                 (and fill-prefix
-                      (looking-at (regexp-quote fill-prefix))
-                      (setq after-prefix (match-end 0)))
-                 (move-to-column (1+ fc))
-                 (fill-move-to-break-point after-prefix)
-                 (point))))
+        ;; Determine where to split the line.
+        (let ((fill-point
+               (save-excursion
+                 (beginning-of-line)
+                 ;; Don't split earlier in the line than the length of the
+                 ;; fill prefix, since the resulting line would be longer.
+                 (when fill-prefix
+                   (move-to-column (string-width fill-prefix)))
+                 (let ((after-prefix (point)))
+                    (move-to-column (1+ fc))
+                    (fill-move-to-break-point after-prefix)
+                    (point)))))
 
          ;; See whether the place we found is any good.
          (if (save-excursion
@@ -7170,9 +7170,6 @@ Returns t if it really did any work."
                (or (bolp)
                    ;; There is no use breaking at end of line.
                    (save-excursion (skip-chars-forward " ") (eolp))
-                   ;; It is futile to split at the end of the prefix
-                   ;; since we would just insert the prefix again.
-                   (and after-prefix (<= (point) after-prefix))
                    ;; Don't split right after a comment starter
                    ;; since we would just make another comment starter.
                    (and comment-start-skip
diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el
index ad7aee1..729001b 100644
--- a/test/lisp/simple-tests.el
+++ b/test/lisp/simple-tests.el
@@ -497,5 +497,19 @@ See Bug#21722."
       (should (equal (line-number-at-pos 5) 3))
       (should (equal (line-number-at-pos 7) 4)))))
 
+
+;;; Auto fill.
+
+(ert-deftest auto-fill-mode-no-break-before-length-of-fill-prefix ()
+  (with-temp-buffer
+    (setq-local fill-prefix "   ")
+    (set-fill-column 5)
+    ;; Shouldn't break after 'foo' (3 characters) when the next
+    ;; line is indented >= to that, that woudln't result in shorter
+    ;; lines.
+    (insert "foo bar")
+    (do-auto-fill)
+    (should (string-equal (buffer-string) "foo bar"))))
+
 (provide 'simple-test)
 ;;; simple-test.el ends here



reply via email to

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