aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2008-04-11 15:34:17 +0000
committerStefan Monnier2008-04-11 15:34:17 +0000
commitd87be1dfc8f886510a30574f7f4917c6cf4aa6c2 (patch)
tree2736e5f9c38bb507b91ebd0f5bc9edd1fee95a26
parentc1b513745f93bee34f47901216db2f315b837b20 (diff)
downloademacs-d87be1dfc8f886510a30574f7f4917c6cf4aa6c2.tar.gz
emacs-d87be1dfc8f886510a30574f7f4917c6cf4aa6c2.zip
(fill-forward-paragraph-function): New var.
(fill-forward-paragraph): New fun. (fill-paragraph, fill-region): Use it.
-rw-r--r--etc/NEWS3
-rw-r--r--lisp/ChangeLog4
-rw-r--r--lisp/textmodes/fill.el92
3 files changed, 59 insertions, 40 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 29421f4004f..9acc5be13a3 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -732,6 +732,9 @@ functions and variables (formerly used for Tamil script).
732 732
733* Lisp Changes in Emacs 23.1 733* Lisp Changes in Emacs 23.1
734 734
735** `fill-forward-paragraph-function' specifies which function the filling
736code should use to find paragraph boundaries.
737
735** The variable `this-command-keys-shift-translated' is non-nil if the 738** The variable `this-command-keys-shift-translated' is non-nil if the
736key sequence invoking the current command was found by 739key sequence invoking the current command was found by
737shift-translation. 740shift-translation.
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 2a01d952a11..0eff7181088 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,9 @@
12008-04-11 Stefan Monnier <monnier@iro.umontreal.ca> 12008-04-11 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 * textmodes/fill.el (fill-forward-paragraph-function): New var.
4 (fill-forward-paragraph): New fun.
5 (fill-paragraph, fill-region): Use it.
6
3 * vc.el: Change `dir-status' to not take (and pass) status-buffer. 7 * vc.el: Change `dir-status' to not take (and pass) status-buffer.
4 (vc-status-create-fileinfo): Make `extra' optional. 8 (vc-status-create-fileinfo): Make `extra' optional.
5 (vc-status-busy): New fun. 9 (vc-status-busy): New fun.
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el
index 23b3c1ade9e..af4e11c9f42 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -53,7 +53,10 @@ A value of nil means that any change in indentation starts a new paragraph."
53(defvar fill-paragraph-function nil 53(defvar fill-paragraph-function nil
54 "Mode-specific function to fill a paragraph, or nil if there is none. 54 "Mode-specific function to fill a paragraph, or nil if there is none.
55If the function returns nil, then `fill-paragraph' does its normal work. 55If the function returns nil, then `fill-paragraph' does its normal work.
56A value of t means explicitly \"do nothing special\".") 56A value of t means explicitly \"do nothing special\".
57Note: This only affects `fill-paragraph' and not `fill-region'
58nor `auto-fill-mode', so it is often better to use some other hook,
59such as `fill-forward-paragraph-function'.")
57 60
58(defvar fill-paragraph-handle-comment t 61(defvar fill-paragraph-handle-comment t
59 "Non-nil means paragraph filling will try to pay attention to comments.") 62 "Non-nil means paragraph filling will try to pay attention to comments.")
@@ -757,6 +760,15 @@ space does not end a sentence, so don't break a line there."
757 (narrow-to-region (minibuffer-prompt-end) (point-max)) 760 (narrow-to-region (minibuffer-prompt-end) (point-max))
758 (fill-paragraph arg))) 761 (fill-paragraph arg)))
759 762
763(defvar fill-forward-paragraph-function 'forward-paragraph
764 "Function to move over paragraphs used by the filling code.
765It is called with a single argument specifying the number of paragraphs to move.
766Just like `forward-paragraph', it should return the number of paragraphs
767left to move.")
768
769(defun fill-forward-paragraph (arg)
770 (funcall fill-forward-paragraph-function arg))
771
760(defun fill-paragraph (&optional justify region) 772(defun fill-paragraph (&optional justify region)
761 "Fill paragraph at or after point. 773 "Fill paragraph at or after point.
762 774
@@ -783,37 +795,37 @@ in the active region."
783 (or (fill-region (region-beginning) (region-end) justify) t)) 795 (or (fill-region (region-beginning) (region-end) justify) t))
784 ;; 2. Try fill-paragraph-function. 796 ;; 2. Try fill-paragraph-function.
785 (and (not (eq fill-paragraph-function t)) 797 (and (not (eq fill-paragraph-function t))
786 (or fill-paragraph-function 798 (or fill-paragraph-function
787 (and (minibufferp (current-buffer)) 799 (and (minibufferp (current-buffer))
788 (= 1 (point-min)))) 800 (= 1 (point-min))))
789 (let ((function (or fill-paragraph-function 801 (let ((function (or fill-paragraph-function
790 ;; In the minibuffer, don't count the width 802 ;; In the minibuffer, don't count the width
791 ;; of the prompt. 803 ;; of the prompt.
792 'fill-minibuffer-function)) 804 'fill-minibuffer-function))
793 ;; If fill-paragraph-function is set, it probably takes care 805 ;; If fill-paragraph-function is set, it probably takes care
794 ;; of comments and stuff. If not, it will have to set 806 ;; of comments and stuff. If not, it will have to set
795 ;; fill-paragraph-handle-comment back to t explicitly or 807 ;; fill-paragraph-handle-comment back to t explicitly or
796 ;; return nil. 808 ;; return nil.
797 (fill-paragraph-handle-comment nil) 809 (fill-paragraph-handle-comment nil)
798 (fill-paragraph-function t)) 810 (fill-paragraph-function t))
799 (funcall function justify))) 811 (funcall function justify)))
800 ;; 3. Try our syntax-aware filling code. 812 ;; 3. Try our syntax-aware filling code.
801 (and fill-paragraph-handle-comment 813 (and fill-paragraph-handle-comment
802 ;; Our code only handles \n-terminated comments right now. 814 ;; Our code only handles \n-terminated comments right now.
803 comment-start (equal comment-end "") 815 comment-start (equal comment-end "")
804 (let ((fill-paragraph-handle-comment nil)) 816 (let ((fill-paragraph-handle-comment nil))
805 (fill-comment-paragraph justify))) 817 (fill-comment-paragraph justify)))
806 ;; 4. If it all fails, default to the good ol' text paragraph filling. 818 ;; 4. If it all fails, default to the good ol' text paragraph filling.
807 (let ((before (point)) 819 (let ((before (point))
808 (paragraph-start paragraph-start) 820 (paragraph-start paragraph-start)
809 ;; Fill prefix used for filling the paragraph. 821 ;; Fill prefix used for filling the paragraph.
810 fill-pfx) 822 fill-pfx)
811 ;; Try to prevent code sections and comment sections from being 823 ;; Try to prevent code sections and comment sections from being
812 ;; filled together. 824 ;; filled together.
813 (when (and fill-paragraph-handle-comment comment-start-skip) 825 (when (and fill-paragraph-handle-comment comment-start-skip)
814 (setq paragraph-start 826 (setq paragraph-start
815 (concat paragraph-start "\\|[ \t]*\\(?:" 827 (concat paragraph-start "\\|[ \t]*\\(?:"
816 comment-start-skip "\\)"))) 828 comment-start-skip "\\)")))
817 (save-excursion 829 (save-excursion
818 ;; To make sure the return value of forward-paragraph is meaningful, 830 ;; To make sure the return value of forward-paragraph is meaningful,
819 ;; we have to start from the beginning of line, otherwise skipping 831 ;; we have to start from the beginning of line, otherwise skipping
@@ -821,19 +833,19 @@ in the active region."
821 ;; a paragraph (and not skipping any chars at EOB would not count 833 ;; a paragraph (and not skipping any chars at EOB would not count
822 ;; as a paragraph even if it is). 834 ;; as a paragraph even if it is).
823 (move-to-left-margin) 835 (move-to-left-margin)
824 (if (not (zerop (forward-paragraph))) 836 (if (not (zerop (fill-forward-paragraph 1)))
825 ;; There's no paragraph at or after point: give up. 837 ;; There's no paragraph at or after point: give up.
826 (setq fill-pfx "") 838 (setq fill-pfx "")
827 (let ((end (point)) 839 (let ((end (point))
828 (beg (progn (backward-paragraph) (point)))) 840 (beg (progn (fill-forward-paragraph -1) (point))))
829 (goto-char before) 841 (goto-char before)
830 (setq fill-pfx 842 (setq fill-pfx
831 (if use-hard-newlines 843 (if use-hard-newlines
832 ;; Can't use fill-region-as-paragraph, since this 844 ;; Can't use fill-region-as-paragraph, since this
833 ;; paragraph may still contain hard newlines. See 845 ;; paragraph may still contain hard newlines. See
834 ;; fill-region. 846 ;; fill-region.
835 (fill-region beg end justify) 847 (fill-region beg end justify)
836 (fill-region-as-paragraph beg end justify)))))) 848 (fill-region-as-paragraph beg end justify))))))
837 fill-pfx))) 849 fill-pfx)))
838 850
839(declare-function comment-search-forward "newcomment" (limit &optional noerror)) 851(declare-function comment-search-forward "newcomment" (limit &optional noerror))
@@ -1002,7 +1014,7 @@ space does not end a sentence, so don't break a line there."
1002 (goto-char (max from to)) 1014 (goto-char (max from to))
1003 (when to-eop 1015 (when to-eop
1004 (skip-chars-backward "\n") 1016 (skip-chars-backward "\n")
1005 (forward-paragraph)) 1017 (fill-forward-paragraph 1))
1006 (setq max (copy-marker (point) t)) 1018 (setq max (copy-marker (point) t))
1007 (goto-char (setq beg (min from to))) 1019 (goto-char (setq beg (min from to)))
1008 (beginning-of-line) 1020 (beginning-of-line)
@@ -1020,9 +1032,9 @@ space does not end a sentence, so don't break a line there."
1020 (goto-char (1+ end))) 1032 (goto-char (1+ end)))
1021 (setq end (if end (min max (1+ end)) max)) 1033 (setq end (if end (min max (1+ end)) max))
1022 (goto-char initial)) 1034 (goto-char initial))
1023 (forward-paragraph 1) 1035 (fill-forward-paragraph 1)
1024 (setq end (min max (point))) 1036 (setq end (min max (point)))
1025 (forward-paragraph -1)) 1037 (fill-forward-paragraph -1))
1026 (if (< (point) beg) 1038 (if (< (point) beg)
1027 (goto-char beg)) 1039 (goto-char beg))
1028 (if (>= (point) initial) 1040 (if (>= (point) initial)