Commit dcfe5c05 authored by Karl Heuer's avatar Karl Heuer
Browse files

(fill-region-as-paragraph): Check again for reaching

the end of the paragraph, after we adjust for places we can't break
and make sure to keep at least one word.
parent f82966e4
...@@ -197,6 +197,7 @@ space does not end a sentence, so don't break a line there." ...@@ -197,6 +197,7 @@ space does not end a sentence, so don't break a line there."
(setq from (point)) (setq from (point))
;; Delete all but one soft newline at end of region. ;; Delete all but one soft newline at end of region.
;; And leave TO before that one.
(goto-char to) (goto-char to)
(while (and (> (point) from) (eq ?\n (char-after (1- (point))))) (while (and (> (point) from) (eq ?\n (char-after (1- (point)))))
(if (and oneleft (if (and oneleft
...@@ -362,20 +363,23 @@ space does not end a sentence, so don't break a line there." ...@@ -362,20 +363,23 @@ space does not end a sentence, so don't break a line there."
(skip-chars-forward " \t") (skip-chars-forward " \t")
(skip-chars-forward "^ \t\n") (skip-chars-forward "^ \t\n")
(setq first nil)))) (setq first nil))))
;; Replace whitespace here with one newline, then indent to left ;; Check again to see if we got to the end of the paragraph.
;; margin. (if (eobp)
(skip-chars-backward " \t") (or nosqueeze (delete-horizontal-space))
(insert ?\n) ;; Replace whitespace here with one newline, then indent to left
;; Give newline the properties of the space(s) it replaces ;; margin.
(set-text-properties (1- (point)) (point) (skip-chars-backward " \t")
(text-properties-at (point))) (insert ?\n)
(indent-to-left-margin) ;; Give newline the properties of the space(s) it replaces
;; Insert the fill prefix after indentation. (set-text-properties (1- (point)) (point)
;; Set prefixcol so whitespace in the prefix won't get lost. (text-properties-at (point)))
(and fill-prefix (not (equal fill-prefix "")) (indent-to-left-margin)
(progn ;; Insert the fill prefix after indentation.
(insert-and-inherit fill-prefix) ;; Set prefixcol so whitespace in the prefix won't get lost.
(setq prefixcol (current-column))))) (and fill-prefix (not (equal fill-prefix ""))
(progn
(insert-and-inherit fill-prefix)
(setq prefixcol (current-column))))))
;; Justify the line just ended, if desired. ;; Justify the line just ended, if desired.
(if justify (if justify
(if (eobp) (if (eobp)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment