Mercurial > emacs
annotate lisp/textmodes/paragraphs.el @ 47750:75f4a9fc7b34
(forward-paragraph): Return the steps left.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Thu, 03 Oct 2002 23:00:19 +0000 |
parents | cc3ba2d0d471 |
children | 353dae5e0134 |
rev | line source |
---|---|
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
37415
diff
changeset
|
1 ;;; paragraphs.el --- paragraph and sentence parsing |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
269
diff
changeset
|
2 |
37302
bf9b394286bd
(forward-sentence): Put the sentence-end
Gerd Moellmann <gerd@gnu.org>
parents:
35964
diff
changeset
|
3 ;; Copyright (C) 1985, 86, 87, 91, 94, 95, 96, 1997, 1999, 2000, 2001 |
19475 | 4 ;; Free Software Foundation, Inc. |
845 | 5 |
789
71d052f72ac1
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
6 ;; Maintainer: FSF |
814
38b2499cb3e9
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
804
diff
changeset
|
7 ;; Keywords: wp |
789
71d052f72ac1
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
8 |
36 | 9 ;; This file is part of GNU Emacs. |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
804 | 13 ;; the Free Software Foundation; either version 2, or (at your option) |
36 | 14 ;; any later version. |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
14169 | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
36 | 25 |
2308
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1462
diff
changeset
|
26 ;;; Commentary: |
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1462
diff
changeset
|
27 |
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1462
diff
changeset
|
28 ;; 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
|
29 ;; Emacs manual. |
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1462
diff
changeset
|
30 |
789
71d052f72ac1
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
31 ;;; Code: |
36 | 32 |
19475 | 33 (defgroup paragraphs nil |
34 "Paragraph and sentence parsing." | |
35 :group 'editing) | |
36 | |
40483
b7f7d0cc89fb
(use-hard-newlines): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38715
diff
changeset
|
37 (define-minor-mode use-hard-newlines |
16019
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
38 "Minor mode to distinguish hard and soft newlines. |
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
39 When active, the functions `newline' and `open-line' add the |
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
40 text-property `hard' to newlines that they insert, and a line is |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
41 only considered as a candidate to match `paragraph-start' or |
16019
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
42 `paragraph-separate' if it follows a hard newline. |
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
43 |
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
44 Prefix argument says to turn mode on if positive, off if negative. |
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
45 When the mode is turned on, if there are newlines in the buffer but no hard |
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
46 newlines, ask the user whether to mark as hard any newlines preceeding a |
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
47 `paragraph-start' line. From a program, second arg INSERT specifies whether |
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
48 to do this; it can be `never' to change nothing, t or `always' to force |
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
49 marking, `guess' to try to do the right thing with no questions, nil |
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
50 or anything else to ask the user. |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
51 |
16019
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
52 Newlines not marked hard are called \"soft\", and are always internal |
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
53 to paragraphs. The fill functions insert and delete only soft newlines." |
40483
b7f7d0cc89fb
(use-hard-newlines): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38715
diff
changeset
|
54 :extra-args (insert) |
b7f7d0cc89fb
(use-hard-newlines): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38715
diff
changeset
|
55 (when use-hard-newlines |
16019
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
56 ;; Turn mode on |
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
57 ;; Intuit hard newlines -- |
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
58 ;; mark as hard any newlines preceding a paragraph-start line. |
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
59 (if (or (eq insert t) (eq insert 'always) |
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
60 (and (not (eq 'never insert)) |
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
61 (not (text-property-any (point-min) (point-max) 'hard t)) |
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
62 (save-excursion |
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
63 (goto-char (point-min)) |
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
64 (search-forward "\n" nil t)) |
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
65 (or (eq insert 'guess) |
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
66 (y-or-n-p "Make newlines between paragraphs hard? ")))) |
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
67 (save-excursion |
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
68 (goto-char (point-min)) |
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
69 (while (search-forward "\n" nil t) |
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
70 (let ((pos (point))) |
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
71 (move-to-left-margin) |
40483
b7f7d0cc89fb
(use-hard-newlines): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38715
diff
changeset
|
72 (when (looking-at paragraph-start) |
b7f7d0cc89fb
(use-hard-newlines): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38715
diff
changeset
|
73 (set-hard-newline-properties (1- pos) pos)) |
b7f7d0cc89fb
(use-hard-newlines): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38715
diff
changeset
|
74 ;; If paragraph-separate, newline after it is hard too. |
b7f7d0cc89fb
(use-hard-newlines): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38715
diff
changeset
|
75 (when (looking-at paragraph-separate) |
b7f7d0cc89fb
(use-hard-newlines): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38715
diff
changeset
|
76 (set-hard-newline-properties (1- pos) pos) |
b7f7d0cc89fb
(use-hard-newlines): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38715
diff
changeset
|
77 (end-of-line) |
b7f7d0cc89fb
(use-hard-newlines): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38715
diff
changeset
|
78 (unless (eobp) |
b7f7d0cc89fb
(use-hard-newlines): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38715
diff
changeset
|
79 (set-hard-newline-properties (point) (1+ (point))))))))))) |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
80 |
40483
b7f7d0cc89fb
(use-hard-newlines): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38715
diff
changeset
|
81 (defcustom paragraph-start "\f\\|[ \t]*$" "\ |
4585
04e78c728252
(paragraph-start): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
2828
diff
changeset
|
82 *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
|
83 This regexp should match lines that separate paragraphs |
04e78c728252
(paragraph-start): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
2828
diff
changeset
|
84 and should also match lines that start a paragraph |
04e78c728252
(paragraph-start): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
2828
diff
changeset
|
85 \(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
|
86 |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
87 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
|
88 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
|
89 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
|
90 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
|
91 |
4585
04e78c728252
(paragraph-start): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
2828
diff
changeset
|
92 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
|
93 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
|
94 |
34655 | 95 If the variable `use-hard-newlines' is non-nil, then only lines following a |
19475 | 96 hard newline are considered to match." |
97 :group 'paragraphs | |
98 :type 'regexp) | |
264 | 99 |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
100 ;; 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
|
101 ;; 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
|
102 ;; 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
|
103 ;; 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
|
104 ;; start a new paragraph). |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
105 |
19475 | 106 (defcustom paragraph-separate "[ \t\f]*$" |
107 "*Regexp for beginning of a line that separates paragraphs. | |
24309
92537e14b89b
(paragraph-separate): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23245
diff
changeset
|
108 If you change this, you may have to change `paragraph-start' also. |
10424
6bcb93cec6f8
(forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents:
9169
diff
changeset
|
109 |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
110 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
|
111 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
|
112 ensures that the paragraph functions will work equally within a region of |
19475 | 113 text indented by a margin setting." |
114 :group 'paragraphs | |
115 :type 'regexp) | |
264 | 116 |
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
117 (defcustom sentence-end-double-space t |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
118 "*Non-nil means a single space does not end a sentence. |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
119 This is relevant for filling. See also `sentence-end-without-period' |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
120 and `colon-double-space'. |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
121 |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
122 If you change this, you should also change `sentence-end'. See Info |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
123 node `Sentences'." |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
124 :type 'boolean |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
125 :group 'fill) |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
126 |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
127 (defcustom sentence-end-without-period nil |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
128 "*Non-nil means a sentence will end without a period. |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
129 For example, a sentence in Thai text ends with double space but |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
130 without a period." |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
131 :type 'boolean |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
132 :group 'fill) |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
133 |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
134 (defcustom sentence-end |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
135 (purecopy |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
136 ;; This is a bit stupid since it's not auto-updated when the |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
137 ;; other variables are changes, but it's still useful info. |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
138 (concat (if sentence-end-without-period "\\w \\|") |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
139 "[.?!][]\"')}]*" |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
140 (if sentence-end-double-space |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
141 "\\($\\| $\\|\t\\| \\)" "\\($\\|[\t ]\\)") |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
142 "[ \t\n]*")) |
19475 | 143 "*Regexp describing the end of a sentence. |
37415 | 144 The value includes the whitespace following the 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
|
145 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
|
146 |
24472 | 147 The default value specifies that in order to be recognized as the end |
148 of a sentence, the ending period, question mark, or exclamation point | |
149 must be followed by two spaces, unless it's inside some sort of quotes | |
150 or parenthesis. | |
151 | |
35964 | 152 See also the variable `sentence-end-double-space', the variable |
153 `sentence-end-without-period' and Info node `Sentences'." | |
19475 | 154 :group 'paragraphs |
155 :type 'regexp) | |
264 | 156 |
19475 | 157 (defcustom page-delimiter "^\014" |
158 "*Regexp describing line-beginnings that separate pages." | |
159 :group 'paragraphs | |
160 :type 'regexp) | |
264 | 161 |
19475 | 162 (defcustom paragraph-ignore-fill-prefix nil |
163 "*Non-nil means the paragraph commands are not affected by `fill-prefix'. | |
164 This is desirable in modes where blank lines are the paragraph delimiters." | |
165 :group 'paragraphs | |
166 :type 'boolean) | |
264 | 167 |
36 | 168 (defun forward-paragraph (&optional arg) |
169 "Move forward to end of paragraph. | |
16757
e1c2e9a44236
(forward-paragraph, backward-paragraph): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
16687
diff
changeset
|
170 With argument ARG, do it ARG times; |
e1c2e9a44236
(forward-paragraph, backward-paragraph): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
16687
diff
changeset
|
171 a negative argument ARG = -N means move backward N paragraphs. |
36 | 172 |
173 A line which `paragraph-start' matches either separates paragraphs | |
174 \(if `paragraph-separate' matches it also) or is the first line of a paragraph. | |
175 A paragraph end is the beginning of a line which is not part of the paragraph | |
176 to which the end of the previous line belongs, or the end of the buffer." | |
177 (interactive "p") | |
178 (or arg (setq arg 1)) | |
26055
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
179 (let* ((opoint (point)) |
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
180 (fill-prefix-regexp |
36 | 181 (and fill-prefix (not (equal fill-prefix "")) |
182 (not paragraph-ignore-fill-prefix) | |
183 (regexp-quote fill-prefix))) | |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
184 ;; 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
|
185 ;; 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
|
186 ;; 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
|
187 ;; work normally with indented text. |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
188 ;; This hack will not find problem cases like "whatever\\|^something". |
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
189 (parstart (if (and (not (equal "" paragraph-start)) |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
190 (equal ?^ (aref paragraph-start 0))) |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
191 (substring paragraph-start 1) |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
192 paragraph-start)) |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
193 (parsep (if (and (not (equal "" paragraph-separate)) |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
194 (equal ?^ (aref paragraph-separate 0))) |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
195 (substring paragraph-separate 1) |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
196 paragraph-separate)) |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
197 (parsep |
36 | 198 (if fill-prefix-regexp |
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
199 (concat parsep "\\|" |
36 | 200 fill-prefix-regexp "[ \t]*$") |
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
201 parsep)) |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
202 ;; This is used for searching. |
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
203 (sp-parstart (concat "^[ \t]*\\(?:" parstart "\\|" parsep "\\)")) |
22953
fbeacfb09096
(forward-paragraph): Fix the logic for handling beginning of buffer
Richard M. Stallman <rms@gnu.org>
parents:
19527
diff
changeset
|
204 start found-start) |
5608
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
205 (while (and (< arg 0) (not (bobp))) |
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
206 (if (and (not (looking-at parsep)) |
10424
6bcb93cec6f8
(forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents:
9169
diff
changeset
|
207 (re-search-backward "^\n" (max (1- (point)) (point-min)) t) |
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
208 (looking-at parsep)) |
36 | 209 nil |
12717
8e153c7bbd90
(forward-paragraph): Don't move back over a line
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
210 (setq start (point)) |
5608
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
211 ;; Move back over paragraph-separating lines. |
36 | 212 (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
|
213 (while (and (not (bobp)) |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
214 (progn (move-to-left-margin) |
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
215 (looking-at parsep))) |
34655 | 216 (forward-line -1)) |
5608
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
217 (if (bobp) |
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
218 nil |
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
219 ;; 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
|
220 (end-of-line) |
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
221 ;; 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
|
222 (if (if fill-prefix-regexp |
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
223 ;; There is a fill prefix; it overrides parstart. |
12717
8e153c7bbd90
(forward-paragraph): Don't move back over a line
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
224 (let (multiple-lines) |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
225 (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
|
226 (progn (move-to-left-margin) |
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
227 (not (looking-at parsep))) |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
228 (looking-at fill-prefix-regexp)) |
34655 | 229 (unless (= (point) start) |
230 (setq multiple-lines t)) | |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
231 (forward-line -1)) |
12717
8e153c7bbd90
(forward-paragraph): Don't move back over a line
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
232 (move-to-left-margin) |
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
233 ;; This deleted code caused a long hanging-indent line |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
234 ;; not to be filled together with the following lines. |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
235 ;; ;; Don't move back over a line before the paragraph |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
236 ;; ;; which doesn't start with fill-prefix |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
237 ;; ;; unless that is the only line we've moved over. |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
238 ;; (and (not (looking-at fill-prefix-regexp)) |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
239 ;; multiple-lines |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
240 ;; (forward-line 1)) |
12717
8e153c7bbd90
(forward-paragraph): Don't move back over a line
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
241 (not (bobp))) |
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
242 (while (and (re-search-backward sp-parstart nil 1) |
22953
fbeacfb09096
(forward-paragraph): Fix the logic for handling beginning of buffer
Richard M. Stallman <rms@gnu.org>
parents:
19527
diff
changeset
|
243 (setq found-start t) |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
244 ;; Found a candidate, but need to check if it is a |
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
245 ;; REAL parstart. |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
246 (progn (setq start (point)) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
247 (move-to-left-margin) |
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
248 (not (looking-at parsep))) |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
249 (not (and (looking-at parstart) |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
250 (or (not use-hard-newlines) |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
251 (get-text-property (1- start) 'hard) |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
252 (bobp))))) |
22953
fbeacfb09096
(forward-paragraph): Fix the logic for handling beginning of buffer
Richard M. Stallman <rms@gnu.org>
parents:
19527
diff
changeset
|
253 (setq found-start nil) |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
254 (goto-char start)) |
22953
fbeacfb09096
(forward-paragraph): Fix the logic for handling beginning of buffer
Richard M. Stallman <rms@gnu.org>
parents:
19527
diff
changeset
|
255 found-start) |
40483
b7f7d0cc89fb
(use-hard-newlines): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38715
diff
changeset
|
256 ;; Found one. |
b7f7d0cc89fb
(use-hard-newlines): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38715
diff
changeset
|
257 (progn |
5608
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
258 ;; Move forward over paragraph separators. |
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
259 ;; 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
|
260 ;; 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
|
261 (while (and (not (eobp)) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
262 (progn (move-to-left-margin) |
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
263 (looking-at parsep))) |
5608
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
264 (forward-line 1)) |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
265 ;; 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
|
266 (end-of-line 0) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
267 (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
|
268 (forward-char 1) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
269 (skip-chars-backward " \t") |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
270 (if (not (bolp)) |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
271 (forward-line 1)))) |
5608
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
272 ;; 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
|
273 (goto-char (point-min))))) |
36 | 274 (setq arg (1+ arg))) |
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
275 |
5608
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
276 (while (and (> arg 0) (not (eobp))) |
14378
2110ae3ef540
(forward-paragraph): Comment change.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
277 ;; Move forward over separator lines, and one more line. |
36 | 278 (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
|
279 (progn (move-to-left-margin) (not (eobp))) |
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
280 (looking-at parsep)) |
10424
6bcb93cec6f8
(forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents:
9169
diff
changeset
|
281 (forward-line 1))) |
36 | 282 (if fill-prefix-regexp |
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
283 ;; There is a fill prefix; it overrides parstart. |
36 | 284 (while (and (not (eobp)) |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
285 (progn (move-to-left-margin) (not (eobp))) |
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
286 (not (looking-at parsep)) |
36 | 287 (looking-at fill-prefix-regexp)) |
288 (forward-line 1)) | |
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
289 (while (and (re-search-forward sp-parstart nil 1) |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
290 (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
|
291 (goto-char start) |
12804
1619fcabdb99
(forward-paragraph): Don't overlook a paragraph-start
Richard M. Stallman <rms@gnu.org>
parents:
12717
diff
changeset
|
292 (not (eobp))) |
1619fcabdb99
(forward-paragraph): Don't overlook a paragraph-start
Richard M. Stallman <rms@gnu.org>
parents:
12717
diff
changeset
|
293 (progn (move-to-left-margin) |
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
294 (not (looking-at parsep))) |
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40483
diff
changeset
|
295 (or (not (looking-at parstart)) |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
296 (and use-hard-newlines |
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
297 (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
|
298 (forward-char 1)) |
6bcb93cec6f8
(forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents:
9169
diff
changeset
|
299 (if (< (point) (point-max)) |
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
300 (goto-char start))) |
25551
5cd9adabaee5
(backward-kill-sentence): Don't test minibuffer-prompt-end here.
Richard M. Stallman <rms@gnu.org>
parents:
25361
diff
changeset
|
301 (setq arg (1- arg))) |
47750
75f4a9fc7b34
(forward-paragraph): Return the steps left.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43384
diff
changeset
|
302 (constrain-to-field nil opoint t) |
75f4a9fc7b34
(forward-paragraph): Return the steps left.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43384
diff
changeset
|
303 ;; Return the number of steps that could not be done. |
75f4a9fc7b34
(forward-paragraph): Return the steps left.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43384
diff
changeset
|
304 arg)) |
36 | 305 |
306 (defun backward-paragraph (&optional arg) | |
307 "Move backward to start of paragraph. | |
16757
e1c2e9a44236
(forward-paragraph, backward-paragraph): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
16687
diff
changeset
|
308 With argument ARG, do it ARG times; |
e1c2e9a44236
(forward-paragraph, backward-paragraph): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
16687
diff
changeset
|
309 a negative argument ARG = -N means move forward N paragraphs. |
36 | 310 |
237 | 311 A paragraph start is the beginning of a line which is a |
312 `first-line-of-paragraph' or which is ordinary text and follows a | |
313 paragraph-separating line; except: if the first real line of a | |
314 paragraph is preceded by a blank line, the paragraph starts at that | |
315 blank line. | |
316 | |
317 See `forward-paragraph' for more information." | |
36 | 318 (interactive "p") |
319 (or arg (setq arg 1)) | |
320 (forward-paragraph (- arg))) | |
321 | |
41709
df0a6a02b580
(mark-paragraph): Clarify doc. Clarify
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
40485
diff
changeset
|
322 (defun mark-paragraph (&optional arg) |
36 | 323 "Put point at beginning of this paragraph, mark at end. |
41709
df0a6a02b580
(mark-paragraph): Clarify doc. Clarify
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
40485
diff
changeset
|
324 The paragraph marked is the one that contains point or follows point. |
df0a6a02b580
(mark-paragraph): Clarify doc. Clarify
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
40485
diff
changeset
|
325 |
df0a6a02b580
(mark-paragraph): Clarify doc. Clarify
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
40485
diff
changeset
|
326 With argument ARG, puts mark at end of a following paragraph, so that |
df0a6a02b580
(mark-paragraph): Clarify doc. Clarify
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
40485
diff
changeset
|
327 the number of paragraphs marked equals ARG. |
df0a6a02b580
(mark-paragraph): Clarify doc. Clarify
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
40485
diff
changeset
|
328 |
df0a6a02b580
(mark-paragraph): Clarify doc. Clarify
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
40485
diff
changeset
|
329 If ARG is negative, point is put at end of this paragraph, mark is put |
43301
898b4b31410f
* lisp/simple.el (mark-word): Mark more if repeated.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
41709
diff
changeset
|
330 at beginning of this or a previous paragraph. |
898b4b31410f
* lisp/simple.el (mark-word): Mark more if repeated.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
41709
diff
changeset
|
331 |
898b4b31410f
* lisp/simple.el (mark-word): Mark more if repeated.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
41709
diff
changeset
|
332 If this command is repeated, it marks the next ARG paragraphs after (or |
898b4b31410f
* lisp/simple.el (mark-word): Mark more if repeated.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
41709
diff
changeset
|
333 before, if arg is negative) the ones already marked." |
41709
df0a6a02b580
(mark-paragraph): Clarify doc. Clarify
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
40485
diff
changeset
|
334 (interactive "p") |
43384
cc3ba2d0d471
* emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
43301
diff
changeset
|
335 (unless arg (setq arg 1)) |
cc3ba2d0d471
* emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
43301
diff
changeset
|
336 (when (zerop arg) |
cc3ba2d0d471
* emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
43301
diff
changeset
|
337 (error "Cannot mark zero paragraphs")) |
cc3ba2d0d471
* emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
43301
diff
changeset
|
338 (cond ((and (eq last-command this-command) (mark t)) |
cc3ba2d0d471
* emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
43301
diff
changeset
|
339 (set-mark |
cc3ba2d0d471
* emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
43301
diff
changeset
|
340 (save-excursion |
cc3ba2d0d471
* emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
43301
diff
changeset
|
341 (goto-char (mark)) |
cc3ba2d0d471
* emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
43301
diff
changeset
|
342 (forward-paragraph arg) |
cc3ba2d0d471
* emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
43301
diff
changeset
|
343 (point)))) |
cc3ba2d0d471
* emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
43301
diff
changeset
|
344 (t |
cc3ba2d0d471
* emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
43301
diff
changeset
|
345 (forward-paragraph arg) |
cc3ba2d0d471
* emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
43301
diff
changeset
|
346 (push-mark nil t t) |
cc3ba2d0d471
* emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
43301
diff
changeset
|
347 (backward-paragraph arg)))) |
36 | 348 |
349 (defun kill-paragraph (arg) | |
350 "Kill forward to end of paragraph. | |
351 With arg N, kill forward to Nth end of paragraph; | |
352 negative arg -N means kill backward to Nth start of paragraph." | |
27837
46fedf13d52e
(kill-paragraph, backward-kill-paragraph)
Dave Love <fx@gnu.org>
parents:
26055
diff
changeset
|
353 (interactive "p") |
7064
19a84bb30e9e
(kill-paragraph): Don't use save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
5653
diff
changeset
|
354 (kill-region (point) (progn (forward-paragraph arg) (point)))) |
36 | 355 |
356 (defun backward-kill-paragraph (arg) | |
357 "Kill back to start of paragraph. | |
358 With arg N, kill back to Nth start of paragraph; | |
359 negative arg -N means kill forward to Nth end of paragraph." | |
27837
46fedf13d52e
(kill-paragraph, backward-kill-paragraph)
Dave Love <fx@gnu.org>
parents:
26055
diff
changeset
|
360 (interactive "p") |
26055
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
361 (kill-region (point) (progn (backward-paragraph arg) (point)))) |
36 | 362 |
363 (defun transpose-paragraphs (arg) | |
364 "Interchange this (or next) paragraph with previous one." | |
365 (interactive "*p") | |
366 (transpose-subr 'forward-paragraph arg)) | |
367 | |
368 (defun start-of-paragraph-text () | |
369 (let ((opoint (point)) npoint) | |
370 (forward-paragraph -1) | |
371 (setq npoint (point)) | |
372 (skip-chars-forward " \t\n") | |
68 | 373 ;; If the range of blank lines found spans the original start point, |
374 ;; try again from the beginning of it. | |
375 ;; Must be careful to avoid infinite loop | |
376 ;; when following a single return at start of buffer. | |
377 (if (and (>= (point) opoint) (< npoint opoint)) | |
36 | 378 (progn |
379 (goto-char npoint) | |
380 (if (> npoint (point-min)) | |
381 (start-of-paragraph-text)))))) | |
382 | |
383 (defun end-of-paragraph-text () | |
384 (let ((opoint (point))) | |
385 (forward-paragraph 1) | |
386 (if (eq (preceding-char) ?\n) (forward-char -1)) | |
387 (if (<= (point) opoint) | |
388 (progn | |
389 (forward-char 1) | |
390 (if (< (point) (point-max)) | |
391 (end-of-paragraph-text)))))) | |
392 | |
393 (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
|
394 "Move forward to next `sentence-end'. With argument, repeat. |
237 | 395 With negative argument, move backward repeatedly to `sentence-beginning'. |
36 | 396 |
237 | 397 The variable `sentence-end' is a regular expression that matches ends of |
398 sentences. Also, every paragraph boundary terminates sentences as well." | |
36 | 399 (interactive "p") |
400 (or arg (setq arg 1)) | |
26055
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
401 (let ((opoint (point))) |
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
402 (while (< arg 0) |
38715
06ad87abb7a4
(forward-sentence): Avoid building
Gerd Moellmann <gerd@gnu.org>
parents:
38412
diff
changeset
|
403 (let ((pos (point)) |
06ad87abb7a4
(forward-sentence): Avoid building
Gerd Moellmann <gerd@gnu.org>
parents:
38412
diff
changeset
|
404 (par-beg (save-excursion (start-of-paragraph-text) (point)))) |
06ad87abb7a4
(forward-sentence): Avoid building
Gerd Moellmann <gerd@gnu.org>
parents:
38412
diff
changeset
|
405 (if (and (re-search-backward sentence-end par-beg t) |
06ad87abb7a4
(forward-sentence): Avoid building
Gerd Moellmann <gerd@gnu.org>
parents:
38412
diff
changeset
|
406 (or (< (match-end 0) pos) |
06ad87abb7a4
(forward-sentence): Avoid building
Gerd Moellmann <gerd@gnu.org>
parents:
38412
diff
changeset
|
407 (re-search-backward sentence-end par-beg t))) |
06ad87abb7a4
(forward-sentence): Avoid building
Gerd Moellmann <gerd@gnu.org>
parents:
38412
diff
changeset
|
408 (goto-char (match-end 0)) |
26055
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
409 (goto-char par-beg))) |
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
410 (setq arg (1+ arg))) |
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
411 (while (> arg 0) |
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
412 (let ((par-end (save-excursion (end-of-paragraph-text) (point)))) |
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
413 (if (re-search-forward sentence-end par-end t) |
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
414 (skip-chars-backward " \t\n") |
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
415 (goto-char par-end))) |
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
416 (setq arg (1- arg))) |
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
417 (constrain-to-field nil opoint t))) |
36 | 418 |
419 (defun backward-sentence (&optional arg) | |
420 "Move backward to start of sentence. With arg, do it arg times. | |
237 | 421 See `forward-sentence' for more information." |
36 | 422 (interactive "p") |
423 (or arg (setq arg 1)) | |
424 (forward-sentence (- arg))) | |
425 | |
426 (defun kill-sentence (&optional arg) | |
427 "Kill from point to end of sentence. | |
428 With arg, repeat; negative arg -N means kill back to Nth start of sentence." | |
27837
46fedf13d52e
(kill-paragraph, backward-kill-paragraph)
Dave Love <fx@gnu.org>
parents:
26055
diff
changeset
|
429 (interactive "p") |
7064
19a84bb30e9e
(kill-paragraph): Don't use save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
5653
diff
changeset
|
430 (kill-region (point) (progn (forward-sentence arg) (point)))) |
36 | 431 |
432 (defun backward-kill-sentence (&optional arg) | |
433 "Kill back from point to start of sentence. | |
434 With arg, repeat, or kill forward to Nth end of sentence if negative arg -N." | |
27837
46fedf13d52e
(kill-paragraph, backward-kill-paragraph)
Dave Love <fx@gnu.org>
parents:
26055
diff
changeset
|
435 (interactive "p") |
26055
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
436 (kill-region (point) (progn (backward-sentence arg) (point)))) |
36 | 437 |
438 (defun mark-end-of-sentence (arg) | |
43301
898b4b31410f
* lisp/simple.el (mark-word): Mark more if repeated.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
41709
diff
changeset
|
439 "Put mark at end of sentence. Arg works as in `forward-sentence'. |
898b4b31410f
* lisp/simple.el (mark-word): Mark more if repeated.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
41709
diff
changeset
|
440 If this command is repeated, it marks the next ARG sentences after the |
898b4b31410f
* lisp/simple.el (mark-word): Mark more if repeated.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
41709
diff
changeset
|
441 ones already marked." |
36 | 442 (interactive "p") |
443 (push-mark | |
43301
898b4b31410f
* lisp/simple.el (mark-word): Mark more if repeated.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
41709
diff
changeset
|
444 (save-excursion |
898b4b31410f
* lisp/simple.el (mark-word): Mark more if repeated.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
41709
diff
changeset
|
445 (if (and (eq last-command this-command) (mark t)) |
898b4b31410f
* lisp/simple.el (mark-word): Mark more if repeated.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
41709
diff
changeset
|
446 (goto-char (mark))) |
898b4b31410f
* lisp/simple.el (mark-word): Mark more if repeated.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
41709
diff
changeset
|
447 (forward-sentence arg) |
898b4b31410f
* lisp/simple.el (mark-word): Mark more if repeated.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
41709
diff
changeset
|
448 (point)) |
898b4b31410f
* lisp/simple.el (mark-word): Mark more if repeated.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
41709
diff
changeset
|
449 nil t)) |
36 | 450 |
451 (defun transpose-sentences (arg) | |
452 "Interchange this (next) and previous sentence." | |
453 (interactive "*p") | |
454 (transpose-subr 'forward-sentence arg)) | |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
269
diff
changeset
|
455 |
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
269
diff
changeset
|
456 ;;; paragraphs.el ends here |