annotate lisp/paragraphs.el @ 211:78478c60bfcd r20-4b4

Import from CVS: tag r20-4b4
author cvs
date Mon, 13 Aug 2007 10:05:51 +0200
parents 41ff10fd062f
children 1f0dabaa0855
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1 ;;; paragraphs.el --- paragraph and sentence parsing.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 86, 87, 91, 94, 95, 97 Free Software Foundation, Inc.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
5 ;; Maintainer: FSF
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
6 ;; Keywords: wp, dumped
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
7
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
9
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
13 ;; any later version.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
14
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
18 ;; General Public License for more details.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
19
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
23 ;; 02111-1307, USA.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
24
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
25 ;;; Synched up with: FSF 19.34.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
26
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
27 ;;; Commentary:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
28
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
29 ;; This file is dumped with XEmacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
30
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
31 ;; This package provides the paragraph-oriented commands documented in the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
32 ;; XEmacs Reference Manual.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
33
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
34 ;; 06/11/1997 - Use char-(after|before) instead of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
35 ;; (following|preceding)-char. -slb
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
36
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
37 ;;; Code:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
38
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
39 (defvar use-hard-newlines nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
40 "Non-nil means to distinguish hard and soft newlines.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
41 When this is non-nil, the functions `newline' and `open-line' add the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
42 text-property `hard' to newlines that they insert. Also, a line is
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
43 only considered as a candidate to match `paragraph-start' or
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
44 `paragraph-separate' if it follows a hard newline. Newlines not
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
45 marked hard are called \"soft\", and are always internal to
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
46 paragraphs. The fill functions always insert soft newlines.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
47
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
48 Each buffer has its own value of this variable.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
49 (make-variable-buffer-local 'use-hard-newlines)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
50
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
51 ;; XEmacs - use purecopy
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
52 (defconst paragraph-start (purecopy "[ \t\n\f]") "\
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
53 *Regexp for beginning of a line that starts OR separates paragraphs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
54 This regexp should match lines that separate paragraphs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
55 and should also match lines that start a paragraph
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
56 \(and are part of that paragraph).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
57
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
58 This is matched against the text at the left margin, which is not necessarily
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
59 the beginning of the line, so it should never use \"^\" as an anchor. This
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
60 ensures that the paragraph functions will work equally well within a region
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
61 of text indented by a margin setting.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
62
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
63 The variable `paragraph-separate' specifies how to distinguish
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
64 lines that start paragraphs from lines that separate them.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
65
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
66 If the variable `use-hard-newlines' is non-nil, then only lines following a
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
67 hard newline are considered to match.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
68
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
69 ;; paragraph-start requires a hard newline, but paragraph-separate does not:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
70 ;; It is assumed that paragraph-separate is distinctive enough to be believed
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
71 ;; whenever it occurs, while it is reasonable to set paragraph-start to
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
72 ;; something very minimal, even including "." (which makes every hard newline
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
73 ;; start a new paragraph).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
74
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
75 ;; XEmacs -- use purecopy
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
76 (defconst paragraph-separate (purecopy "[ \t\f]*$") "\
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
77 *Regexp for beginning of a line that separates paragraphs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
78 If you change this, you may have to change paragraph-start also.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
79
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
80 This is matched against the text at the left margin, which is not necessarily
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
81 the beginning of the line, so it should not use \"^\" as an anchor. This
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
82 ensures that the paragraph functions will work equally within a region of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
83 text indented by a margin setting.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
84
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
85 ;; XEmacs -- use purecopy
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
86 (defconst sentence-end (purecopy "[.?!][]\"')}]*\\($\\| $\\|\t\\| \\)[ \t\n]*") "\
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
87 *Regexp describing the end of a sentence.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
88 All paragraph boundaries also end sentences, regardless.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
89
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
90 In order to be recognized as the end of a sentence, the ending period,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
91 question mark, or exclamation point must be followed by two spaces,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
92 unless it's inside some sort of quotes or parenthesis.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
93
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
94 ;; XEmacs -- use purecopy
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
95 (defconst page-delimiter (purecopy "^\014") "\
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
96 *Regexp describing line-beginnings that separate pages.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
97
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
98 (defvar paragraph-ignore-fill-prefix nil "\
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
99 Non-nil means the paragraph commands are not affected by `fill-prefix'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
100 This is desirable in modes where blank lines are the paragraph delimiters.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
101
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
102 (defun forward-paragraph (&optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
103 "Move forward to end of paragraph.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
104 With arg N, do it N times; negative arg -N means move backward N paragraphs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
105
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
106 A line which `paragraph-start' matches either separates paragraphs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
107 \(if `paragraph-separate' matches it also) or is the first line of a paragraph.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
108 A paragraph end is the beginning of a line which is not part of the paragraph
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
109 to which the end of the previous line belongs, or the end of the buffer."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
110 (interactive "_p") ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
111 (or arg (setq arg 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
112 (let* ((fill-prefix-regexp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
113 (and fill-prefix (not (equal fill-prefix ""))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
114 (not paragraph-ignore-fill-prefix)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
115 (regexp-quote fill-prefix)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
116 ;; Remove ^ from paragraph-start and paragraph-sep if they are there.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
117 ;; These regexps shouldn't be anchored, because we look for them
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
118 ;; starting at the left-margin. This allows paragraph commands to
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
119 ;; work normally with indented text.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
120 ;; This hack will not find problem cases like "whatever\\|^something".
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
121 (paragraph-start (if (and (not (equal "" paragraph-start))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
122 (equal ?^ (aref paragraph-start 0)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
123 (substring paragraph-start 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
124 paragraph-start))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
125 (paragraph-separate (if (and (not (equal "" paragraph-start))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
126 (equal ?^ (aref paragraph-separate 0)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
127 (substring paragraph-separate 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
128 paragraph-separate))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
129 (paragraph-separate
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
130 (if fill-prefix-regexp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
131 (concat paragraph-separate "\\|"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
132 fill-prefix-regexp "[ \t]*$")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
133 paragraph-separate))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
134 ;; This is used for searching.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
135 (sp-paragraph-start (concat "^[ \t]*\\(" paragraph-start "\\)"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
136 start)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
137 (while (and (< arg 0) (not (bobp)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
138 (if (and (not (looking-at paragraph-separate))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
139 (re-search-backward "^\n" (max (1- (point)) (point-min)) t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
140 (looking-at paragraph-separate))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
141 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
142 (setq start (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
143 ;; Move back over paragraph-separating lines.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
144 (forward-char -1) (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
145 (while (and (not (bobp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
146 (progn (move-to-left-margin)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
147 (looking-at paragraph-separate)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
148 (forward-line -1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
149 (if (bobp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
150 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
151 ;; Go to end of the previous (non-separating) line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
152 (end-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
153 ;; Search back for line that starts or separates paragraphs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
154 (if (if fill-prefix-regexp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
155 ;; There is a fill prefix; it overrides paragraph-start.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
156 (let (multiple-lines)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
157 (while (and (progn (beginning-of-line) (not (bobp)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
158 (progn (move-to-left-margin)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
159 (not (looking-at paragraph-separate)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
160 (looking-at fill-prefix-regexp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
161 (if (not (= (point) start))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
162 (setq multiple-lines t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
163 (forward-line -1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
164 (move-to-left-margin)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
165 ;; Don't move back over a line before the paragraph
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
166 ;; which doesn't start with fill-prefix
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
167 ;; unless that is the only line we've moved over.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
168 (and (not (looking-at fill-prefix-regexp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
169 multiple-lines
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
170 (forward-line 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
171 (not (bobp)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
172 (while (and (re-search-backward sp-paragraph-start nil 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
173 ;; Found a candidate, but need to check if it is a
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
174 ;; REAL paragraph-start.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
175 (not (bobp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
176 (progn (setq start (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
177 (move-to-left-margin)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
178 (not (looking-at paragraph-separate)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
179 (or (not (looking-at paragraph-start))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
180 (and use-hard-newlines
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
181 (not (get-text-property (1- start)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
182 'hard)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
183 (goto-char start))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
184 (> (point) (point-min)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
185 ;; Found one.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
186 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
187 ;; Move forward over paragraph separators.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
188 ;; We know this cannot reach the place we started
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
189 ;; because we know we moved back over a non-separator.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
190 (while (and (not (eobp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
191 (progn (move-to-left-margin)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
192 (looking-at paragraph-separate)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
193 (forward-line 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
194 ;; If line before paragraph is just margin, back up to there.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
195 (end-of-line 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
196 (if (> (current-column) (current-left-margin))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
197 (forward-char 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
198 (skip-chars-backward " \t")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
199 (if (not (bolp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
200 (forward-line 1))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
201 ;; No starter or separator line => use buffer beg.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
202 (goto-char (point-min)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
203 (setq arg (1+ arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
204 (while (and (> arg 0) (not (eobp)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
205 ;; Move forward over separator lines, and one more line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
206 (while (prog1 (and (not (eobp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
207 (progn (move-to-left-margin) (not (eobp)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
208 (looking-at paragraph-separate))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
209 (forward-line 1)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
210 (if fill-prefix-regexp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
211 ;; There is a fill prefix; it overrides paragraph-start.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
212 (while (and (not (eobp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
213 (progn (move-to-left-margin) (not (eobp)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
214 (not (looking-at paragraph-separate))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
215 (looking-at fill-prefix-regexp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
216 (forward-line 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
217 (while (and (re-search-forward sp-paragraph-start nil 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
218 (progn (setq start (match-beginning 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
219 (goto-char start)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
220 (not (eobp)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
221 (progn (move-to-left-margin)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
222 (not (looking-at paragraph-separate)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
223 (or (not (looking-at paragraph-start))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
224 (and use-hard-newlines
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
225 (not (get-text-property (1- start) 'hard)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
226 (forward-char 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
227 (if (< (point) (point-max))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
228 (goto-char start)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
229 (setq arg (1- arg)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
230
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
231 (defun backward-paragraph (&optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
232 "Move backward to start of paragraph.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
233 With arg N, do it N times; negative arg -N means move forward N paragraphs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
234
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
235 A paragraph start is the beginning of a line which is a
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
236 `first-line-of-paragraph' or which is ordinary text and follows a
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
237 paragraph-separating line; except: if the first real line of a
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
238 paragraph is preceded by a blank line, the paragraph starts at that
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
239 blank line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
240
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
241 See `forward-paragraph' for more information."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
242 (interactive "_p") ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
243 (or arg (setq arg 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
244 (forward-paragraph (- arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
245
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
246 (defun mark-paragraph ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
247 "Put point at beginning of this paragraph, mark at end.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
248 The paragraph marked is the one that contains point or follows point."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
249 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
250 (forward-paragraph 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
251 (push-mark nil t t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
252 (backward-paragraph 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
253
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
254 (defun kill-paragraph (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
255 "Kill forward to end of paragraph.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
256 With arg N, kill forward to Nth end of paragraph;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
257 negative arg -N means kill backward to Nth start of paragraph."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
258 (interactive "*p") ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
259 (kill-region (point) (progn (forward-paragraph arg) (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
260
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
261 (defun backward-kill-paragraph (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
262 "Kill back to start of paragraph.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
263 With arg N, kill back to Nth start of paragraph;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
264 negative arg -N means kill forward to Nth end of paragraph."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
265 (interactive "*p") ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
266 (kill-region (point) (progn (backward-paragraph arg) (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
267
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
268 (defun transpose-paragraphs (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
269 "Interchange this (or next) paragraph with previous one."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
270 (interactive "*p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
271 (transpose-subr 'forward-paragraph arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
272
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
273 (defun start-of-paragraph-text ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
274 (let ((opoint (point)) npoint)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
275 (forward-paragraph -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
276 (setq npoint (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
277 (skip-chars-forward " \t\n")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
278 ;; If the range of blank lines found spans the original start point,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
279 ;; try again from the beginning of it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
280 ;; Must be careful to avoid infinite loop
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
281 ;; when following a single return at start of buffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
282 (if (and (>= (point) opoint) (< npoint opoint))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
283 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
284 (goto-char npoint)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
285 (if (> npoint (point-min))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
286 (start-of-paragraph-text))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
287
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
288 (defun end-of-paragraph-text ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
289 (let ((opoint (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
290 (forward-paragraph 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
291 (if (eq (char-before (point)) ?\n) (forward-char -1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
292 (if (<= (point) opoint)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
293 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
294 (forward-char 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
295 (if (< (point) (point-max))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
296 (end-of-paragraph-text))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
297
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
298 (defun forward-sentence (&optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
299 "Move forward to next `sentence-end'. With argument, repeat.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
300 With negative argument, move backward repeatedly to `sentence-beginning'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
301
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
302 The variable `sentence-end' is a regular expression that matches ends of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
303 sentences. Also, every paragraph boundary terminates sentences as well."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
304 (interactive "_p") ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
305 (or arg (setq arg 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
306 (while (< arg 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
307 (let ((par-beg (save-excursion (start-of-paragraph-text) (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
308 (if (re-search-backward (concat sentence-end "[^ \t\n]") par-beg t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
309 (goto-char (1- (match-end 0)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
310 (goto-char par-beg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
311 (setq arg (1+ arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
312 (while (> arg 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
313 (let ((par-end (save-excursion (end-of-paragraph-text) (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
314 (if (re-search-forward sentence-end par-end t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
315 (skip-chars-backward " \t\n")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
316 (goto-char par-end)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
317 (setq arg (1- arg))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
318
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
319 (defun backward-sentence (&optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
320 "Move backward to start of sentence. With arg, do it arg times.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
321 See `forward-sentence' for more information."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
322 (interactive "_p") ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
323 (or arg (setq arg 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
324 (forward-sentence (- arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
325
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
326 (defun kill-sentence (&optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
327 "Kill from point to end of sentence.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
328 With arg, repeat; negative arg -N means kill back to Nth start of sentence."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
329 (interactive "*p") ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
330 (kill-region (point) (progn (forward-sentence arg) (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
331
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
332 (defun backward-kill-sentence (&optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
333 "Kill back from point to start of sentence.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
334 With arg, repeat, or kill forward to Nth end of sentence if negative arg -N."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
335 (interactive "*p") ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
336 (kill-region (point) (progn (backward-sentence arg) (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
337
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
338 (defun mark-end-of-sentence (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
339 "Put mark at end of sentence. Arg works as in `forward-sentence'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
340 (interactive "p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
341 ;; FSF Version:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
342 ; (push-mark
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
343 ; (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
344 ; (forward-sentence arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
345 ; (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
346 ; nil t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
347 (mark-something 'mark-end-of-sentence 'forward-sentence arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
348
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 209
diff changeset
349 (defun mark-end-of-line (arg)
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 209
diff changeset
350 "Put mark at end of line. Arg works as in `end-of-line'."
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 209
diff changeset
351 (interactive "p")
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 209
diff changeset
352 (mark-something 'mark-end-of-line 'end-of-line arg))
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 209
diff changeset
353
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 209
diff changeset
354
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
355 (defun transpose-sentences (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
356 "Interchange this (next) and previous sentence."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
357 (interactive "*p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
358 (transpose-subr 'forward-sentence arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
359
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
360 ;;; paragraphs.el ends here