aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Freilich2017-08-23 13:40:45 -0400
committerNoam Postavsky2017-08-30 20:10:36 -0400
commitcda26e64621d71c6a797f694418d844a621998be (patch)
tree9ac729275eb1129bacb340ba849d84ffc4eb3a46
parent160295867de98241a16f2ede93da7e825ed4406b (diff)
downloademacs-cda26e64621d71c6a797f694418d844a621998be.tar.gz
emacs-cda26e64621d71c6a797f694418d844a621998be.zip
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.
-rw-r--r--lisp/simple.el27
-rw-r--r--test/lisp/simple-tests.el14
2 files changed, 26 insertions, 15 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index 13cfa3487da..27990bb6611 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -7151,18 +7151,18 @@ Returns t if it really did any work."
7151 (setq fill-prefix prefix)))) 7151 (setq fill-prefix prefix))))
7152 7152
7153 (while (and (not give-up) (> (current-column) fc)) 7153 (while (and (not give-up) (> (current-column) fc))
7154 ;; Determine where to split the line. 7154 ;; Determine where to split the line.
7155 (let* (after-prefix 7155 (let ((fill-point
7156 (fill-point 7156 (save-excursion
7157 (save-excursion 7157 (beginning-of-line)
7158 (beginning-of-line) 7158 ;; Don't split earlier in the line than the length of the
7159 (setq after-prefix (point)) 7159 ;; fill prefix, since the resulting line would be longer.
7160 (and fill-prefix 7160 (when fill-prefix
7161 (looking-at (regexp-quote fill-prefix)) 7161 (move-to-column (string-width fill-prefix)))
7162 (setq after-prefix (match-end 0))) 7162 (let ((after-prefix (point)))
7163 (move-to-column (1+ fc)) 7163 (move-to-column (1+ fc))
7164 (fill-move-to-break-point after-prefix) 7164 (fill-move-to-break-point after-prefix)
7165 (point)))) 7165 (point)))))
7166 7166
7167 ;; See whether the place we found is any good. 7167 ;; See whether the place we found is any good.
7168 (if (save-excursion 7168 (if (save-excursion
@@ -7170,9 +7170,6 @@ Returns t if it really did any work."
7170 (or (bolp) 7170 (or (bolp)
7171 ;; There is no use breaking at end of line. 7171 ;; There is no use breaking at end of line.
7172 (save-excursion (skip-chars-forward " ") (eolp)) 7172 (save-excursion (skip-chars-forward " ") (eolp))
7173 ;; It is futile to split at the end of the prefix
7174 ;; since we would just insert the prefix again.
7175 (and after-prefix (<= (point) after-prefix))
7176 ;; Don't split right after a comment starter 7173 ;; Don't split right after a comment starter
7177 ;; since we would just make another comment starter. 7174 ;; since we would just make another comment starter.
7178 (and comment-start-skip 7175 (and comment-start-skip
diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el
index ad7aee1db17..729001bdf3a 100644
--- a/test/lisp/simple-tests.el
+++ b/test/lisp/simple-tests.el
@@ -497,5 +497,19 @@ See Bug#21722."
497 (should (equal (line-number-at-pos 5) 3)) 497 (should (equal (line-number-at-pos 5) 3))
498 (should (equal (line-number-at-pos 7) 4))))) 498 (should (equal (line-number-at-pos 7) 4)))))
499 499
500
501;;; Auto fill.
502
503(ert-deftest auto-fill-mode-no-break-before-length-of-fill-prefix ()
504 (with-temp-buffer
505 (setq-local fill-prefix " ")
506 (set-fill-column 5)
507 ;; Shouldn't break after 'foo' (3 characters) when the next
508 ;; line is indented >= to that, that woudln't result in shorter
509 ;; lines.
510 (insert "foo bar")
511 (do-auto-fill)
512 (should (string-equal (buffer-string) "foo bar"))))
513
500(provide 'simple-test) 514(provide 'simple-test)
501;;; simple-test.el ends here 515;;; simple-test.el ends here