Mercurial > emacs
annotate lisp/textmodes/paragraphs.el @ 11102:2484f8186e34
New magic number for text/enriched files.
author | Boris Goldowsky <boris@gnu.org> |
---|---|
date | Thu, 23 Mar 1995 14:09:34 +0000 |
parents | 33769cbeb58e |
children | e6bdaaa6ce1b |
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 |
7300 | 3 ;; Copyright (C) 1985, 86, 87, 91, 94 Free Software Foundation, Inc. |
845 | 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 | 8 ;; This file is part of GNU Emacs. |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
804 | 12 ;; the Free Software Foundation; either version 2, or (at your option) |
36 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
2308
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1462
diff
changeset
|
24 ;;; Commentary: |
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1462
diff
changeset
|
25 |
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1462
diff
changeset
|
26 ;; 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
|
27 ;; Emacs manual. |
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1462
diff
changeset
|
28 |
789
71d052f72ac1
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
29 ;;; Code: |
36 | 30 |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
31 (defvar use-hard-newlines nil |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
32 "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
|
33 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
|
34 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
|
35 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
|
36 `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
|
37 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
|
38 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
|
39 |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
40 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
|
41 (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
|
42 |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
43 (defconst paragraph-start "[ \t\n\f]" "\ |
4585
04e78c728252
(paragraph-start): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
2828
diff
changeset
|
44 *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
|
45 This regexp should match lines that separate paragraphs |
04e78c728252
(paragraph-start): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
2828
diff
changeset
|
46 and should also match lines that start a paragraph |
04e78c728252
(paragraph-start): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
2828
diff
changeset
|
47 \(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
|
48 |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
49 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
|
50 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
|
51 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
|
52 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
|
53 |
4585
04e78c728252
(paragraph-start): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
2828
diff
changeset
|
54 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
|
55 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
|
56 |
6bcb93cec6f8
(forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents:
9169
diff
changeset
|
57 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
|
58 hard newline are considered to match.") |
264 | 59 |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
60 ;; 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
|
61 ;; 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
|
62 ;; 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
|
63 ;; 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
|
64 ;; start a new paragraph). |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
65 |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
66 (defconst paragraph-separate "[ \t\f]*$" "\ |
269 | 67 *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
|
68 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
|
69 |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
70 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
|
71 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
|
72 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
|
73 text indented by a margin setting.") |
264 | 74 |
269 | 75 (defconst sentence-end (purecopy "[.?!][]\"')}]*\\($\\| $\\|\t\\| \\)[ \t\n]*") "\ |
76 *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
|
77 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
|
78 |
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 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
|
80 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
|
81 unless it's inside some sort of quotes or parenthesis.") |
264 | 82 |
269 | 83 (defconst page-delimiter "^\014" "\ |
84 *Regexp describing line-beginnings that separate pages.") | |
264 | 85 |
269 | 86 (defvar paragraph-ignore-fill-prefix nil "\ |
87 Non-nil means the paragraph commands are not affected by `fill-prefix'. | |
88 This is desirable in modes where blank lines are the paragraph delimiters.") | |
264 | 89 |
36 | 90 (defun forward-paragraph (&optional arg) |
91 "Move forward to end of paragraph. | |
5653
db6bea4e5345
(forward-paragraph): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
5608
diff
changeset
|
92 With arg N, do it N times; negative arg -N means move backward N paragraphs. |
36 | 93 |
94 A line which `paragraph-start' matches either separates paragraphs | |
95 \(if `paragraph-separate' matches it also) or is the first line of a paragraph. | |
96 A paragraph end is the beginning of a line which is not part of the paragraph | |
97 to which the end of the previous line belongs, or the end of the buffer." | |
98 (interactive "p") | |
99 (or arg (setq arg 1)) | |
100 (let* ((fill-prefix-regexp | |
101 (and fill-prefix (not (equal fill-prefix "")) | |
102 (not paragraph-ignore-fill-prefix) | |
103 (regexp-quote fill-prefix))) | |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
104 ;; 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
|
105 ;; 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
|
106 ;; 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
|
107 ;; work normally with indented text. |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
108 ;; 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
|
109 (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
|
110 (equal ?^ (aref paragraph-start 0))) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
111 (substring paragraph-start 1) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
112 paragraph-start)) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
113 (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
|
114 (equal ?^ (aref paragraph-separate 0))) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
115 (substring paragraph-separate 1) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
116 paragraph-separate)) |
36 | 117 (paragraph-separate |
118 (if fill-prefix-regexp | |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
119 (concat paragraph-separate "\\|" |
36 | 120 fill-prefix-regexp "[ \t]*$") |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
121 paragraph-separate)) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
122 ;; This is used for searching. |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
123 (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
|
124 start) |
5608
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
125 (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
|
126 (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
|
127 (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
|
128 (looking-at paragraph-separate)) |
36 | 129 nil |
5608
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
130 ;; Move back over paragraph-separating lines. |
36 | 131 (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
|
132 (while (and (not (bobp)) |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
133 (progn (move-to-left-margin) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
134 (looking-at paragraph-separate))) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
135 (forward-line -1)) |
5608
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
136 (if (bobp) |
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
137 nil |
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
138 ;; 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
|
139 (end-of-line) |
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
140 ;; 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
|
141 (if (if fill-prefix-regexp |
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
142 ;; There is a fill prefix; it overrides paragraph-start. |
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
143 (progn |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
144 (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
|
145 (progn (move-to-left-margin) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
146 (not (looking-at paragraph-separate))) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
147 (looking-at fill-prefix-regexp)) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
148 (forward-line -1)) |
5608
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
149 (not (bobp))) |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
150 (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
|
151 ;; 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
|
152 ;; REAL paragraph-start. |
10424
6bcb93cec6f8
(forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents:
9169
diff
changeset
|
153 (not (bobp)) |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
154 (progn (setq start (point)) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
155 (move-to-left-margin) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
156 (not (looking-at paragraph-separate))) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
157 (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
|
158 (and use-hard-newlines |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
159 (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
|
160 'hard))))) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
161 (goto-char start)) |
10424
6bcb93cec6f8
(forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents:
9169
diff
changeset
|
162 (> (point) (point-min))) |
5608
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
163 ;; Found one. |
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
164 (progn |
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
165 ;; Move forward over paragraph separators. |
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
166 ;; 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
|
167 ;; 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
|
168 (while (and (not (eobp)) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
169 (progn (move-to-left-margin) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
170 (looking-at paragraph-separate))) |
5608
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
171 (forward-line 1)) |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
172 ;; 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
|
173 (end-of-line 0) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
174 (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
|
175 (forward-char 1) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
176 (skip-chars-backward " \t") |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
177 (if (not (bolp)) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
178 (forward-line 1)))) |
5608
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
179 ;; 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
|
180 (goto-char (point-min))))) |
36 | 181 (setq arg (1+ arg))) |
5608
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
182 (while (and (> arg 0) (not (eobp))) |
36 | 183 (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
|
184 (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
|
185 (looking-at paragraph-separate)) |
10424
6bcb93cec6f8
(forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents:
9169
diff
changeset
|
186 (forward-line 1))) |
36 | 187 (if fill-prefix-regexp |
188 ;; There is a fill prefix; it overrides paragraph-start. | |
189 (while (and (not (eobp)) | |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
190 (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
|
191 (not (looking-at paragraph-separate)) |
36 | 192 (looking-at fill-prefix-regexp)) |
193 (forward-line 1)) | |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
194 (while (and (re-search-forward sp-paragraph-start nil 1) |
10464
765fe4b8deaf
(forward-paragraph): Fix end-of-buffer bug.
Richard M. Stallman <rms@gnu.org>
parents:
10424
diff
changeset
|
195 (not (eobp)) |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
196 (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
|
197 (goto-char start) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
198 (move-to-left-margin) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
199 (not (looking-at paragraph-separate))) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
200 (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
|
201 (and use-hard-newlines |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
202 (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
|
203 (forward-char 1)) |
6bcb93cec6f8
(forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents:
9169
diff
changeset
|
204 (if (< (point) (point-max)) |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
205 (goto-char start))) |
36 | 206 (setq arg (1- arg))))) |
207 | |
208 (defun backward-paragraph (&optional arg) | |
209 "Move backward to start of paragraph. | |
210 With arg N, do it N times; negative arg -N means move forward N paragraphs. | |
211 | |
237 | 212 A paragraph start is the beginning of a line which is a |
213 `first-line-of-paragraph' or which is ordinary text and follows a | |
214 paragraph-separating line; except: if the first real line of a | |
215 paragraph is preceded by a blank line, the paragraph starts at that | |
216 blank line. | |
217 | |
218 See `forward-paragraph' for more information." | |
36 | 219 (interactive "p") |
220 (or arg (setq arg 1)) | |
221 (forward-paragraph (- arg))) | |
222 | |
223 (defun mark-paragraph () | |
224 "Put point at beginning of this paragraph, mark at end. | |
225 The paragraph marked is the one that contains point or follows point." | |
226 (interactive) | |
227 (forward-paragraph 1) | |
2827
0daa9d777306
(mark-paragraph): Activate the mark.
Richard M. Stallman <rms@gnu.org>
parents:
2503
diff
changeset
|
228 (push-mark nil t t) |
36 | 229 (backward-paragraph 1)) |
230 | |
231 (defun kill-paragraph (arg) | |
232 "Kill forward to end of paragraph. | |
233 With arg N, kill forward to Nth end of paragraph; | |
234 negative arg -N means kill backward to Nth start of paragraph." | |
237 | 235 (interactive "p") |
7064
19a84bb30e9e
(kill-paragraph): Don't use save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
5653
diff
changeset
|
236 (kill-region (point) (progn (forward-paragraph arg) (point)))) |
36 | 237 |
238 (defun backward-kill-paragraph (arg) | |
239 "Kill back to start of paragraph. | |
240 With arg N, kill back to Nth start of paragraph; | |
241 negative arg -N means kill forward to Nth end of paragraph." | |
237 | 242 (interactive "p") |
7064
19a84bb30e9e
(kill-paragraph): Don't use save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
5653
diff
changeset
|
243 (kill-region (point) (progn (backward-paragraph arg) (point)))) |
36 | 244 |
245 (defun transpose-paragraphs (arg) | |
246 "Interchange this (or next) paragraph with previous one." | |
247 (interactive "*p") | |
248 (transpose-subr 'forward-paragraph arg)) | |
249 | |
250 (defun start-of-paragraph-text () | |
251 (let ((opoint (point)) npoint) | |
252 (forward-paragraph -1) | |
253 (setq npoint (point)) | |
254 (skip-chars-forward " \t\n") | |
68 | 255 ;; If the range of blank lines found spans the original start point, |
256 ;; try again from the beginning of it. | |
257 ;; Must be careful to avoid infinite loop | |
258 ;; when following a single return at start of buffer. | |
259 (if (and (>= (point) opoint) (< npoint opoint)) | |
36 | 260 (progn |
261 (goto-char npoint) | |
262 (if (> npoint (point-min)) | |
263 (start-of-paragraph-text)))))) | |
264 | |
265 (defun end-of-paragraph-text () | |
266 (let ((opoint (point))) | |
267 (forward-paragraph 1) | |
268 (if (eq (preceding-char) ?\n) (forward-char -1)) | |
269 (if (<= (point) opoint) | |
270 (progn | |
271 (forward-char 1) | |
272 (if (< (point) (point-max)) | |
273 (end-of-paragraph-text)))))) | |
274 | |
275 (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
|
276 "Move forward to next `sentence-end'. With argument, repeat. |
237 | 277 With negative argument, move backward repeatedly to `sentence-beginning'. |
36 | 278 |
237 | 279 The variable `sentence-end' is a regular expression that matches ends of |
280 sentences. Also, every paragraph boundary terminates sentences as well." | |
36 | 281 (interactive "p") |
282 (or arg (setq arg 1)) | |
283 (while (< arg 0) | |
284 (let ((par-beg (save-excursion (start-of-paragraph-text) (point)))) | |
285 (if (re-search-backward (concat sentence-end "[^ \t\n]") par-beg t) | |
286 (goto-char (1- (match-end 0))) | |
287 (goto-char par-beg))) | |
288 (setq arg (1+ arg))) | |
289 (while (> arg 0) | |
290 (let ((par-end (save-excursion (end-of-paragraph-text) (point)))) | |
291 (if (re-search-forward sentence-end par-end t) | |
292 (skip-chars-backward " \t\n") | |
293 (goto-char par-end))) | |
294 (setq arg (1- arg)))) | |
295 | |
296 (defun backward-sentence (&optional arg) | |
297 "Move backward to start of sentence. With arg, do it arg times. | |
237 | 298 See `forward-sentence' for more information." |
36 | 299 (interactive "p") |
300 (or arg (setq arg 1)) | |
301 (forward-sentence (- arg))) | |
302 | |
303 (defun kill-sentence (&optional arg) | |
304 "Kill from point to end of sentence. | |
305 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
|
306 (interactive "p") |
7064
19a84bb30e9e
(kill-paragraph): Don't use save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
5653
diff
changeset
|
307 (kill-region (point) (progn (forward-sentence arg) (point)))) |
36 | 308 |
309 (defun backward-kill-sentence (&optional arg) | |
310 "Kill back from point to start of sentence. | |
311 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
|
312 (interactive "p") |
7064
19a84bb30e9e
(kill-paragraph): Don't use save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
5653
diff
changeset
|
313 (kill-region (point) (progn (backward-sentence arg) (point)))) |
36 | 314 |
315 (defun mark-end-of-sentence (arg) | |
237 | 316 "Put mark at end of sentence. Arg works as in `forward-sentence'." |
36 | 317 (interactive "p") |
318 (push-mark | |
319 (save-excursion | |
320 (forward-sentence arg) | |
2828
abc6df78588f
(mark-end-of-sentence): Activate the mark.
Richard M. Stallman <rms@gnu.org>
parents:
2827
diff
changeset
|
321 (point)) |
abc6df78588f
(mark-end-of-sentence): Activate the mark.
Richard M. Stallman <rms@gnu.org>
parents:
2827
diff
changeset
|
322 nil t)) |
36 | 323 |
324 (defun transpose-sentences (arg) | |
325 "Interchange this (next) and previous sentence." | |
326 (interactive "*p") | |
327 (transpose-subr 'forward-sentence arg)) | |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
269
diff
changeset
|
328 |
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
269
diff
changeset
|
329 ;;; paragraphs.el ends here |