Mercurial > emacs
comparison lisp/textmodes/fill.el @ 50408:329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Don't remove space at end of paragraph: it makes refill.el unusable.
(fill-paragraph, fill-comment-paragraph): Don't add newline at EOP.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Wed, 02 Apr 2003 23:04:09 +0000 |
parents | 5ade352e8d1c |
children | 97b1943f76b5 |
comparison
equal
deleted
inserted
replaced
50407:41c0eed9d556 | 50408:329ac267f1fc |
---|---|
625 ;; if we indent-according-to-mode. | 625 ;; if we indent-according-to-mode. |
626 (when (and fill-prefix fill-indent-according-to-mode | 626 (when (and fill-prefix fill-indent-according-to-mode |
627 (string-match "\\`[ \t]*\\'" fill-prefix)) | 627 (string-match "\\`[ \t]*\\'" fill-prefix)) |
628 (setq fill-prefix nil))) | 628 (setq fill-prefix nil))) |
629 | 629 |
630 (save-restriction | 630 (goto-char from) |
631 (beginning-of-line) | |
632 | |
633 (if (not justify) ; filling disabled: just check indentation | |
634 (progn | |
635 (goto-char from) | |
636 (while (< (point) to) | |
637 (if (and (not (eolp)) | |
638 (< (current-indentation) (current-left-margin))) | |
639 (fill-indent-to-left-margin)) | |
640 (forward-line 1))) | |
641 | |
642 (if use-hard-newlines | |
643 (remove-list-of-text-properties from to '(hard))) | |
644 ;; Make sure first line is indented (at least) to left margin... | |
645 (if (or (memq justify '(right center)) | |
646 (< (current-indentation) (current-left-margin))) | |
647 (fill-indent-to-left-margin)) | |
648 ;; Delete the fill-prefix from every line. | |
649 (fill-delete-prefix from to fill-prefix) | |
650 (setq from (point)) | |
651 | |
652 ;; FROM, and point, are now before the text to fill, | |
653 ;; but after any fill prefix on the first line. | |
654 | |
655 (fill-delete-newlines from to justify nosqueeze squeeze-after) | |
656 | |
657 ;; This is the actual filling loop. | |
631 (goto-char from) | 658 (goto-char from) |
632 (beginning-of-line) | 659 (let (linebeg) |
633 | 660 (while (< (point) to) |
634 (if (not justify) ; filling disabled: just check indentation | 661 (setq linebeg (point)) |
635 (progn | 662 (move-to-column (1+ (current-fill-column))) |
636 (goto-char from) | 663 (if (when (< (point) to) |
637 (while (< (point) to) | 664 ;; Find the position where we'll break the line. |
638 (if (and (not (eolp)) | 665 (fill-move-to-break-point linebeg) |
639 (< (current-indentation) (current-left-margin))) | 666 ;; Check again to see if we got to the end of |
640 (fill-indent-to-left-margin)) | 667 ;; the paragraph. |
641 (forward-line 1))) | 668 (skip-chars-forward " \t") |
642 | 669 (< (point) to)) |
643 (if use-hard-newlines | 670 ;; Found a place to cut. |
644 (remove-list-of-text-properties from to '(hard))) | 671 (progn |
645 ;; Make sure first line is indented (at least) to left margin... | 672 (fill-newline) |
646 (if (or (memq justify '(right center)) | 673 (when justify |
647 (< (current-indentation) (current-left-margin))) | 674 ;; Justify the line just ended, if desired. |
648 (fill-indent-to-left-margin)) | 675 (save-excursion |
649 ;; Delete the fill-prefix from every line. | 676 (forward-line -1) |
650 (fill-delete-prefix from to fill-prefix) | 677 (justify-current-line justify nil t)))) |
651 (setq from (point)) | 678 |
652 | 679 (goto-char to) |
653 ;; FROM, and point, are now before the text to fill, | 680 ;; Justify this last line, if desired. |
654 ;; but after any fill prefix on the first line. | 681 (if justify (justify-current-line justify t t)))))) |
655 | 682 ;; Leave point after final newline. |
656 (fill-delete-newlines from to justify nosqueeze squeeze-after) | 683 (goto-char to) |
657 | 684 (unless (eobp) (forward-char 1)) |
658 ;; This is the actual filling loop. | |
659 (goto-char from) | |
660 (let (linebeg) | |
661 (while (< (point) to) | |
662 (setq linebeg (point)) | |
663 (move-to-column (1+ (current-fill-column))) | |
664 (if (when (< (point) to) | |
665 ;; Find the position where we'll break the line. | |
666 (fill-move-to-break-point linebeg) | |
667 ;; Check again to see if we got to the end of | |
668 ;; the paragraph. | |
669 (skip-chars-forward " \t") | |
670 (< (point) to)) | |
671 ;; Found a place to cut. | |
672 (progn | |
673 (fill-newline) | |
674 (when justify | |
675 ;; Justify the line just ended, if desired. | |
676 (save-excursion | |
677 (forward-line -1) | |
678 (justify-current-line justify nil t)))) | |
679 | |
680 (goto-char to) | |
681 (if (and (eolp) (or (not nosqueeze) justify)) | |
682 (delete-horizontal-space)) | |
683 ;; Justify this last line, if desired. | |
684 (if justify (justify-current-line justify t t)))))) | |
685 ;; Leave point after final newline. | |
686 (goto-char to)) | |
687 (unless (eobp) | |
688 (forward-char 1)) | |
689 ;; Return the fill-prefix we used | 685 ;; Return the fill-prefix we used |
690 fill-prefix))) | 686 fill-prefix))) |
691 | 687 |
692 (defsubst skip-line-prefix (prefix) | 688 (defsubst skip-line-prefix (prefix) |
693 "If point is inside the string PREFIX at the beginning of line, move past it." | 689 "If point is inside the string PREFIX at the beginning of line, move past it." |
746 ;; as a paragraph even if it is). | 742 ;; as a paragraph even if it is). |
747 (move-to-left-margin) | 743 (move-to-left-margin) |
748 (if (not (zerop (forward-paragraph))) | 744 (if (not (zerop (forward-paragraph))) |
749 ;; There's no paragraph at or after point: give up. | 745 ;; There's no paragraph at or after point: give up. |
750 (setq fill-pfx "") | 746 (setq fill-pfx "") |
751 (or (bolp) (newline 1)) | |
752 (let ((end (point)) | 747 (let ((end (point)) |
753 (beg (progn (backward-paragraph) (point)))) | 748 (beg (progn (backward-paragraph) (point)))) |
754 (goto-char before) | 749 (goto-char before) |
755 (setq fill-pfx | 750 (setq fill-pfx |
756 (if use-hard-newlines | 751 (if use-hard-newlines |
826 comment-start-skip "\\)\\(?:" | 821 comment-start-skip "\\)\\(?:" |
827 (default-value 'paragraph-start) "\\)")) | 822 (default-value 'paragraph-start) "\\)")) |
828 (paragraph-ignore-fill-prefix nil) | 823 (paragraph-ignore-fill-prefix nil) |
829 (fill-prefix comment-fill-prefix) | 824 (fill-prefix comment-fill-prefix) |
830 (after-line (if has-code-and-comment | 825 (after-line (if has-code-and-comment |
831 (line-beginning-position 2))) | 826 (line-beginning-position 2)))) |
832 ) | 827 (setq end (progn (forward-paragraph) (point))) |
833 (setq end (progn | |
834 (forward-paragraph) | |
835 (or (bolp) (newline 1)) | |
836 (point))) | |
837 ;; If this comment starts on a line with code, | 828 ;; If this comment starts on a line with code, |
838 ;; include that line in the filling. | 829 ;; include that line in the filling. |
839 (setq beg (progn (backward-paragraph) | 830 (setq beg (progn (backward-paragraph) |
840 (if (eq (point) after-line) | 831 (if (eq (point) after-line) |
841 (forward-line -1)) | 832 (forward-line -1)) |
842 (point)))) | 833 (point))))) |
843 ) | |
844 | 834 |
845 ;; Find the fill-prefix to use. | 835 ;; Find the fill-prefix to use. |
846 (cond | 836 (cond |
847 (fill-prefix) ; Use the user-provided fill prefix. | 837 (fill-prefix) ; Use the user-provided fill prefix. |
848 ((and adaptive-fill-mode ; Try adaptive fill mode. | 838 ((and adaptive-fill-mode ; Try adaptive fill mode. |