aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2002-10-31 00:30:36 +0000
committerStefan Monnier2002-10-31 00:30:36 +0000
commitef11ff9b1f7a896cddf3e07e1da9672e02237fae (patch)
treef91ae77f0f961fea3aa12475cc781f0315f71671
parent58401a3476a31efdf8481293bcf58e220313bdd4 (diff)
downloademacs-ef11ff9b1f7a896cddf3e07e1da9672e02237fae.tar.gz
emacs-ef11ff9b1f7a896cddf3e07e1da9672e02237fae.zip
(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.
-rw-r--r--lisp/textmodes/fill.el118
1 files changed, 58 insertions, 60 deletions
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el
index d8ba7f076c1..44f01898c3c 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -465,6 +465,10 @@ The break position will be always after LINEBEG and generally before point."
465 ;; point is at the place where the break occurs. 465 ;; point is at the place where the break occurs.
466 (forward-char 1) 466 (forward-char 1)
467 (when (fill-nobreak-p) (skip-chars-backward " \t" linebeg)))) 467 (when (fill-nobreak-p) (skip-chars-backward " \t" linebeg))))
468
469 ;; Move back over the single space between the words.
470 (skip-chars-backward " \t")
471
468 ;; If the left margin and fill prefix by themselves 472 ;; If the left margin and fill prefix by themselves
469 ;; pass the fill-column. or if they are zero 473 ;; pass the fill-column. or if they are zero
470 ;; but we have no room for even one word, 474 ;; 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 (forward-char -1) 494 (forward-char -1)
491 (goto-char pos)))) 495 (goto-char pos))))
492 (setq first nil))) 496 (setq first nil)))
493 ;; Normally, move back over the single space between
494 ;; the words.
495 (skip-chars-backward " \t")
496 497
497 (if enable-multibyte-characters 498 (if enable-multibyte-characters
498 ;; If we are going to break the line after or 499 ;; 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
547between words canonical before filling. Fifth arg SQUEEZE-AFTER, if non-nil, 548between words canonical before filling. Fifth arg SQUEEZE-AFTER, if non-nil,
548means don't canonicalize spaces before that position. 549means don't canonicalize spaces before that position.
549 550
550Return the fill-prefix used for filling. 551Return the `fill-prefix' used for filling.
551 552
552If `sentence-end-double-space' is non-nil, then period followed by one 553If `sentence-end-double-space' is non-nil, then period followed by one
553space does not end a sentence, so don't break a line there." 554space 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 (if current-prefix-arg 'full)))) 558 (if current-prefix-arg 'full))))
558 (unless (memq justify '(t nil none full center left right)) 559 (unless (memq justify '(t nil none full center left right))
559 (setq justify 'full)) 560 (setq justify 'full))
560 ;; Arrange for undoing the fill to restore point.
561 (if (and buffer-undo-list (not (eq buffer-undo-list t)))
562 (setq buffer-undo-list (cons (point) buffer-undo-list)))
563 561
564 ;; Make sure "to" is the endpoint. 562 ;; Make sure "to" is the endpoint.
565 (goto-char (min from to)) 563 (goto-char (min from to))
@@ -610,7 +608,6 @@ space does not end a sentence, so don't break a line there."
610 (save-restriction 608 (save-restriction
611 (goto-char from) 609 (goto-char from)
612 (beginning-of-line) 610 (beginning-of-line)
613 (narrow-to-region (point) to)
614 611
615 (if (not justify) ; filling disabled: just check indentation 612 (if (not justify) ; filling disabled: just check indentation
616 (progn 613 (progn
@@ -642,24 +639,27 @@ space does not end a sentence, so don't break a line there."
642 (while (< (point) to) 639 (while (< (point) to)
643 (setq linebeg (point)) 640 (setq linebeg (point))
644 (move-to-column (1+ (current-fill-column))) 641 (move-to-column (1+ (current-fill-column)))
645 (if (>= (point) to) 642 (if (when (< (point) to)
646 (or nosqueeze (delete-horizontal-space)) 643 ;; Find the position where we'll break the line.
647 ;; Find the position where we'll break the line. 644 (fill-move-to-break-point linebeg)
648 (fill-move-to-break-point linebeg) 645 ;; Check again to see if we got to the end of
649 646 ;; the paragraph.
650 ;; Check again to see if we got to the end of the paragraph. 647 (skip-chars-forward " \t")
651 (if (save-excursion (skip-chars-forward " \t") (>= (point) to)) 648 (< (point) to))
652 (or nosqueeze (delete-horizontal-space)) 649 ;; Found a place to cut.
653 (fill-newline))) 650 (progn
654 ;; Justify the line just ended, if desired. 651 (fill-newline)
655 (if justify 652 (when justify
656 (if (save-excursion (skip-chars-forward " \t") (>= (point) to)) 653 ;; Justify the line just ended, if desired.
657 (progn 654 (save-excursion
658 (delete-horizontal-space) 655 (forward-line -1)
659 (justify-current-line justify t t)) 656 (justify-current-line justify nil t))))
660 (save-excursion 657
661 (forward-line -1) 658 (goto-char to)
662 (justify-current-line justify nil t))))))) 659 (if (and (eolp) (or (not nosqueeze) justify))
660 (delete-horizontal-space))
661 ;; Justify this last line, if desired.
662 (if justify (justify-current-line justify t t))))))
663 ;; Leave point after final newline. 663 ;; Leave point after final newline.
664 (goto-char to)) 664 (goto-char to))
665 (unless (eobp) 665 (unless (eobp)
@@ -747,40 +747,38 @@ space does not end a sentence, so don't break a line there."
747 (if current-prefix-arg 'full)))) 747 (if current-prefix-arg 'full))))
748 (unless (memq justify '(t nil none full center left right)) 748 (unless (memq justify '(t nil none full center left right))
749 (setq justify 'full)) 749 (setq justify 'full))
750 (let (end beg fill-pfx) 750 (let (max beg fill-pfx)
751 (save-restriction 751 (goto-char (max from to))
752 (goto-char (max from to)) 752 (when to-eop
753 (when to-eop 753 (skip-chars-backward "\n")
754 (skip-chars-backward "\n") 754 (forward-paragraph))
755 (forward-paragraph)) 755 (setq max (copy-marker (point) t))
756 (setq end (point)) 756 (goto-char (setq beg (min from to)))
757 (goto-char (setq beg (min from to))) 757 (beginning-of-line)
758 (beginning-of-line) 758 (while (< (point) max)
759 (narrow-to-region (point) end) 759 (let ((initial (point))
760 (while (not (eobp)) 760 end)
761 (let ((initial (point)) 761 ;; If using hard newlines, break at every one for filling
762 end) 762 ;; purposes rather than using paragraph breaks.
763 ;; If using hard newlines, break at every one for filling 763 (if use-hard-newlines
764 ;; purposes rather than using paragraph breaks. 764 (progn
765 (if use-hard-newlines 765 (while (and (setq end (text-property-any (point) max
766 (progn 766 'hard t))
767 (while (and (setq end (text-property-any (point) (point-max) 767 (not (= ?\n (char-after end)))
768 'hard t)) 768 (not (>= end max)))
769 (not (= ?\n (char-after end))) 769 (goto-char (1+ end)))
770 (not (= end (point-max)))) 770 (setq end (if end (min max (1+ end)) max))
771 (goto-char (1+ end))) 771 (goto-char initial))
772 (setq end (if end (min (point-max) (1+ end)) (point-max))) 772 (forward-paragraph 1)
773 (goto-char initial)) 773 (setq end (min max (point)))
774 (forward-paragraph 1) 774 (forward-paragraph -1))
775 (setq end (point)) 775 (if (< (point) beg)
776 (forward-paragraph -1)) 776 (goto-char beg))
777 (if (< (point) beg) 777 (if (>= (point) initial)
778 (goto-char beg)) 778 (setq fill-pfx
779 (if (>= (point) initial) 779 (fill-region-as-paragraph (point) end justify nosqueeze))
780 (setq fill-pfx 780 (goto-char end))))
781 (fill-region-as-paragraph (point) end justify nosqueeze)) 781 fill-pfx))
782 (goto-char end))))
783 fill-pfx)))
784 782
785 783
786(defcustom default-justification 'left 784(defcustom default-justification 'left