comparison lisp/prim/paragraphs.el @ 72:b9518feda344 r20-0b31

Import from CVS: tag r20-0b31
author cvs
date Mon, 13 Aug 2007 09:03:46 +0200
parents 131b0175ea99
children 360340f9fd5f
comparison
equal deleted inserted replaced
71:bae944334fa4 72:b9518feda344
1 ;;; paragraphs.el --- paragraph and sentence parsing. 1 ;;; paragraphs.el --- paragraph and sentence parsing.
2 2
3 ;; Copyright (C) 1985, 1986, 1987, 1991, 1993, 1994, 1995 3 ;; Copyright (C) 1985, 86, 87, 91, 94, 95 Free Software Foundation, Inc.
4 ;; Free Software Foundation, Inc.
5 4
6 ;; Maintainer: FSF 5 ;; Maintainer: FSF
7 ;; Keywords: wp 6 ;; Keywords: wp
8 7
9 ;; This file is part of XEmacs. 8 ;; This file is part of XEmacs.
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of 16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details. 18 ;; General Public License for more details.
20 19
21 ;; You should have received a copy of the GNU General Public License 20 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs; see the file COPYING. If not, write to the 21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
23 ;; Free Software Foundation, 59 Temple Place - Suite 330, 22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 ;; Boston, MA 02111-1307, USA. 23 ;; 02111-1307, USA.
25 24
26 ;;; Synched up with: FSF 19.30. 25 ;;; Synched up with: FSF 19.34.
27 26
28 ;;; Commentary: 27 ;;; Commentary:
29 28
30 ;; This package provides the paragraph-oriented commands documented in the 29 ;; This package provides the paragraph-oriented commands documented in the
31 ;; XEmacs Reference Manual. 30 ;; XEmacs Reference Manual.
42 paragraphs. The fill functions always insert soft newlines. 41 paragraphs. The fill functions always insert soft newlines.
43 42
44 Each buffer has its own value of this variable.") 43 Each buffer has its own value of this variable.")
45 (make-variable-buffer-local 'use-hard-newlines) 44 (make-variable-buffer-local 'use-hard-newlines)
46 45
46 ;; XEmacs - use purecopy
47 (defconst paragraph-start (purecopy "[ \t\n\f]") "\ 47 (defconst paragraph-start (purecopy "[ \t\n\f]") "\
48 *Regexp for beginning of a line that starts OR separates paragraphs. 48 *Regexp for beginning of a line that starts OR separates paragraphs.
49 This regexp should match lines that separate paragraphs 49 This regexp should match lines that separate paragraphs
50 and should also match lines that start a paragraph 50 and should also match lines that start a paragraph
51 \(and are part of that paragraph). 51 \(and are part of that paragraph).
65 ;; It is assumed that paragraph-separate is distinctive enough to be believed 65 ;; It is assumed that paragraph-separate is distinctive enough to be believed
66 ;; whenever it occurs, while it is reasonable to set paragraph-start to 66 ;; whenever it occurs, while it is reasonable to set paragraph-start to
67 ;; something very minimal, even including "." (which makes every hard newline 67 ;; something very minimal, even including "." (which makes every hard newline
68 ;; start a new paragraph). 68 ;; start a new paragraph).
69 69
70 ;; XEmacs -- use purecopy
70 (defconst paragraph-separate (purecopy "[ \t\f]*$") "\ 71 (defconst paragraph-separate (purecopy "[ \t\f]*$") "\
71 *Regexp for beginning of a line that separates paragraphs. 72 *Regexp for beginning of a line that separates paragraphs.
72 If you change this, you may have to change paragraph-start also. 73 If you change this, you may have to change paragraph-start also.
73 74
74 This is matched against the text at the left margin, which is not necessarily 75 This is matched against the text at the left margin, which is not necessarily
75 the beginning of the line, so it should not use \"^\" as an anchor. This 76 the beginning of the line, so it should not use \"^\" as an anchor. This
76 ensures that the paragraph functions will work equally within a region of 77 ensures that the paragraph functions will work equally within a region of
77 text indented by a margin setting.") 78 text indented by a margin setting.")
78 79
80 ;; XEmacs -- use purecopy
79 (defconst sentence-end (purecopy "[.?!][]\"')}]*\\($\\| $\\|\t\\| \\)[ \t\n]*") "\ 81 (defconst sentence-end (purecopy "[.?!][]\"')}]*\\($\\| $\\|\t\\| \\)[ \t\n]*") "\
80 *Regexp describing the end of a sentence. 82 *Regexp describing the end of a sentence.
81 All paragraph boundaries also end sentences, regardless. 83 All paragraph boundaries also end sentences, regardless.
82 84
83 In order to be recognized as the end of a sentence, the ending period, 85 In order to be recognized as the end of a sentence, the ending period,
84 question mark, or exclamation point must be followed by two spaces, 86 question mark, or exclamation point must be followed by two spaces,
85 unless it's inside some sort of quotes or parenthesis.") 87 unless it's inside some sort of quotes or parenthesis.")
86 88
89 ;; XEmacs -- use purecopy
87 (defconst page-delimiter (purecopy "^\014") "\ 90 (defconst page-delimiter (purecopy "^\014") "\
88 *Regexp describing line-beginnings that separate pages.") 91 *Regexp describing line-beginnings that separate pages.")
89 92
90 (defvar paragraph-ignore-fill-prefix nil "\ 93 (defvar paragraph-ignore-fill-prefix nil "\
91 Non-nil means the paragraph commands are not affected by `fill-prefix'. 94 Non-nil means the paragraph commands are not affected by `fill-prefix'.
97 100
98 A line which `paragraph-start' matches either separates paragraphs 101 A line which `paragraph-start' matches either separates paragraphs
99 \(if `paragraph-separate' matches it also) or is the first line of a paragraph. 102 \(if `paragraph-separate' matches it also) or is the first line of a paragraph.
100 A paragraph end is the beginning of a line which is not part of the paragraph 103 A paragraph end is the beginning of a line which is not part of the paragraph
101 to which the end of the previous line belongs, or the end of the buffer." 104 to which the end of the previous line belongs, or the end of the buffer."
102 (interactive "_p") 105 (interactive "_p") ; XEmacs
103 (or arg (setq arg 1)) 106 (or arg (setq arg 1))
104 (let* ((fill-prefix-regexp 107 (let* ((fill-prefix-regexp
105 (and fill-prefix (not (equal fill-prefix "")) 108 (and fill-prefix (not (equal fill-prefix ""))
106 (not paragraph-ignore-fill-prefix) 109 (not paragraph-ignore-fill-prefix)
107 (regexp-quote fill-prefix))) 110 (regexp-quote fill-prefix)))
138 (progn (move-to-left-margin) 141 (progn (move-to-left-margin)
139 (looking-at paragraph-separate))) 142 (looking-at paragraph-separate)))
140 (forward-line -1)) 143 (forward-line -1))
141 (if (bobp) 144 (if (bobp)
142 nil 145 nil
143 (progn 146 ;; Go to end of the previous (non-separating) line.
144 ;; Go to end of the previous (non-separating) line. 147 (end-of-line)
145 (end-of-line) 148 ;; Search back for line that starts or separates paragraphs.
146 ;; Search back for line that starts or separates paragraphs. 149 (if (if fill-prefix-regexp
147 (if (if fill-prefix-regexp 150 ;; There is a fill prefix; it overrides paragraph-start.
148 ;; There is a fill prefix; it overrides paragraph-start.
149 (let (multiple-lines) 151 (let (multiple-lines)
150 (while (and (progn (beginning-of-line) (not (bobp))) 152 (while (and (progn (beginning-of-line) (not (bobp)))
151 (progn (move-to-left-margin) 153 (progn (move-to-left-margin)
152 (not (looking-at paragraph-separate))) 154 (not (looking-at paragraph-separate)))
153 (looking-at fill-prefix-regexp)) 155 (looking-at fill-prefix-regexp))
173 (and use-hard-newlines 175 (and use-hard-newlines
174 (not (get-text-property (1- start) 176 (not (get-text-property (1- start)
175 'hard))))) 177 'hard)))))
176 (goto-char start)) 178 (goto-char start))
177 (> (point) (point-min))) 179 (> (point) (point-min)))
178 ;; Found one. 180 ;; Found one.
179 (progn 181 (progn
180 ;; Move forward over paragraph separators. 182 ;; Move forward over paragraph separators.
181 ;; We know this cannot reach the place we started 183 ;; We know this cannot reach the place we started
182 ;; because we know we moved back over a non-separator. 184 ;; because we know we moved back over a non-separator.
183 (while (and (not (eobp)) 185 (while (and (not (eobp))
184 (progn (move-to-left-margin) 186 (progn (move-to-left-margin)
185 (looking-at paragraph-separate))) 187 (looking-at paragraph-separate)))
186 (forward-line 1)) 188 (forward-line 1))
187 ;; If line before paragraph is just margin, back up to there. 189 ;; If line before paragraph is just margin, back up to there.
188 (end-of-line 0) 190 (end-of-line 0)
189 (if (> (current-column) (current-left-margin)) 191 (if (> (current-column) (current-left-margin))
190 (forward-char 1) 192 (forward-char 1)
191 (skip-chars-backward " \t") 193 (skip-chars-backward " \t")
192 (if (not (bolp)) 194 (if (not (bolp))
193 (forward-line 1)))) 195 (forward-line 1))))
194 ;; No starter or separator line => use buffer beg. 196 ;; No starter or separator line => use buffer beg.
195 (goto-char (point-min)))))) 197 (goto-char (point-min)))))
196 (setq arg (1+ arg))) 198 (setq arg (1+ arg)))
197 (while (and (> arg 0) (not (eobp))) 199 (while (and (> arg 0) (not (eobp)))
200 ;; Move forward over separator lines, and one more line.
198 (while (prog1 (and (not (eobp)) 201 (while (prog1 (and (not (eobp))
199 (progn (move-to-left-margin) (not (eobp))) 202 (progn (move-to-left-margin) (not (eobp)))
200 (looking-at paragraph-separate)) 203 (looking-at paragraph-separate))
201 (forward-line 1))) 204 (forward-line 1)))
202 (if fill-prefix-regexp 205 (if fill-prefix-regexp
229 paragraph-separating line; except: if the first real line of a 232 paragraph-separating line; except: if the first real line of a
230 paragraph is preceded by a blank line, the paragraph starts at that 233 paragraph is preceded by a blank line, the paragraph starts at that
231 blank line. 234 blank line.
232 235
233 See `forward-paragraph' for more information." 236 See `forward-paragraph' for more information."
234 (interactive "_p") 237 (interactive "_p") ; XEmacs
235 (or arg (setq arg 1)) 238 (or arg (setq arg 1))
236 (forward-paragraph (- arg))) 239 (forward-paragraph (- arg)))
237 240
238 (defun mark-paragraph () 241 (defun mark-paragraph ()
239 "Put point at beginning of this paragraph, mark at end. 242 "Put point at beginning of this paragraph, mark at end.
245 248
246 (defun kill-paragraph (arg) 249 (defun kill-paragraph (arg)
247 "Kill forward to end of paragraph. 250 "Kill forward to end of paragraph.
248 With arg N, kill forward to Nth end of paragraph; 251 With arg N, kill forward to Nth end of paragraph;
249 negative arg -N means kill backward to Nth start of paragraph." 252 negative arg -N means kill backward to Nth start of paragraph."
250 (interactive "*p") 253 (interactive "*p") ; XEmacs
251 (kill-region (point) (progn (forward-paragraph arg) (point)))) 254 (kill-region (point) (progn (forward-paragraph arg) (point))))
252 255
253 (defun backward-kill-paragraph (arg) 256 (defun backward-kill-paragraph (arg)
254 "Kill back to start of paragraph. 257 "Kill back to start of paragraph.
255 With arg N, kill back to Nth start of paragraph; 258 With arg N, kill back to Nth start of paragraph;
256 negative arg -N means kill forward to Nth end of paragraph." 259 negative arg -N means kill forward to Nth end of paragraph."
257 (interactive "*p") 260 (interactive "*p") ; XEmacs
258 (kill-region (point) (progn (backward-paragraph arg) (point)))) 261 (kill-region (point) (progn (backward-paragraph arg) (point))))
259 262
260 (defun transpose-paragraphs (arg) 263 (defun transpose-paragraphs (arg)
261 "Interchange this (or next) paragraph with previous one." 264 "Interchange this (or next) paragraph with previous one."
262 (interactive "*p") 265 (interactive "*p")
289 292
290 (defun forward-sentence (&optional arg) 293 (defun forward-sentence (&optional arg)
291 "Move forward to next `sentence-end'. With argument, repeat. 294 "Move forward to next `sentence-end'. With argument, repeat.
292 With negative argument, move backward repeatedly to `sentence-beginning'. 295 With negative argument, move backward repeatedly to `sentence-beginning'.
293 296
294 The variable `sentence-end' is a regular expression that matches ends 297 The variable `sentence-end' is a regular expression that matches ends of
295 of sentences. Also, every paragraph boundary terminates sentences as 298 sentences. Also, every paragraph boundary terminates sentences as well."
296 well." 299 (interactive "_p") ; XEmacs
297 (interactive "_p")
298 (or arg (setq arg 1)) 300 (or arg (setq arg 1))
299 (while (< arg 0) 301 (while (< arg 0)
300 (let ((par-beg (save-excursion (start-of-paragraph-text) (point)))) 302 (let ((par-beg (save-excursion (start-of-paragraph-text) (point))))
301 (if (re-search-backward (concat sentence-end "[^ \t\n]") par-beg t) 303 (if (re-search-backward (concat sentence-end "[^ \t\n]") par-beg t)
302 (goto-char (1- (match-end 0))) 304 (goto-char (1- (match-end 0)))
310 (setq arg (1- arg)))) 312 (setq arg (1- arg))))
311 313
312 (defun backward-sentence (&optional arg) 314 (defun backward-sentence (&optional arg)
313 "Move backward to start of sentence. With arg, do it arg times. 315 "Move backward to start of sentence. With arg, do it arg times.
314 See `forward-sentence' for more information." 316 See `forward-sentence' for more information."
315 (interactive "_p") 317 (interactive "_p") ; XEmacs
316 (or arg (setq arg 1)) 318 (or arg (setq arg 1))
317 (forward-sentence (- arg))) 319 (forward-sentence (- arg)))
318 320
319 (defun kill-sentence (&optional arg) 321 (defun kill-sentence (&optional arg)
320 "Kill from point to end of sentence. 322 "Kill from point to end of sentence.
321 With arg, repeat; negative arg -N means kill back to Nth start of sentence." 323 With arg, repeat; negative arg -N means kill back to Nth start of sentence."
322 (interactive "p") 324 (interactive "*p") ; XEmacs
323 (kill-region (point) (progn (forward-sentence arg) (point)))) 325 (kill-region (point) (progn (forward-sentence arg) (point))))
324 326
325 (defun backward-kill-sentence (&optional arg) 327 (defun backward-kill-sentence (&optional arg)
326 "Kill back from point to start of sentence. 328 "Kill back from point to start of sentence.
327 With arg, repeat, or kill forward to Nth end of sentence if negative arg -N." 329 With arg, repeat, or kill forward to Nth end of sentence if negative arg -N."
328 (interactive "p") 330 (interactive "*p") ; XEmacs
329 (kill-region (point) (progn (backward-sentence arg) (point)))) 331 (kill-region (point) (progn (backward-sentence arg) (point))))
330 332
331 (defun mark-end-of-sentence (arg) 333 (defun mark-end-of-sentence (arg)
332 "Put mark at end of sentence. Arg works as in `forward-sentence'." 334 "Put mark at end of sentence. Arg works as in `forward-sentence'."
333 (interactive "p") 335 (interactive "p")
336 ;; FSF Version:
337 ; (push-mark
338 ; (save-excursion
339 ; (forward-sentence arg)
340 ; (point))
341 ; nil t))
334 (mark-something 'mark-end-of-sentence 'forward-sentence arg)) 342 (mark-something 'mark-end-of-sentence 'forward-sentence arg))
335 343
336 (defun transpose-sentences (arg) 344 (defun transpose-sentences (arg)
337 "Interchange this (next) and previous sentence." 345 "Interchange this (next) and previous sentence."
338 (interactive "*p") 346 (interactive "*p")
339 (transpose-subr 'forward-sentence arg)) 347 (transpose-subr 'forward-sentence arg))
340 348
341 ;;; paragraphs.el ends here 349 ;;; paragraphs.el ends here
342