Commit ef11ff9b authored by Stefan Monnier's avatar Stefan Monnier
Browse files

(fill-move-to-break-point): Skip white space

_before_ checking to see if we're hitting the margin.
(fill-region-as-paragraph): Don't fiddle with the undo-list any more:
it's now done by the C primitives.  Don't use narrowing.
Reorganize the line-breaking part of the code to simplify the control
flow and make it work in the absence of narrowing.
(fill-region): Don't use narrowing.
parent 58401a34
...@@ -465,6 +465,10 @@ The break position will be always after LINEBEG and generally before point." ...@@ -465,6 +465,10 @@ The break position will be always after LINEBEG and generally before point."
;; point is at the place where the break occurs. ;; point is at the place where the break occurs.
(forward-char 1) (forward-char 1)
(when (fill-nobreak-p) (skip-chars-backward " \t" linebeg)))) (when (fill-nobreak-p) (skip-chars-backward " \t" linebeg))))
;; Move back over the single space between the words.
(skip-chars-backward " \t")
;; If the left margin and fill prefix by themselves ;; If the left margin and fill prefix by themselves
;; pass the fill-column. or if they are zero ;; pass the fill-column. or if they are zero
;; but we have no room for even one word, ;; but we have no room for even one word,
...@@ -490,9 +494,6 @@ The break position will be always after LINEBEG and generally before point." ...@@ -490,9 +494,6 @@ The break position will be always after LINEBEG and generally before point."
(forward-char -1) (forward-char -1)
(goto-char pos)))) (goto-char pos))))
(setq first nil))) (setq first nil)))
;; Normally, move back over the single space between
;; the words.
(skip-chars-backward " \t")
(if enable-multibyte-characters (if enable-multibyte-characters
;; If we are going to break the line after or ;; If we are going to break the line after or
...@@ -547,7 +548,7 @@ justification. Fourth arg NOSQUEEZE non-nil means not to make spaces ...@@ -547,7 +548,7 @@ justification. Fourth arg NOSQUEEZE non-nil means not to make spaces
between words canonical before filling. Fifth arg SQUEEZE-AFTER, if non-nil, between words canonical before filling. Fifth arg SQUEEZE-AFTER, if non-nil,
means don't canonicalize spaces before that position. means don't canonicalize spaces before that position.
Return the fill-prefix used for filling. Return the `fill-prefix' used for filling.
If `sentence-end-double-space' is non-nil, then period followed by one If `sentence-end-double-space' is non-nil, then period followed by one
space does not end a sentence, so don't break a line there." space does not end a sentence, so don't break a line there."
...@@ -557,9 +558,6 @@ space does not end a sentence, so don't break a line there." ...@@ -557,9 +558,6 @@ space does not end a sentence, so don't break a line there."
(if current-prefix-arg 'full)))) (if current-prefix-arg 'full))))
(unless (memq justify '(t nil none full center left right)) (unless (memq justify '(t nil none full center left right))
(setq justify 'full)) (setq justify 'full))
;; Arrange for undoing the fill to restore point.
(if (and buffer-undo-list (not (eq buffer-undo-list t)))
(setq buffer-undo-list (cons (point) buffer-undo-list)))
;; Make sure "to" is the endpoint. ;; Make sure "to" is the endpoint.
(goto-char (min from to)) (goto-char (min from to))
...@@ -610,7 +608,6 @@ space does not end a sentence, so don't break a line there." ...@@ -610,7 +608,6 @@ space does not end a sentence, so don't break a line there."
(save-restriction (save-restriction
(goto-char from) (goto-char from)
(beginning-of-line) (beginning-of-line)
(narrow-to-region (point) to)
(if (not justify) ; filling disabled: just check indentation (if (not justify) ; filling disabled: just check indentation
(progn (progn
...@@ -642,24 +639,27 @@ space does not end a sentence, so don't break a line there." ...@@ -642,24 +639,27 @@ space does not end a sentence, so don't break a line there."
(while (< (point) to) (while (< (point) to)
(setq linebeg (point)) (setq linebeg (point))
(move-to-column (1+ (current-fill-column))) (move-to-column (1+ (current-fill-column)))
(if (>= (point) to) (if (when (< (point) to)
(or nosqueeze (delete-horizontal-space)) ;; Find the position where we'll break the line.
;; Find the position where we'll break the line. (fill-move-to-break-point linebeg)
(fill-move-to-break-point linebeg) ;; Check again to see if we got to the end of
;; the paragraph.
;; Check again to see if we got to the end of the paragraph. (skip-chars-forward " \t")
(if (save-excursion (skip-chars-forward " \t") (>= (point) to)) (< (point) to))
(or nosqueeze (delete-horizontal-space)) ;; Found a place to cut.
(fill-newline))) (progn
;; Justify the line just ended, if desired. (fill-newline)
(if justify (when justify
(if (save-excursion (skip-chars-forward " \t") (>= (point) to)) ;; Justify the line just ended, if desired.
(progn (save-excursion
(delete-horizontal-space) (forward-line -1)
(justify-current-line justify t t)) (justify-current-line justify nil t))))
(save-excursion
(forward-line -1) (goto-char to)
(justify-current-line justify nil t))))))) (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. ;; Leave point after final newline.
(goto-char to)) (goto-char to))
(unless (eobp) (unless (eobp)
...@@ -747,40 +747,38 @@ space does not end a sentence, so don't break a line there." ...@@ -747,40 +747,38 @@ space does not end a sentence, so don't break a line there."
(if current-prefix-arg 'full)))) (if current-prefix-arg 'full))))
(unless (memq justify '(t nil none full center left right)) (unless (memq justify '(t nil none full center left right))
(setq justify 'full)) (setq justify 'full))
(let (end beg fill-pfx) (let (max beg fill-pfx)
(save-restriction (goto-char (max from to))
(goto-char (max from to)) (when to-eop
(when to-eop (skip-chars-backward "\n")
(skip-chars-backward "\n") (forward-paragraph))
(forward-paragraph)) (setq max (copy-marker (point) t))
(setq end (point)) (goto-char (setq beg (min from to)))
(goto-char (setq beg (min from to))) (beginning-of-line)
(beginning-of-line) (while (< (point) max)
(narrow-to-region (point) end) (let ((initial (point))
(while (not (eobp)) end)
(let ((initial (point)) ;; If using hard newlines, break at every one for filling
end) ;; purposes rather than using paragraph breaks.
;; If using hard newlines, break at every one for filling (if use-hard-newlines
;; purposes rather than using paragraph breaks. (progn
(if use-hard-newlines (while (and (setq end (text-property-any (point) max
(progn 'hard t))
(while (and (setq end (text-property-any (point) (point-max) (not (= ?\n (char-after end)))
'hard t)) (not (>= end max)))
(not (= ?\n (char-after end))) (goto-char (1+ end)))
(not (= end (point-max)))) (setq end (if end (min max (1+ end)) max))
(goto-char (1+ end))) (goto-char initial))
(setq end (if end (min (point-max) (1+ end)) (point-max))) (forward-paragraph 1)
(goto-char initial)) (setq end (min max (point)))
(forward-paragraph 1) (forward-paragraph -1))
(setq end (point)) (if (< (point) beg)
(forward-paragraph -1)) (goto-char beg))
(if (< (point) beg) (if (>= (point) initial)
(goto-char beg)) (setq fill-pfx
(if (>= (point) initial) (fill-region-as-paragraph (point) end justify nosqueeze))
(setq fill-pfx (goto-char end))))
(fill-region-as-paragraph (point) end justify nosqueeze)) fill-pfx))
(goto-char end))))
fill-pfx)))
(defcustom default-justification 'left (defcustom default-justification 'left
......
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