- (setq linebeg (point))
- (move-to-column (1+ (current-fill-column)))
- (if (when (< (point) to)
- ;; Find the position where we'll break the line.
- (fill-move-to-break-point linebeg)
- ;; Check again to see if we got to the end of
- ;; the paragraph.
- (skip-chars-forward " \t")
- (< (point) to))
- ;; Found a place to cut.
- (progn
- (fill-newline)
- (when justify
- ;; Justify the line just ended, if desired.
- (save-excursion
- (forward-line -1)
- (justify-current-line justify nil t))))
-
- (goto-char to)
- (if (and (eolp) (or (not nosqueeze) justify))
- (delete-horizontal-space))
- ;; Justify this last line, if desired.
- (if justify (justify-current-line justify t t))))))
- ;; Leave point after final newline.
- (goto-char to))
- (unless (eobp)
- (forward-char 1))
+ (if (and (not (eolp))
+ (< (current-indentation) (current-left-margin)))
+ (fill-indent-to-left-margin))
+ (forward-line 1)))
+
+ (if use-hard-newlines
+ (remove-list-of-text-properties from to '(hard)))
+ ;; Make sure first line is indented (at least) to left margin...
+ (if (or (memq justify '(right center))
+ (< (current-indentation) (current-left-margin)))
+ (fill-indent-to-left-margin))
+ ;; Delete the fill-prefix from every line.
+ (fill-delete-prefix from to fill-prefix)
+ (setq from (point))
+
+ ;; FROM, and point, are now before the text to fill,
+ ;; but after any fill prefix on the first line.
+
+ (fill-delete-newlines from to justify nosqueeze squeeze-after)
+
+ ;; This is the actual filling loop.
+ (goto-char from)
+ (let (linebeg)
+ (while (< (point) to)
+ (setq linebeg (point))
+ (move-to-column (current-fill-column))
+ (if (when (< (point) to)
+ ;; Find the position where we'll break the line.
+ (forward-char 1) ;Use an immediately following space, if any.
+ (fill-move-to-break-point linebeg)
+ ;; Check again to see if we got to the end of
+ ;; the paragraph.
+ (skip-chars-forward " \t")
+ (< (point) to))
+ ;; Found a place to cut.
+ (progn
+ (fill-newline)
+ (when justify
+ ;; Justify the line just ended, if desired.
+ (save-excursion
+ (forward-line -1)
+ (justify-current-line justify nil t))))
+
+ (goto-char to)
+ ;; Justify this last line, if desired.
+ (if justify (justify-current-line justify t t))))))
+ ;; Leave point after final newline.
+ (goto-char to)
+ (unless (eobp) (forward-char 1))