Mercurial > hg > xemacs-beta
comparison lisp/prim/paragraphs.el @ 4:b82b59fe008d r19-15b3
Import from CVS: tag r19-15b3
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:46:56 +0200 |
parents | 376386a54a3c |
children | ec9a17fef872 |
comparison
equal
deleted
inserted
replaced
3:30df88044ec6 | 4:b82b59fe008d |
---|---|
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. |
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 Free | 21 ;; along with XEmacs; see the file COPYING. If not, write to the Free |
23 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
24 | 23 ;; 02111-1307, USA. |
25 ;;; Synched up with: FSF 19.30. | 24 |
25 ;;; Synched up with: FSF 19.34. | |
26 | 26 |
27 ;;; Commentary: | 27 ;;; Commentary: |
28 | 28 |
29 ;; This package provides the paragraph-oriented commands documented in the | 29 ;; This package provides the paragraph-oriented commands documented in the |
30 ;; XEmacs Reference Manual. | 30 ;; XEmacs Reference Manual. |
41 paragraphs. The fill functions always insert soft newlines. | 41 paragraphs. The fill functions always insert soft newlines. |
42 | 42 |
43 Each buffer has its own value of this variable.") | 43 Each buffer has its own value of this variable.") |
44 (make-variable-buffer-local 'use-hard-newlines) | 44 (make-variable-buffer-local 'use-hard-newlines) |
45 | 45 |
46 ;; XEmacs - use purecopy | |
46 (defconst paragraph-start (purecopy "[ \t\n\f]") "\ | 47 (defconst paragraph-start (purecopy "[ \t\n\f]") "\ |
47 *Regexp for beginning of a line that starts OR separates paragraphs. | 48 *Regexp for beginning of a line that starts OR separates paragraphs. |
48 This regexp should match lines that separate paragraphs | 49 This regexp should match lines that separate paragraphs |
49 and should also match lines that start a paragraph | 50 and should also match lines that start a paragraph |
50 \(and are part of that paragraph). | 51 \(and are part of that paragraph). |
64 ;; 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 |
65 ;; 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 |
66 ;; something very minimal, even including "." (which makes every hard newline | 67 ;; something very minimal, even including "." (which makes every hard newline |
67 ;; start a new paragraph). | 68 ;; start a new paragraph). |
68 | 69 |
70 ;; XEmacs -- use purecopy | |
69 (defconst paragraph-separate (purecopy "[ \t\f]*$") "\ | 71 (defconst paragraph-separate (purecopy "[ \t\f]*$") "\ |
70 *Regexp for beginning of a line that separates paragraphs. | 72 *Regexp for beginning of a line that separates paragraphs. |
71 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. |
72 | 74 |
73 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 |
74 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 |
75 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 |
76 text indented by a margin setting.") | 78 text indented by a margin setting.") |
77 | 79 |
80 ;; XEmacs -- use purecopy | |
78 (defconst sentence-end (purecopy "[.?!][]\"')}]*\\($\\| $\\|\t\\| \\)[ \t\n]*") "\ | 81 (defconst sentence-end (purecopy "[.?!][]\"')}]*\\($\\| $\\|\t\\| \\)[ \t\n]*") "\ |
79 *Regexp describing the end of a sentence. | 82 *Regexp describing the end of a sentence. |
80 All paragraph boundaries also end sentences, regardless. | 83 All paragraph boundaries also end sentences, regardless. |
81 | 84 |
82 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, |
83 question mark, or exclamation point must be followed by two spaces, | 86 question mark, or exclamation point must be followed by two spaces, |
84 unless it's inside some sort of quotes or parenthesis.") | 87 unless it's inside some sort of quotes or parenthesis.") |
85 | 88 |
89 ;; XEmacs -- use purecopy | |
86 (defconst page-delimiter (purecopy "^\014") "\ | 90 (defconst page-delimiter (purecopy "^\014") "\ |
87 *Regexp describing line-beginnings that separate pages.") | 91 *Regexp describing line-beginnings that separate pages.") |
88 | 92 |
89 (defvar paragraph-ignore-fill-prefix nil "\ | 93 (defvar paragraph-ignore-fill-prefix nil "\ |
90 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'. |
96 | 100 |
97 A line which `paragraph-start' matches either separates paragraphs | 101 A line which `paragraph-start' matches either separates paragraphs |
98 \(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. |
99 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 |
100 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." |
101 (interactive "_p") | 105 (interactive "_p") ; XEmacs |
102 (or arg (setq arg 1)) | 106 (or arg (setq arg 1)) |
103 (let* ((fill-prefix-regexp | 107 (let* ((fill-prefix-regexp |
104 (and fill-prefix (not (equal fill-prefix "")) | 108 (and fill-prefix (not (equal fill-prefix "")) |
105 (not paragraph-ignore-fill-prefix) | 109 (not paragraph-ignore-fill-prefix) |
106 (regexp-quote fill-prefix))) | 110 (regexp-quote fill-prefix))) |
137 (progn (move-to-left-margin) | 141 (progn (move-to-left-margin) |
138 (looking-at paragraph-separate))) | 142 (looking-at paragraph-separate))) |
139 (forward-line -1)) | 143 (forward-line -1)) |
140 (if (bobp) | 144 (if (bobp) |
141 nil | 145 nil |
142 (progn | 146 ;; Go to end of the previous (non-separating) line. |
143 ;; Go to end of the previous (non-separating) line. | 147 (end-of-line) |
144 (end-of-line) | 148 ;; Search back for line that starts or separates paragraphs. |
145 ;; Search back for line that starts or separates paragraphs. | 149 (if (if fill-prefix-regexp |
146 (if (if fill-prefix-regexp | 150 ;; There is a fill prefix; it overrides paragraph-start. |
147 ;; There is a fill prefix; it overrides paragraph-start. | |
148 (let (multiple-lines) | 151 (let (multiple-lines) |
149 (while (and (progn (beginning-of-line) (not (bobp))) | 152 (while (and (progn (beginning-of-line) (not (bobp))) |
150 (progn (move-to-left-margin) | 153 (progn (move-to-left-margin) |
151 (not (looking-at paragraph-separate))) | 154 (not (looking-at paragraph-separate))) |
152 (looking-at fill-prefix-regexp)) | 155 (looking-at fill-prefix-regexp)) |
172 (and use-hard-newlines | 175 (and use-hard-newlines |
173 (not (get-text-property (1- start) | 176 (not (get-text-property (1- start) |
174 'hard))))) | 177 'hard))))) |
175 (goto-char start)) | 178 (goto-char start)) |
176 (> (point) (point-min))) | 179 (> (point) (point-min))) |
177 ;; Found one. | 180 ;; Found one. |
178 (progn | 181 (progn |
179 ;; Move forward over paragraph separators. | 182 ;; Move forward over paragraph separators. |
180 ;; We know this cannot reach the place we started | 183 ;; We know this cannot reach the place we started |
181 ;; because we know we moved back over a non-separator. | 184 ;; because we know we moved back over a non-separator. |
182 (while (and (not (eobp)) | 185 (while (and (not (eobp)) |
183 (progn (move-to-left-margin) | 186 (progn (move-to-left-margin) |
184 (looking-at paragraph-separate))) | 187 (looking-at paragraph-separate))) |
185 (forward-line 1)) | 188 (forward-line 1)) |
186 ;; If line before paragraph is just margin, back up to there. | 189 ;; If line before paragraph is just margin, back up to there. |
187 (end-of-line 0) | 190 (end-of-line 0) |
188 (if (> (current-column) (current-left-margin)) | 191 (if (> (current-column) (current-left-margin)) |
189 (forward-char 1) | 192 (forward-char 1) |
190 (skip-chars-backward " \t") | 193 (skip-chars-backward " \t") |
191 (if (not (bolp)) | 194 (if (not (bolp)) |
192 (forward-line 1)))) | 195 (forward-line 1)))) |
193 ;; No starter or separator line => use buffer beg. | 196 ;; No starter or separator line => use buffer beg. |
194 (goto-char (point-min)))))) | 197 (goto-char (point-min))))) |
195 (setq arg (1+ arg))) | 198 (setq arg (1+ arg))) |
196 (while (and (> arg 0) (not (eobp))) | 199 (while (and (> arg 0) (not (eobp))) |
200 ;; Move forward over separator lines, and one more line. | |
197 (while (prog1 (and (not (eobp)) | 201 (while (prog1 (and (not (eobp)) |
198 (progn (move-to-left-margin) (not (eobp))) | 202 (progn (move-to-left-margin) (not (eobp))) |
199 (looking-at paragraph-separate)) | 203 (looking-at paragraph-separate)) |
200 (forward-line 1))) | 204 (forward-line 1))) |
201 (if fill-prefix-regexp | 205 (if fill-prefix-regexp |
228 paragraph-separating line; except: if the first real line of a | 232 paragraph-separating line; except: if the first real line of a |
229 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 |
230 blank line. | 234 blank line. |
231 | 235 |
232 See `forward-paragraph' for more information." | 236 See `forward-paragraph' for more information." |
233 (interactive "_p") | 237 (interactive "_p") ; XEmacs |
234 (or arg (setq arg 1)) | 238 (or arg (setq arg 1)) |
235 (forward-paragraph (- arg))) | 239 (forward-paragraph (- arg))) |
236 | 240 |
237 (defun mark-paragraph () | 241 (defun mark-paragraph () |
238 "Put point at beginning of this paragraph, mark at end. | 242 "Put point at beginning of this paragraph, mark at end. |
244 | 248 |
245 (defun kill-paragraph (arg) | 249 (defun kill-paragraph (arg) |
246 "Kill forward to end of paragraph. | 250 "Kill forward to end of paragraph. |
247 With arg N, kill forward to Nth end of paragraph; | 251 With arg N, kill forward to Nth end of paragraph; |
248 negative arg -N means kill backward to Nth start of paragraph." | 252 negative arg -N means kill backward to Nth start of paragraph." |
249 (interactive "*p") | 253 (interactive "*p") ; XEmacs |
250 (kill-region (point) (progn (forward-paragraph arg) (point)))) | 254 (kill-region (point) (progn (forward-paragraph arg) (point)))) |
251 | 255 |
252 (defun backward-kill-paragraph (arg) | 256 (defun backward-kill-paragraph (arg) |
253 "Kill back to start of paragraph. | 257 "Kill back to start of paragraph. |
254 With arg N, kill back to Nth start of paragraph; | 258 With arg N, kill back to Nth start of paragraph; |
255 negative arg -N means kill forward to Nth end of paragraph." | 259 negative arg -N means kill forward to Nth end of paragraph." |
256 (interactive "*p") | 260 (interactive "*p") ; XEmacs |
257 (kill-region (point) (progn (backward-paragraph arg) (point)))) | 261 (kill-region (point) (progn (backward-paragraph arg) (point)))) |
258 | 262 |
259 (defun transpose-paragraphs (arg) | 263 (defun transpose-paragraphs (arg) |
260 "Interchange this (or next) paragraph with previous one." | 264 "Interchange this (or next) paragraph with previous one." |
261 (interactive "*p") | 265 (interactive "*p") |
288 | 292 |
289 (defun forward-sentence (&optional arg) | 293 (defun forward-sentence (&optional arg) |
290 "Move forward to next `sentence-end'. With argument, repeat. | 294 "Move forward to next `sentence-end'. With argument, repeat. |
291 With negative argument, move backward repeatedly to `sentence-beginning'. | 295 With negative argument, move backward repeatedly to `sentence-beginning'. |
292 | 296 |
293 The variable `sentence-end' is a regular expression that matches ends | 297 The variable `sentence-end' is a regular expression that matches ends of |
294 of sentences. Also, every paragraph boundary terminates sentences as | 298 sentences. Also, every paragraph boundary terminates sentences as well." |
295 well." | 299 (interactive "_p") ; XEmacs |
296 (interactive "_p") | |
297 (or arg (setq arg 1)) | 300 (or arg (setq arg 1)) |
298 (while (< arg 0) | 301 (while (< arg 0) |
299 (let ((par-beg (save-excursion (start-of-paragraph-text) (point)))) | 302 (let ((par-beg (save-excursion (start-of-paragraph-text) (point)))) |
300 (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) |
301 (goto-char (1- (match-end 0))) | 304 (goto-char (1- (match-end 0))) |
309 (setq arg (1- arg)))) | 312 (setq arg (1- arg)))) |
310 | 313 |
311 (defun backward-sentence (&optional arg) | 314 (defun backward-sentence (&optional arg) |
312 "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. |
313 See `forward-sentence' for more information." | 316 See `forward-sentence' for more information." |
314 (interactive "_p") | 317 (interactive "_p") ; XEmacs |
315 (or arg (setq arg 1)) | 318 (or arg (setq arg 1)) |
316 (forward-sentence (- arg))) | 319 (forward-sentence (- arg))) |
317 | 320 |
318 (defun kill-sentence (&optional arg) | 321 (defun kill-sentence (&optional arg) |
319 "Kill from point to end of sentence. | 322 "Kill from point to end of sentence. |
320 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." |
321 (interactive "p") | 324 (interactive "*p") ; XEmacs |
322 (kill-region (point) (progn (forward-sentence arg) (point)))) | 325 (kill-region (point) (progn (forward-sentence arg) (point)))) |
323 | 326 |
324 (defun backward-kill-sentence (&optional arg) | 327 (defun backward-kill-sentence (&optional arg) |
325 "Kill back from point to start of sentence. | 328 "Kill back from point to start of sentence. |
326 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." |
327 (interactive "p") | 330 (interactive "*p") ; XEmacs |
328 (kill-region (point) (progn (backward-sentence arg) (point)))) | 331 (kill-region (point) (progn (backward-sentence arg) (point)))) |
329 | 332 |
330 (defun mark-end-of-sentence (arg) | 333 (defun mark-end-of-sentence (arg) |
331 "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'." |
332 (interactive "p") | 335 (interactive "p") |
336 ;; FSF Version: | |
337 ; (push-mark | |
338 ; (save-excursion | |
339 ; (forward-sentence arg) | |
340 ; (point)) | |
341 ; nil t)) | |
333 (mark-something 'mark-end-of-sentence 'forward-sentence arg)) | 342 (mark-something 'mark-end-of-sentence 'forward-sentence arg)) |
334 | 343 |
335 (defun transpose-sentences (arg) | 344 (defun transpose-sentences (arg) |
336 "Interchange this (next) and previous sentence." | 345 "Interchange this (next) and previous sentence." |
337 (interactive "*p") | 346 (interactive "*p") |
338 (transpose-subr 'forward-sentence arg)) | 347 (transpose-subr 'forward-sentence arg)) |
339 | 348 |
340 ;;; paragraphs.el ends here | 349 ;;; paragraphs.el ends here |
341 |