annotate lisp/paragraphs.el @ 1929:7999c3afeac9

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