(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
(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
(should (equal (line-number-at-pos 5) 3))
(should (equal (line-number-at-pos 7) 4)))))
+\f
+;;; 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