annotate lisp/textmodes/paragraphs.el @ 14417:2b2e0cef30d5

(cpp-parse-error): Fix error format string.
author Karl Heuer <kwzh@gnu.org>
date Mon, 29 Jan 1996 23:11:17 +0000
parents 2110ae3ef540
children 99cc9a8dd157
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
659
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 269
diff changeset
1 ;;; paragraphs.el --- paragraph and sentence parsing.
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 269
diff changeset
2
11235
e6bdaaa6ce1b Update copyright.
Karl Heuer <kwzh@gnu.org>
parents: 10864
diff changeset
3 ;; Copyright (C) 1985, 86, 87, 91, 94, 95 Free Software Foundation, Inc.
845
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
4
789
71d052f72ac1 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 732
diff changeset
5 ;; Maintainer: FSF
814
38b2499cb3e9 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 804
diff changeset
6 ;; Keywords: wp
789
71d052f72ac1 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 732
diff changeset
7
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
9
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
804
33aaf4b71a1d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 789
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
13 ;; any later version.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
14
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
19
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12804
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12804
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12804
diff changeset
23 ;; Boston, MA 02111-1307, USA.
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
24
2308
f287613dfc28 Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1462
diff changeset
25 ;;; Commentary:
f287613dfc28 Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1462
diff changeset
26
f287613dfc28 Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1462
diff changeset
27 ;; This package provides the paragraph-oriented commands documented in the
f287613dfc28 Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1462
diff changeset
28 ;; Emacs manual.
f287613dfc28 Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1462
diff changeset
29
789
71d052f72ac1 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 732
diff changeset
30 ;;; Code:
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
31
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
32 (defvar use-hard-newlines nil
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
33 "Non-nil means to distinguish hard and soft newlines.
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
34 When this is non-nil, the functions `newline' and `open-line' add the
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
35 text-property `hard' to newlines that they insert. Also, a line is
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
36 only considered as a candidate to match `paragraph-start' or
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
37 `paragraph-separate' if it follows a hard newline. Newlines not
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
38 marked hard are called \"soft\", and are always internal to
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
39 paragraphs. The fill functions always insert soft newlines.
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
40
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
41 Each buffer has its own value of this variable.")
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
42 (make-variable-buffer-local 'use-hard-newlines)
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
43
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
44 (defconst paragraph-start "[ \t\n\f]" "\
4585
04e78c728252 (paragraph-start): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 2828
diff changeset
45 *Regexp for beginning of a line that starts OR separates paragraphs.
04e78c728252 (paragraph-start): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 2828
diff changeset
46 This regexp should match lines that separate paragraphs
04e78c728252 (paragraph-start): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 2828
diff changeset
47 and should also match lines that start a paragraph
04e78c728252 (paragraph-start): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 2828
diff changeset
48 \(and are part of that paragraph).
10424
6bcb93cec6f8 (forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents: 9169
diff changeset
49
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
50 This is matched against the text at the left margin, which is not necessarily
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
51 the beginning of the line, so it should never use \"^\" as an anchor. This
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
52 ensures that the paragraph functions will work equally well within a region
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
53 of text indented by a margin setting.
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
54
4585
04e78c728252 (paragraph-start): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 2828
diff changeset
55 The variable `paragraph-separate' specifies how to distinguish
10424
6bcb93cec6f8 (forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents: 9169
diff changeset
56 lines that start paragraphs from lines that separate them.
6bcb93cec6f8 (forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents: 9169
diff changeset
57
6bcb93cec6f8 (forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents: 9169
diff changeset
58 If the variable `use-hard-newlines' is nonnil, then only lines following a
6bcb93cec6f8 (forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents: 9169
diff changeset
59 hard newline are considered to match.")
264
7db4ff4204a5 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 237
diff changeset
60
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
61 ;; paragraph-start requires a hard newline, but paragraph-separate does not:
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
62 ;; It is assumed that paragraph-separate is distinctive enough to be believed
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
63 ;; whenever it occurs, while it is reasonable to set paragraph-start to
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
64 ;; something very minimal, even including "." (which makes every hard newline
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
65 ;; start a new paragraph).
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
66
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
67 (defconst paragraph-separate "[ \t\f]*$" "\
269
2ca8cdb96a9f *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 264
diff changeset
68 *Regexp for beginning of a line that separates paragraphs.
10424
6bcb93cec6f8 (forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents: 9169
diff changeset
69 If you change this, you may have to change paragraph-start also.
6bcb93cec6f8 (forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents: 9169
diff changeset
70
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
71 This is matched against the text at the left margin, which is not necessarily
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
72 the beginning of the line, so it should not use \"^\" as an anchor. This
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
73 ensures that the paragraph functions will work equally within a region of
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
74 text indented by a margin setting.")
264
7db4ff4204a5 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 237
diff changeset
75
269
2ca8cdb96a9f *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 264
diff changeset
76 (defconst sentence-end (purecopy "[.?!][]\"')}]*\\($\\| $\\|\t\\| \\)[ \t\n]*") "\
2ca8cdb96a9f *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 264
diff changeset
77 *Regexp describing the end of a sentence.
2503
fb3509fdf8b7 Sat Apr 10 00:39:29 1993 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents: 2308
diff changeset
78 All paragraph boundaries also end sentences, regardless.
fb3509fdf8b7 Sat Apr 10 00:39:29 1993 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents: 2308
diff changeset
79
fb3509fdf8b7 Sat Apr 10 00:39:29 1993 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents: 2308
diff changeset
80 In order to be recognized as the end of a sentence, the ending period,
fb3509fdf8b7 Sat Apr 10 00:39:29 1993 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents: 2308
diff changeset
81 question mark, or exclamation point must be followed by two spaces,
fb3509fdf8b7 Sat Apr 10 00:39:29 1993 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents: 2308
diff changeset
82 unless it's inside some sort of quotes or parenthesis.")
264
7db4ff4204a5 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 237
diff changeset
83
269
2ca8cdb96a9f *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 264
diff changeset
84 (defconst page-delimiter "^\014" "\
2ca8cdb96a9f *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 264
diff changeset
85 *Regexp describing line-beginnings that separate pages.")
264
7db4ff4204a5 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 237
diff changeset
86
269
2ca8cdb96a9f *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 264
diff changeset
87 (defvar paragraph-ignore-fill-prefix nil "\
2ca8cdb96a9f *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 264
diff changeset
88 Non-nil means the paragraph commands are not affected by `fill-prefix'.
2ca8cdb96a9f *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 264
diff changeset
89 This is desirable in modes where blank lines are the paragraph delimiters.")
264
7db4ff4204a5 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 237
diff changeset
90
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
91 (defun forward-paragraph (&optional arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
92 "Move forward to end of paragraph.
5653
db6bea4e5345 (forward-paragraph): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5608
diff changeset
93 With arg N, do it N times; negative arg -N means move backward N paragraphs.
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
94
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
95 A line which `paragraph-start' matches either separates paragraphs
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
96 \(if `paragraph-separate' matches it also) or is the first line of a paragraph.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
97 A paragraph end is the beginning of a line which is not part of the paragraph
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
98 to which the end of the previous line belongs, or the end of the buffer."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
99 (interactive "p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
100 (or arg (setq arg 1))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
101 (let* ((fill-prefix-regexp
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
102 (and fill-prefix (not (equal fill-prefix ""))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
103 (not paragraph-ignore-fill-prefix)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
104 (regexp-quote fill-prefix)))
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
105 ;; Remove ^ from paragraph-start and paragraph-sep if they are there.
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
106 ;; These regexps shouldn't be anchored, because we look for them
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
107 ;; starting at the left-margin. This allows paragraph commands to
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
108 ;; work normally with indented text.
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
109 ;; This hack will not find problem cases like "whatever\\|^something".
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
110 (paragraph-start (if (and (not (equal "" paragraph-start))
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
111 (equal ?^ (aref paragraph-start 0)))
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
112 (substring paragraph-start 1)
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
113 paragraph-start))
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
114 (paragraph-separate (if (and (not (equal "" paragraph-start))
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
115 (equal ?^ (aref paragraph-separate 0)))
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
116 (substring paragraph-separate 1)
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
117 paragraph-separate))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
118 (paragraph-separate
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
119 (if fill-prefix-regexp
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
120 (concat paragraph-separate "\\|"
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
121 fill-prefix-regexp "[ \t]*$")
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
122 paragraph-separate))
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
123 ;; This is used for searching.
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
124 (sp-paragraph-start (concat "^[ \t]*\\(" paragraph-start "\\)"))
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
125 start)
5608
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
126 (while (and (< arg 0) (not (bobp)))
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
127 (if (and (not (looking-at paragraph-separate))
10424
6bcb93cec6f8 (forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents: 9169
diff changeset
128 (re-search-backward "^\n" (max (1- (point)) (point-min)) t)
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
129 (looking-at paragraph-separate))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
130 nil
12717
8e153c7bbd90 (forward-paragraph): Don't move back over a line
Richard M. Stallman <rms@gnu.org>
parents: 11235
diff changeset
131 (setq start (point))
5608
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
132 ;; Move back over paragraph-separating lines.
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
133 (forward-char -1) (beginning-of-line)
10424
6bcb93cec6f8 (forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents: 9169
diff changeset
134 (while (and (not (bobp))
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
135 (progn (move-to-left-margin)
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
136 (looking-at paragraph-separate)))
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
137 (forward-line -1))
5608
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
138 (if (bobp)
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
139 nil
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
140 ;; Go to end of the previous (non-separating) line.
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
141 (end-of-line)
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
142 ;; Search back for line that starts or separates paragraphs.
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
143 (if (if fill-prefix-regexp
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
144 ;; There is a fill prefix; it overrides paragraph-start.
12717
8e153c7bbd90 (forward-paragraph): Don't move back over a line
Richard M. Stallman <rms@gnu.org>
parents: 11235
diff changeset
145 (let (multiple-lines)
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
146 (while (and (progn (beginning-of-line) (not (bobp)))
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
147 (progn (move-to-left-margin)
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
148 (not (looking-at paragraph-separate)))
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
149 (looking-at fill-prefix-regexp))
12717
8e153c7bbd90 (forward-paragraph): Don't move back over a line
Richard M. Stallman <rms@gnu.org>
parents: 11235
diff changeset
150 (if (not (= (point) start))
8e153c7bbd90 (forward-paragraph): Don't move back over a line
Richard M. Stallman <rms@gnu.org>
parents: 11235
diff changeset
151 (setq multiple-lines t))
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
152 (forward-line -1))
12717
8e153c7bbd90 (forward-paragraph): Don't move back over a line
Richard M. Stallman <rms@gnu.org>
parents: 11235
diff changeset
153 (move-to-left-margin)
8e153c7bbd90 (forward-paragraph): Don't move back over a line
Richard M. Stallman <rms@gnu.org>
parents: 11235
diff changeset
154 ;; Don't move back over a line before the paragraph
8e153c7bbd90 (forward-paragraph): Don't move back over a line
Richard M. Stallman <rms@gnu.org>
parents: 11235
diff changeset
155 ;; which doesn't start with fill-prefix
8e153c7bbd90 (forward-paragraph): Don't move back over a line
Richard M. Stallman <rms@gnu.org>
parents: 11235
diff changeset
156 ;; unless that is the only line we've moved over.
8e153c7bbd90 (forward-paragraph): Don't move back over a line
Richard M. Stallman <rms@gnu.org>
parents: 11235
diff changeset
157 (and (not (looking-at fill-prefix-regexp))
8e153c7bbd90 (forward-paragraph): Don't move back over a line
Richard M. Stallman <rms@gnu.org>
parents: 11235
diff changeset
158 multiple-lines
8e153c7bbd90 (forward-paragraph): Don't move back over a line
Richard M. Stallman <rms@gnu.org>
parents: 11235
diff changeset
159 (forward-line 1))
8e153c7bbd90 (forward-paragraph): Don't move back over a line
Richard M. Stallman <rms@gnu.org>
parents: 11235
diff changeset
160 (not (bobp)))
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
161 (while (and (re-search-backward sp-paragraph-start nil 1)
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
162 ;; Found a candidate, but need to check if it is a
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
163 ;; REAL paragraph-start.
10424
6bcb93cec6f8 (forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents: 9169
diff changeset
164 (not (bobp))
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
165 (progn (setq start (point))
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
166 (move-to-left-margin)
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
167 (not (looking-at paragraph-separate)))
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
168 (or (not (looking-at paragraph-start))
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
169 (and use-hard-newlines
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
170 (not (get-text-property (1- start)
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
171 'hard)))))
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
172 (goto-char start))
10424
6bcb93cec6f8 (forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents: 9169
diff changeset
173 (> (point) (point-min)))
5608
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
174 ;; Found one.
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
175 (progn
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
176 ;; Move forward over paragraph separators.
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
177 ;; We know this cannot reach the place we started
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
178 ;; because we know we moved back over a non-separator.
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
179 (while (and (not (eobp))
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
180 (progn (move-to-left-margin)
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
181 (looking-at paragraph-separate)))
5608
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
182 (forward-line 1))
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
183 ;; If line before paragraph is just margin, back up to there.
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
184 (end-of-line 0)
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
185 (if (> (current-column) (current-left-margin))
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
186 (forward-char 1)
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
187 (skip-chars-backward " \t")
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
188 (if (not (bolp))
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
189 (forward-line 1))))
5608
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
190 ;; No starter or separator line => use buffer beg.
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
191 (goto-char (point-min)))))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
192 (setq arg (1+ arg)))
5608
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
193 (while (and (> arg 0) (not (eobp)))
14378
2110ae3ef540 (forward-paragraph): Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
194 ;; Move forward over separator lines, and one more line.
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
195 (while (prog1 (and (not (eobp))
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
196 (progn (move-to-left-margin) (not (eobp)))
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
197 (looking-at paragraph-separate))
10424
6bcb93cec6f8 (forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents: 9169
diff changeset
198 (forward-line 1)))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
199 (if fill-prefix-regexp
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
200 ;; There is a fill prefix; it overrides paragraph-start.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
201 (while (and (not (eobp))
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
202 (progn (move-to-left-margin) (not (eobp)))
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
203 (not (looking-at paragraph-separate))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
204 (looking-at fill-prefix-regexp))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
205 (forward-line 1))
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
206 (while (and (re-search-forward sp-paragraph-start nil 1)
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
207 (progn (setq start (match-beginning 0))
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
208 (goto-char start)
12804
1619fcabdb99 (forward-paragraph): Don't overlook a paragraph-start
Richard M. Stallman <rms@gnu.org>
parents: 12717
diff changeset
209 (not (eobp)))
1619fcabdb99 (forward-paragraph): Don't overlook a paragraph-start
Richard M. Stallman <rms@gnu.org>
parents: 12717
diff changeset
210 (progn (move-to-left-margin)
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
211 (not (looking-at paragraph-separate)))
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
212 (or (not (looking-at paragraph-start))
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
213 (and use-hard-newlines
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
214 (not (get-text-property (1- start) 'hard)))))
10424
6bcb93cec6f8 (forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents: 9169
diff changeset
215 (forward-char 1))
6bcb93cec6f8 (forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents: 9169
diff changeset
216 (if (< (point) (point-max))
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
217 (goto-char start)))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
218 (setq arg (1- arg)))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
219
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
220 (defun backward-paragraph (&optional arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
221 "Move backward to start of paragraph.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
222 With arg N, do it N times; negative arg -N means move forward N paragraphs.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
223
237
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
224 A paragraph start is the beginning of a line which is a
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
225 `first-line-of-paragraph' or which is ordinary text and follows a
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
226 paragraph-separating line; except: if the first real line of a
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
227 paragraph is preceded by a blank line, the paragraph starts at that
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
228 blank line.
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
229
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
230 See `forward-paragraph' for more information."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
231 (interactive "p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
232 (or arg (setq arg 1))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
233 (forward-paragraph (- arg)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
234
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
235 (defun mark-paragraph ()
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
236 "Put point at beginning of this paragraph, mark at end.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
237 The paragraph marked is the one that contains point or follows point."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
238 (interactive)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
239 (forward-paragraph 1)
2827
0daa9d777306 (mark-paragraph): Activate the mark.
Richard M. Stallman <rms@gnu.org>
parents: 2503
diff changeset
240 (push-mark nil t t)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
241 (backward-paragraph 1))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
242
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
243 (defun kill-paragraph (arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
244 "Kill forward to end of paragraph.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
245 With arg N, kill forward to Nth end of paragraph;
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
246 negative arg -N means kill backward to Nth start of paragraph."
237
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
247 (interactive "p")
7064
19a84bb30e9e (kill-paragraph): Don't use save-excursion.
Richard M. Stallman <rms@gnu.org>
parents: 5653
diff changeset
248 (kill-region (point) (progn (forward-paragraph arg) (point))))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
249
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
250 (defun backward-kill-paragraph (arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
251 "Kill back to start of paragraph.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
252 With arg N, kill back to Nth start of paragraph;
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
253 negative arg -N means kill forward to Nth end of paragraph."
237
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
254 (interactive "p")
7064
19a84bb30e9e (kill-paragraph): Don't use save-excursion.
Richard M. Stallman <rms@gnu.org>
parents: 5653
diff changeset
255 (kill-region (point) (progn (backward-paragraph arg) (point))))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
256
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
257 (defun transpose-paragraphs (arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
258 "Interchange this (or next) paragraph with previous one."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
259 (interactive "*p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
260 (transpose-subr 'forward-paragraph arg))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
261
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
262 (defun start-of-paragraph-text ()
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
263 (let ((opoint (point)) npoint)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
264 (forward-paragraph -1)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
265 (setq npoint (point))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
266 (skip-chars-forward " \t\n")
68
7680293d57f3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
267 ;; If the range of blank lines found spans the original start point,
7680293d57f3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
268 ;; try again from the beginning of it.
7680293d57f3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
269 ;; Must be careful to avoid infinite loop
7680293d57f3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
270 ;; when following a single return at start of buffer.
7680293d57f3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
271 (if (and (>= (point) opoint) (< npoint opoint))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
272 (progn
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
273 (goto-char npoint)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
274 (if (> npoint (point-min))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
275 (start-of-paragraph-text))))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
276
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
277 (defun end-of-paragraph-text ()
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
278 (let ((opoint (point)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
279 (forward-paragraph 1)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
280 (if (eq (preceding-char) ?\n) (forward-char -1))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
281 (if (<= (point) opoint)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
282 (progn
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
283 (forward-char 1)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
284 (if (< (point) (point-max))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
285 (end-of-paragraph-text))))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
286
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
287 (defun forward-sentence (&optional arg)
2503
fb3509fdf8b7 Sat Apr 10 00:39:29 1993 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents: 2308
diff changeset
288 "Move forward to next `sentence-end'. With argument, repeat.
237
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
289 With negative argument, move backward repeatedly to `sentence-beginning'.
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
290
237
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
291 The variable `sentence-end' is a regular expression that matches ends of
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
292 sentences. Also, every paragraph boundary terminates sentences as well."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
293 (interactive "p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
294 (or arg (setq arg 1))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
295 (while (< arg 0)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
296 (let ((par-beg (save-excursion (start-of-paragraph-text) (point))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
297 (if (re-search-backward (concat sentence-end "[^ \t\n]") par-beg t)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
298 (goto-char (1- (match-end 0)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
299 (goto-char par-beg)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
300 (setq arg (1+ arg)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
301 (while (> arg 0)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
302 (let ((par-end (save-excursion (end-of-paragraph-text) (point))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
303 (if (re-search-forward sentence-end par-end t)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
304 (skip-chars-backward " \t\n")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
305 (goto-char par-end)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
306 (setq arg (1- arg))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
307
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
308 (defun backward-sentence (&optional arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
309 "Move backward to start of sentence. With arg, do it arg times.
237
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
310 See `forward-sentence' for more information."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
311 (interactive "p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
312 (or arg (setq arg 1))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
313 (forward-sentence (- arg)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
314
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
315 (defun kill-sentence (&optional arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
316 "Kill from point to end of sentence.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
317 With arg, repeat; negative arg -N means kill back to Nth start of sentence."
9169
edc1c9086c5c (backward-kill-sentence): Work in read-only buffers.
Richard M. Stallman <rms@gnu.org>
parents: 7300
diff changeset
318 (interactive "p")
7064
19a84bb30e9e (kill-paragraph): Don't use save-excursion.
Richard M. Stallman <rms@gnu.org>
parents: 5653
diff changeset
319 (kill-region (point) (progn (forward-sentence arg) (point))))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
320
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
321 (defun backward-kill-sentence (&optional arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
322 "Kill back from point to start of sentence.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
323 With arg, repeat, or kill forward to Nth end of sentence if negative arg -N."
9169
edc1c9086c5c (backward-kill-sentence): Work in read-only buffers.
Richard M. Stallman <rms@gnu.org>
parents: 7300
diff changeset
324 (interactive "p")
7064
19a84bb30e9e (kill-paragraph): Don't use save-excursion.
Richard M. Stallman <rms@gnu.org>
parents: 5653
diff changeset
325 (kill-region (point) (progn (backward-sentence arg) (point))))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
326
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
327 (defun mark-end-of-sentence (arg)
237
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
328 "Put mark at end of sentence. Arg works as in `forward-sentence'."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
329 (interactive "p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
330 (push-mark
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
331 (save-excursion
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
332 (forward-sentence arg)
2828
abc6df78588f (mark-end-of-sentence): Activate the mark.
Richard M. Stallman <rms@gnu.org>
parents: 2827
diff changeset
333 (point))
abc6df78588f (mark-end-of-sentence): Activate the mark.
Richard M. Stallman <rms@gnu.org>
parents: 2827
diff changeset
334 nil t))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
335
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
336 (defun transpose-sentences (arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
337 "Interchange this (next) and previous sentence."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
338 (interactive "*p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
339 (transpose-subr 'forward-sentence arg))
659
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 269
diff changeset
340
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 269
diff changeset
341 ;;; paragraphs.el ends here