aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2007-10-18 00:06:33 +0000
committerJuri Linkov2007-10-18 00:06:33 +0000
commitb2d35abb427ccf9c0b826039c18db8e71419f4c8 (patch)
tree0e26d8f08137f64835f8888d8ac640d60ffec8bb
parent77f698ef0912f19c2baa68423dae7bfe4719b123 (diff)
downloademacs-b2d35abb427ccf9c0b826039c18db8e71419f4c8.tar.gz
emacs-b2d35abb427ccf9c0b826039c18db8e71419f4c8.zip
(fill-paragraph-or-region): Remove function at the request of RMS.
(fill-paragraph): Change `arg' to optional `justify'. Add interactive arg `region'. Fix docstring. At the first `or' branch add call to `fill-region' if it the region is active in transient-mark-mode.
-rw-r--r--lisp/textmodes/fill.el137
1 files changed, 67 insertions, 70 deletions
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el
index 2671680542a..cf52793f7b5 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -752,10 +752,10 @@ space does not end a sentence, so don't break a line there."
752 (narrow-to-region (minibuffer-prompt-end) (point-max)) 752 (narrow-to-region (minibuffer-prompt-end) (point-max))
753 (fill-paragraph arg))) 753 (fill-paragraph arg)))
754 754
755(defun fill-paragraph (arg) 755(defun fill-paragraph (&optional justify region)
756 "Fill paragraph at or after point. 756 "Fill paragraph at or after point.
757 757
758If ARG is non-nil (interactively, with prefix argument), justify as well. 758If JUSTIFY is non-nil (interactively, with prefix argument), justify as well.
759If `sentence-end-double-space' is non-nil, then period followed by one 759If `sentence-end-double-space' is non-nil, then period followed by one
760space does not end a sentence, so don't break a line there. 760space does not end a sentence, so don't break a line there.
761the variable `fill-column' controls the width for filling. 761the variable `fill-column' controls the width for filling.
@@ -763,64 +763,73 @@ the variable `fill-column' controls the width for filling.
763If `fill-paragraph-function' is non-nil, we call it (passing our 763If `fill-paragraph-function' is non-nil, we call it (passing our
764argument to it), and if it returns non-nil, we simply return its value. 764argument to it), and if it returns non-nil, we simply return its value.
765 765
766If `fill-paragraph-function' is nil, return the `fill-prefix' used for filling." 766If `fill-paragraph-function' is nil, return the `fill-prefix' used for filling.
767
768Interactively (when `region' is non-nil) in Transient Mark mode when
769the mark is active, call `fill-region' to fill each of the paragraphs
770in the active region."
767 (interactive (progn 771 (interactive (progn
768 (barf-if-buffer-read-only) 772 (barf-if-buffer-read-only)
769 (list (if current-prefix-arg 'full)))) 773 (list (if current-prefix-arg 'full) t)))
770 ;; First try fill-paragraph-function. 774 (or
771 (or (and (not (eq fill-paragraph-function t)) 775 ;; 1. Fill the region if it is active when called interactively.
772 (or fill-paragraph-function 776 (and region transient-mark-mode mark-active
773 (and (minibufferp (current-buffer)) 777 (not (eq (region-beginning) (region-end)))
774 (= 1 (point-min)))) 778 (fill-region (region-beginning) (region-end) justify))
775 (let ((function (or fill-paragraph-function 779 ;; 2. Try fill-paragraph-function.
776 ;; In the minibuffer, don't count the width 780 (and (not (eq fill-paragraph-function t))
777 ;; of the prompt. 781 (or fill-paragraph-function
778 'fill-minibuffer-function)) 782 (and (minibufferp (current-buffer))
779 ;; If fill-paragraph-function is set, it probably takes care 783 (= 1 (point-min))))
780 ;; of comments and stuff. If not, it will have to set 784 (let ((function (or fill-paragraph-function
781 ;; fill-paragraph-handle-comment back to t explicitly or 785 ;; In the minibuffer, don't count the width
782 ;; return nil. 786 ;; of the prompt.
783 (fill-paragraph-handle-comment nil) 787 'fill-minibuffer-function))
784 (fill-paragraph-function t)) 788 ;; If fill-paragraph-function is set, it probably takes care
785 (funcall function arg))) 789 ;; of comments and stuff. If not, it will have to set
786 ;; Then try our syntax-aware filling code. 790 ;; fill-paragraph-handle-comment back to t explicitly or
787 (and fill-paragraph-handle-comment 791 ;; return nil.
788 ;; Our code only handles \n-terminated comments right now. 792 (fill-paragraph-handle-comment nil)
789 comment-start (equal comment-end "") 793 (fill-paragraph-function t))
790 (let ((fill-paragraph-handle-comment nil)) 794 (funcall function justify)))
791 (fill-comment-paragraph arg))) 795 ;; 3. Try our syntax-aware filling code.
792 ;; If it all fails, default to the good ol' text paragraph filling. 796 (and fill-paragraph-handle-comment
793 (let ((before (point)) 797 ;; Our code only handles \n-terminated comments right now.
794 (paragraph-start paragraph-start) 798 comment-start (equal comment-end "")
795 ;; Fill prefix used for filling the paragraph. 799 (let ((fill-paragraph-handle-comment nil))
796 fill-pfx) 800 (fill-comment-paragraph justify)))
797 ;; Try to prevent code sections and comment sections from being 801 ;; 4. If it all fails, default to the good ol' text paragraph filling.
798 ;; filled together. 802 (let ((before (point))
799 (when (and fill-paragraph-handle-comment comment-start-skip) 803 (paragraph-start paragraph-start)
800 (setq paragraph-start 804 ;; Fill prefix used for filling the paragraph.
801 (concat paragraph-start "\\|[ \t]*\\(?:" 805 fill-pfx)
802 comment-start-skip "\\)"))) 806 ;; Try to prevent code sections and comment sections from being
803 (save-excursion 807 ;; filled together.
804 ;; To make sure the return value of forward-paragraph is meaningful, 808 (when (and fill-paragraph-handle-comment comment-start-skip)
805 ;; we have to start from the beginning of line, otherwise skipping 809 (setq paragraph-start
806 ;; past the last few chars of a paragraph-separator would count as 810 (concat paragraph-start "\\|[ \t]*\\(?:"
807 ;; a paragraph (and not skipping any chars at EOB would not count 811 comment-start-skip "\\)")))
808 ;; as a paragraph even if it is). 812 (save-excursion
809 (move-to-left-margin) 813 ;; To make sure the return value of forward-paragraph is meaningful,
810 (if (not (zerop (forward-paragraph))) 814 ;; we have to start from the beginning of line, otherwise skipping
811 ;; There's no paragraph at or after point: give up. 815 ;; past the last few chars of a paragraph-separator would count as
812 (setq fill-pfx "") 816 ;; a paragraph (and not skipping any chars at EOB would not count
813 (let ((end (point)) 817 ;; as a paragraph even if it is).
814 (beg (progn (backward-paragraph) (point)))) 818 (move-to-left-margin)
815 (goto-char before) 819 (if (not (zerop (forward-paragraph)))
816 (setq fill-pfx 820 ;; There's no paragraph at or after point: give up.
817 (if use-hard-newlines 821 (setq fill-pfx "")
818 ;; Can't use fill-region-as-paragraph, since this 822 (let ((end (point))
819 ;; paragraph may still contain hard newlines. See 823 (beg (progn (backward-paragraph) (point))))
820 ;; fill-region. 824 (goto-char before)
821 (fill-region beg end arg) 825 (setq fill-pfx
822 (fill-region-as-paragraph beg end arg)))))) 826 (if use-hard-newlines
823 fill-pfx))) 827 ;; Can't use fill-region-as-paragraph, since this
828 ;; paragraph may still contain hard newlines. See
829 ;; fill-region.
830 (fill-region beg end justify)
831 (fill-region-as-paragraph beg end justify))))))
832 fill-pfx)))
824 833
825(defun fill-comment-paragraph (&optional justify) 834(defun fill-comment-paragraph (&optional justify)
826 "Fill current comment. 835 "Fill current comment.
@@ -1007,18 +1016,6 @@ space does not end a sentence, so don't break a line there."
1007 (goto-char end)))) 1016 (goto-char end))))
1008 fill-pfx)) 1017 fill-pfx))
1009 1018
1010(defun fill-paragraph-or-region (arg)
1011 "Fill the active region or current paragraph.
1012In Transient Mark mode, when the mark is active, it calls `fill-region'
1013on the active region. Otherwise, it calls `fill-paragraph'."
1014 (interactive (progn
1015 (barf-if-buffer-read-only)
1016 (list (if current-prefix-arg 'full))))
1017 (if (and transient-mark-mode mark-active
1018 (not (eq (region-beginning) (region-end))))
1019 (fill-region (region-beginning) (region-end) arg)
1020 (fill-paragraph arg)))
1021
1022 1019
1023(defcustom default-justification 'left 1020(defcustom default-justification 'left
1024 "*Method of justifying text not otherwise specified. 1021 "*Method of justifying text not otherwise specified.