annotate lisp/textmodes/paragraphs.el @ 64732:29c131ee3778

Add autoload cookies for all coding systems.
author Kenichi Handa <handa@m17n.org>
date Fri, 05 Aug 2005 01:14:08 +0000
parents a8fa7c632ee4
children 5b1a238fcbb4 f9a65d7ebd29
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
57405
ba8ab430f898 (sentence-end-double-space)
Luc Teirlinck <teirllm@auburn.edu>
parents: 57282
diff changeset
3 ;; Copyright (C) 1985, 86, 87, 91, 94, 95, 96, 1997, 1999, 2000, 2001, 2004
19475
c8c9212a86a7 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17569
diff changeset
4 ;; Free Software Foundation, Inc.
845
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
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
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
10
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
804
33aaf4b71a1d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 789
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
14 ;; any later version.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
15
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
20
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12804
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64084
a8fa7c632ee4 Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 59179
diff changeset
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
a8fa7c632ee4 Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 59179
diff changeset
24 ;; Boston, MA 02110-1301, USA.
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
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
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
32
19475
c8c9212a86a7 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17569
diff changeset
33 (defgroup paragraphs nil
c8c9212a86a7 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17569
diff changeset
34 "Paragraph and sentence parsing."
c8c9212a86a7 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17569
diff changeset
35 :group 'editing)
c8c9212a86a7 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17569
diff changeset
36
56941
e838a0739922 (use-hard-newlines): Make it into a permanent local.
Luc Teirlinck <teirllm@auburn.edu>
parents: 56084
diff changeset
37 (put 'use-hard-newlines 'permanent-local t)
40483
b7f7d0cc89fb (use-hard-newlines): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38715
diff changeset
38 (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
39 "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
40 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
41 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
42 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
43 `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
44
99cc9a8dd157 (use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents: 14378
diff changeset
45 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
46 When the mode is turned on, if there are newlines in the buffer but no hard
49599
5ade352e8d1c Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48401
diff changeset
47 newlines, ask the user whether to mark as hard any newlines preceeding a
16019
99cc9a8dd157 (use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents: 14378
diff changeset
48 `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
49 to do this; it can be `never' to change nothing, t or `always' to force
49599
5ade352e8d1c Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48401
diff changeset
50 marking, `guess' to try to do the right thing with no questions, nil
16019
99cc9a8dd157 (use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents: 14378
diff changeset
51 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
52
16019
99cc9a8dd157 (use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents: 14378
diff changeset
53 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
54 to paragraphs. The fill functions insert and delete only soft newlines."
48401
2928f718924e (use-hard-newlines): Add group.
Markus Rost <rost@math.uni-bielefeld.de>
parents: 47829
diff changeset
55 :group 'paragraphs
40483
b7f7d0cc89fb (use-hard-newlines): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38715
diff changeset
56 :extra-args (insert)
b7f7d0cc89fb (use-hard-newlines): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38715
diff changeset
57 (when use-hard-newlines
16019
99cc9a8dd157 (use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents: 14378
diff changeset
58 ;; Turn mode on
99cc9a8dd157 (use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents: 14378
diff changeset
59 ;; Intuit hard newlines --
99cc9a8dd157 (use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents: 14378
diff changeset
60 ;; 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
61 (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
62 (and (not (eq 'never insert))
99cc9a8dd157 (use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents: 14378
diff changeset
63 (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
64 (save-excursion
99cc9a8dd157 (use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents: 14378
diff changeset
65 (goto-char (point-min))
99cc9a8dd157 (use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents: 14378
diff changeset
66 (search-forward "\n" nil t))
99cc9a8dd157 (use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents: 14378
diff changeset
67 (or (eq insert 'guess)
99cc9a8dd157 (use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents: 14378
diff changeset
68 (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
69 (save-excursion
99cc9a8dd157 (use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents: 14378
diff changeset
70 (goto-char (point-min))
99cc9a8dd157 (use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents: 14378
diff changeset
71 (while (search-forward "\n" nil t)
99cc9a8dd157 (use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents: 14378
diff changeset
72 (let ((pos (point)))
99cc9a8dd157 (use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents: 14378
diff changeset
73 (move-to-left-margin)
40483
b7f7d0cc89fb (use-hard-newlines): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38715
diff changeset
74 (when (looking-at paragraph-start)
b7f7d0cc89fb (use-hard-newlines): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38715
diff changeset
75 (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
76 ;; 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
77 (when (looking-at paragraph-separate)
b7f7d0cc89fb (use-hard-newlines): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38715
diff changeset
78 (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
79 (end-of-line)
b7f7d0cc89fb (use-hard-newlines): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38715
diff changeset
80 (unless (eobp)
b7f7d0cc89fb (use-hard-newlines): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38715
diff changeset
81 (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
82
40483
b7f7d0cc89fb (use-hard-newlines): Use define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38715
diff changeset
83 (defcustom paragraph-start "\f\\|[ \t]*$" "\
4585
04e78c728252 (paragraph-start): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 2828
diff changeset
84 *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
85 This regexp should match lines that separate paragraphs
04e78c728252 (paragraph-start): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 2828
diff changeset
86 and should also match lines that start a paragraph
04e78c728252 (paragraph-start): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 2828
diff changeset
87 \(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
88
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
89 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
90 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
91 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
92 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
93
4585
04e78c728252 (paragraph-start): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 2828
diff changeset
94 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
95 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
96
34655
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27837
diff changeset
97 If the variable `use-hard-newlines' is non-nil, then only lines following a
19475
c8c9212a86a7 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17569
diff changeset
98 hard newline are considered to match."
c8c9212a86a7 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17569
diff changeset
99 :group 'paragraphs
c8c9212a86a7 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17569
diff changeset
100 :type 'regexp)
264
7db4ff4204a5 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 237
diff changeset
101
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
102 ;; 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
103 ;; 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
104 ;; 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
105 ;; 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
106 ;; start a new paragraph).
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
107
19475
c8c9212a86a7 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17569
diff changeset
108 (defcustom paragraph-separate "[ \t\f]*$"
c8c9212a86a7 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17569
diff changeset
109 "*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
110 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
111
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
112 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
113 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
114 ensures that the paragraph functions will work equally within a region of
19475
c8c9212a86a7 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17569
diff changeset
115 text indented by a margin setting."
c8c9212a86a7 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17569
diff changeset
116 :group 'paragraphs
c8c9212a86a7 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17569
diff changeset
117 :type 'regexp)
264
7db4ff4204a5 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 237
diff changeset
118
40485
ca833879aa7b (sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40483
diff changeset
119 (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
120 "*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
121 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
122 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
123
54977
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
124 This value is used by the function `sentence-end' to construct the
57405
ba8ab430f898 (sentence-end-double-space)
Luc Teirlinck <teirllm@auburn.edu>
parents: 57282
diff changeset
125 regexp describing the end of a sentence, when the value of the variable
ba8ab430f898 (sentence-end-double-space)
Luc Teirlinck <teirllm@auburn.edu>
parents: 57282
diff changeset
126 `sentence-end' is nil. See Info node `(elisp)Standard Regexps'."
40485
ca833879aa7b (sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40483
diff changeset
127 :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
128 :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
129
ca833879aa7b (sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40483
diff changeset
130 (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
131 "*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
132 For example, a sentence in Thai text ends with double space but
54977
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
133 without a period.
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
134
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
135 This value is used by the function `sentence-end' to construct the
57405
ba8ab430f898 (sentence-end-double-space)
Luc Teirlinck <teirllm@auburn.edu>
parents: 57282
diff changeset
136 regexp describing the end of a sentence, when the value of the variable
ba8ab430f898 (sentence-end-double-space)
Luc Teirlinck <teirllm@auburn.edu>
parents: 57282
diff changeset
137 `sentence-end' is nil. See Info node `(elisp)Standard Regexps'."
40485
ca833879aa7b (sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40483
diff changeset
138 :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
139 :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
140
53721
40f76024a6c1 (sentence-end-without-space): New variable.
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
141 (defcustom sentence-end-without-space
40f76024a6c1 (sentence-end-without-space): New variable.
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
142 "$B!#!%!)!*$A!##.#?#!$(0!$!%!)!*$(G!$!%!)!*(B"
57405
ba8ab430f898 (sentence-end-double-space)
Luc Teirlinck <teirllm@auburn.edu>
parents: 57282
diff changeset
143 "*String of characters that end sentence without following spaces.
54977
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
144
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
145 This value is used by the function `sentence-end' to construct the
57405
ba8ab430f898 (sentence-end-double-space)
Luc Teirlinck <teirllm@auburn.edu>
parents: 57282
diff changeset
146 regexp describing the end of a sentence, when the value of the variable
ba8ab430f898 (sentence-end-double-space)
Luc Teirlinck <teirllm@auburn.edu>
parents: 57282
diff changeset
147 `sentence-end' is nil. See Info node `(elisp)Standard Regexps'."
53721
40f76024a6c1 (sentence-end-without-space): New variable.
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
148 :group 'paragraphs
40f76024a6c1 (sentence-end-without-space): New variable.
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
149 :type 'string)
40f76024a6c1 (sentence-end-without-space): New variable.
Kenichi Handa <handa@m17n.org>
parents: 52401
diff changeset
150
54977
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
151 (defcustom sentence-end nil
19475
c8c9212a86a7 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17569
diff changeset
152 "*Regexp describing the end of a sentence.
37415
16c36231eb5c (sentence-end): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 37302
diff changeset
153 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
154 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
155
54977
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
156 The value nil means to use the default value defined by the
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
157 function `sentence-end'. You should always use this function
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
158 to obtain the value of this variable."
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
159 :group 'paragraphs
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
160 :type '(choice regexp (const :tag "Use default value" nil)))
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
161
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
162 (defun sentence-end ()
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
163 "Return the regexp describing the end of a sentence.
24472
30ee4bf65cb3 (sentence-end): Doc fix.
Dave Love <fx@gnu.org>
parents: 24309
diff changeset
164
54977
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
165 This function returns either the value of the variable `sentence-end'
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
166 if it is non-nil, or the default value constructed from the
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
167 variables `sentence-end-double-space', `sentence-end-without-period'
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
168 and `sentence-end-without-space'. The default value specifies
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
169 that in order to be recognized as the end of a sentence, the
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
170 ending period, question mark, or exclamation point must be
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
171 followed by two spaces, unless it's inside some sort of quotes or
57405
ba8ab430f898 (sentence-end-double-space)
Luc Teirlinck <teirllm@auburn.edu>
parents: 57282
diff changeset
172 parenthesis. See Info node `(elisp)Standard Regexps'."
54977
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
173 (or sentence-end
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
174 (concat (if sentence-end-without-period "\\w \\|")
56084
4d540c98ac8c (sentence-end): Add 0x5397d as close brace.
Richard M. Stallman <rms@gnu.org>
parents: 55732
diff changeset
175 "\\([.?!][]\"'\xd0c9\x5397d)}]*"
54977
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
176 (if sentence-end-double-space
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
177 "\\($\\| $\\|\t\\| \\)" "\\($\\|[\t ]\\)")
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
178 "\\|[" sentence-end-without-space "]+\\)"
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
179 "[ \t\n]*")))
264
7db4ff4204a5 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 237
diff changeset
180
19475
c8c9212a86a7 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17569
diff changeset
181 (defcustom page-delimiter "^\014"
c8c9212a86a7 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17569
diff changeset
182 "*Regexp describing line-beginnings that separate pages."
c8c9212a86a7 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17569
diff changeset
183 :group 'paragraphs
c8c9212a86a7 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17569
diff changeset
184 :type 'regexp)
264
7db4ff4204a5 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 237
diff changeset
185
19475
c8c9212a86a7 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17569
diff changeset
186 (defcustom paragraph-ignore-fill-prefix nil
c8c9212a86a7 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17569
diff changeset
187 "*Non-nil means the paragraph commands are not affected by `fill-prefix'.
c8c9212a86a7 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17569
diff changeset
188 This is desirable in modes where blank lines are the paragraph delimiters."
c8c9212a86a7 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17569
diff changeset
189 :group 'paragraphs
c8c9212a86a7 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17569
diff changeset
190 :type 'boolean)
264
7db4ff4204a5 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 237
diff changeset
191
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
192 (defun forward-paragraph (&optional arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
193 "Move forward to end of paragraph.
16757
e1c2e9a44236 (forward-paragraph, backward-paragraph): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 16687
diff changeset
194 With argument ARG, do it ARG times;
e1c2e9a44236 (forward-paragraph, backward-paragraph): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 16687
diff changeset
195 a negative argument ARG = -N means move backward N paragraphs.
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
196
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
197 A line which `paragraph-start' matches either separates paragraphs
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
198 \(if `paragraph-separate' matches it also) or is the first line of a paragraph.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
199 A paragraph end is the beginning of a line which is not part of the paragraph
47829
353dae5e0134 (forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47750
diff changeset
200 to which the end of the previous line belongs, or the end of the buffer.
353dae5e0134 (forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47750
diff changeset
201 Returns the count of paragraphs left to move."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
202 (interactive "p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
203 (or arg (setq arg 1))
26055
cf5dd9e8bf79 (forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents: 25551
diff changeset
204 (let* ((opoint (point))
cf5dd9e8bf79 (forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents: 25551
diff changeset
205 (fill-prefix-regexp
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
206 (and fill-prefix (not (equal fill-prefix ""))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
207 (not paragraph-ignore-fill-prefix)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
208 (regexp-quote fill-prefix)))
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
209 ;; 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
210 ;; 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
211 ;; 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
212 ;; work normally with indented text.
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
213 ;; 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
214 (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
215 (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
216 (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
217 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
218 (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
219 (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
220 (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
221 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
222 (parsep
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
223 (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
224 (concat parsep "\\|"
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
225 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
226 parsep))
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
227 ;; 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
228 (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
229 start found-start)
5608
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
230 (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
231 (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
232 (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
233 (looking-at parsep))
47829
353dae5e0134 (forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47750
diff changeset
234 (setq arg (1+ arg))
12717
8e153c7bbd90 (forward-paragraph): Don't move back over a line
Richard M. Stallman <rms@gnu.org>
parents: 11235
diff changeset
235 (setq start (point))
5608
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
236 ;; Move back over paragraph-separating lines.
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
237 (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
238 (while (and (not (bobp))
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
239 (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
240 (looking-at parsep)))
34655
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27837
diff changeset
241 (forward-line -1))
5608
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
242 (if (bobp)
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
243 nil
47829
353dae5e0134 (forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47750
diff changeset
244 (setq arg (1+ arg))
5608
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
245 ;; 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
246 (end-of-line)
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
247 ;; 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
248 (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
249 ;; 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
250 (let (multiple-lines)
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
251 (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
252 (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
253 (not (looking-at parsep)))
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
254 (looking-at fill-prefix-regexp))
34655
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27837
diff changeset
255 (unless (= (point) start)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27837
diff changeset
256 (setq multiple-lines t))
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
257 (forward-line -1))
12717
8e153c7bbd90 (forward-paragraph): Don't move back over a line
Richard M. Stallman <rms@gnu.org>
parents: 11235
diff changeset
258 (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
259 ;; 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
260 ;; 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
261 ;; ;; 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
262 ;; ;; 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
263 ;; ;; 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
264 ;; (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
265 ;; 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
266 ;; (forward-line 1))
12717
8e153c7bbd90 (forward-paragraph): Don't move back over a line
Richard M. Stallman <rms@gnu.org>
parents: 11235
diff changeset
267 (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
268 (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
269 (setq found-start t)
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
270 ;; 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
271 ;; REAL parstart.
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
272 (progn (setq start (point))
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
273 (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
274 (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
275 (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
276 (or (not use-hard-newlines)
57282
a35c6f55300f (forward-paragraph): Avoid args-out-of-range error when point winds up
Luc Teirlinck <teirllm@auburn.edu>
parents: 56941
diff changeset
277 (bobp)
a35c6f55300f (forward-paragraph): Avoid args-out-of-range error when point winds up
Luc Teirlinck <teirllm@auburn.edu>
parents: 56941
diff changeset
278 (get-text-property
a35c6f55300f (forward-paragraph): Avoid args-out-of-range error when point winds up
Luc Teirlinck <teirllm@auburn.edu>
parents: 56941
diff changeset
279 (1- start) 'hard)))))
22953
fbeacfb09096 (forward-paragraph): Fix the logic for handling beginning of buffer
Richard M. Stallman <rms@gnu.org>
parents: 19527
diff changeset
280 (setq found-start nil)
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
281 (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
282 found-start)
47829
353dae5e0134 (forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47750
diff changeset
283 ;; Found one.
353dae5e0134 (forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47750
diff changeset
284 (progn
5608
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
285 ;; Move forward over paragraph separators.
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
286 ;; 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
287 ;; 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
288 (while (and (not (eobp))
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
289 (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
290 (looking-at parsep)))
5608
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
291 (forward-line 1))
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
292 ;; 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
293 (end-of-line 0)
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
294 (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
295 (forward-char 1)
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
296 (skip-chars-backward " \t")
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
297 (if (not (bolp))
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
298 (forward-line 1))))
5608
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
299 ;; No starter or separator line => use buffer beg.
47829
353dae5e0134 (forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47750
diff changeset
300 (goto-char (point-min))))))
40485
ca833879aa7b (sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 40483
diff changeset
301
5608
c4c662362d39 (forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents: 4585
diff changeset
302 (while (and (> arg 0) (not (eobp)))
47829
353dae5e0134 (forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47750
diff changeset
303 ;; Move forward over separator lines...
353dae5e0134 (forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47750
diff changeset
304 (while (and (not (eobp))
353dae5e0134 (forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47750
diff changeset
305 (progn (move-to-left-margin) (not (eobp)))
353dae5e0134 (forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47750
diff changeset
306 (looking-at parsep))
353dae5e0134 (forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47750
diff changeset
307 (forward-line 1))
353dae5e0134 (forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47750
diff changeset
308 (unless (eobp) (setq arg (1- arg)))
353dae5e0134 (forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47750
diff changeset
309 ;; ... and one more line.
353dae5e0134 (forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47750
diff changeset
310 (forward-line 1)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
311 (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
312 ;; There is a fill prefix; it overrides parstart.
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
313 (while (and (not (eobp))
10864
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
314 (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
315 (not (looking-at parsep))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
316 (looking-at fill-prefix-regexp))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
317 (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
318 (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
319 (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
320 (goto-char start)
12804
1619fcabdb99 (forward-paragraph): Don't overlook a paragraph-start
Richard M. Stallman <rms@gnu.org>
parents: 12717
diff changeset
321 (not (eobp)))
1619fcabdb99 (forward-paragraph): Don't overlook a paragraph-start
Richard M. Stallman <rms@gnu.org>
parents: 12717
diff changeset
322 (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
323 (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
324 (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
325 (and use-hard-newlines
33769cbeb58e (paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents: 10464
diff changeset
326 (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
327 (forward-char 1))
6bcb93cec6f8 (forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents: 9169
diff changeset
328 (if (< (point) (point-max))
47829
353dae5e0134 (forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47750
diff changeset
329 (goto-char start))))
47750
75f4a9fc7b34 (forward-paragraph): Return the steps left.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 43384
diff changeset
330 (constrain-to-field nil opoint t)
75f4a9fc7b34 (forward-paragraph): Return the steps left.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 43384
diff changeset
331 ;; 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
332 arg))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
333
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
334 (defun backward-paragraph (&optional arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
335 "Move backward to start of paragraph.
16757
e1c2e9a44236 (forward-paragraph, backward-paragraph): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 16687
diff changeset
336 With argument ARG, do it ARG times;
e1c2e9a44236 (forward-paragraph, backward-paragraph): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 16687
diff changeset
337 a negative argument ARG = -N means move forward N paragraphs.
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
338
237
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
339 A paragraph start is the beginning of a line which is a
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
340 `first-line-of-paragraph' or which is ordinary text and follows a
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
341 paragraph-separating line; except: if the first real line of a
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
342 paragraph is preceded by a blank line, the paragraph starts at that
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
343 blank line.
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
344
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
345 See `forward-paragraph' for more information."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
346 (interactive "p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
347 (or arg (setq arg 1))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
348 (forward-paragraph (- arg)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
349
59179
4b5e5c2f1ee0 (mark-paragraph): New arg ALLOW-EXTEND
Richard M. Stallman <rms@gnu.org>
parents: 58919
diff changeset
350 (defun mark-paragraph (&optional arg allow-extend)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
351 "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
352 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
353
df0a6a02b580 (mark-paragraph): Clarify doc. Clarify
Kai Großjohann <kgrossjo@eu.uu.net>
parents: 40485
diff changeset
354 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
355 the number of paragraphs marked equals ARG.
df0a6a02b580 (mark-paragraph): Clarify doc. Clarify
Kai Großjohann <kgrossjo@eu.uu.net>
parents: 40485
diff changeset
356
df0a6a02b580 (mark-paragraph): Clarify doc. Clarify
Kai Großjohann <kgrossjo@eu.uu.net>
parents: 40485
diff changeset
357 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
358 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
359
59179
4b5e5c2f1ee0 (mark-paragraph): New arg ALLOW-EXTEND
Richard M. Stallman <rms@gnu.org>
parents: 58919
diff changeset
360 Interactively, if this command is repeated
4b5e5c2f1ee0 (mark-paragraph): New arg ALLOW-EXTEND
Richard M. Stallman <rms@gnu.org>
parents: 58919
diff changeset
361 or (in Transient Mark mode) if the mark is active,
4b5e5c2f1ee0 (mark-paragraph): New arg ALLOW-EXTEND
Richard M. Stallman <rms@gnu.org>
parents: 58919
diff changeset
362 it marks the next ARG paragraphs after the ones already marked."
4b5e5c2f1ee0 (mark-paragraph): New arg ALLOW-EXTEND
Richard M. Stallman <rms@gnu.org>
parents: 58919
diff changeset
363 (interactive "p\np")
43384
cc3ba2d0d471 * emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
parents: 43301
diff changeset
364 (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
365 (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
366 (error "Cannot mark zero paragraphs"))
59179
4b5e5c2f1ee0 (mark-paragraph): New arg ALLOW-EXTEND
Richard M. Stallman <rms@gnu.org>
parents: 58919
diff changeset
367 (cond ((and allow-extend
4b5e5c2f1ee0 (mark-paragraph): New arg ALLOW-EXTEND
Richard M. Stallman <rms@gnu.org>
parents: 58919
diff changeset
368 (or (and (eq last-command this-command) (mark t))
4b5e5c2f1ee0 (mark-paragraph): New arg ALLOW-EXTEND
Richard M. Stallman <rms@gnu.org>
parents: 58919
diff changeset
369 (and transient-mark-mode mark-active)))
43384
cc3ba2d0d471 * emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
parents: 43301
diff changeset
370 (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
371 (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
372 (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
373 (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
374 (point))))
cc3ba2d0d471 * emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
parents: 43301
diff changeset
375 (t
cc3ba2d0d471 * emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
parents: 43301
diff changeset
376 (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
377 (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
378 (backward-paragraph arg))))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
379
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
380 (defun kill-paragraph (arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
381 "Kill forward to end of paragraph.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
382 With arg N, kill forward to Nth end of paragraph;
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
383 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
384 (interactive "p")
7064
19a84bb30e9e (kill-paragraph): Don't use save-excursion.
Richard M. Stallman <rms@gnu.org>
parents: 5653
diff changeset
385 (kill-region (point) (progn (forward-paragraph arg) (point))))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
386
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
387 (defun backward-kill-paragraph (arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
388 "Kill back to start of paragraph.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
389 With arg N, kill back to Nth start of paragraph;
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
390 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
391 (interactive "p")
26055
cf5dd9e8bf79 (forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents: 25551
diff changeset
392 (kill-region (point) (progn (backward-paragraph arg) (point))))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
393
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
394 (defun transpose-paragraphs (arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
395 "Interchange this (or next) paragraph with previous one."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
396 (interactive "*p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
397 (transpose-subr 'forward-paragraph arg))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
398
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
399 (defun start-of-paragraph-text ()
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
400 (let ((opoint (point)) npoint)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
401 (forward-paragraph -1)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
402 (setq npoint (point))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
403 (skip-chars-forward " \t\n")
68
7680293d57f3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
404 ;; If the range of blank lines found spans the original start point,
7680293d57f3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
405 ;; try again from the beginning of it.
7680293d57f3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
406 ;; Must be careful to avoid infinite loop
7680293d57f3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
407 ;; when following a single return at start of buffer.
7680293d57f3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
408 (if (and (>= (point) opoint) (< npoint opoint))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
409 (progn
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
410 (goto-char npoint)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
411 (if (> npoint (point-min))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
412 (start-of-paragraph-text))))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
413
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
414 (defun end-of-paragraph-text ()
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
415 (let ((opoint (point)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
416 (forward-paragraph 1)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
417 (if (eq (preceding-char) ?\n) (forward-char -1))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
418 (if (<= (point) opoint)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
419 (progn
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
420 (forward-char 1)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
421 (if (< (point) (point-max))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
422 (end-of-paragraph-text))))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
423
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
424 (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
425 "Move forward to next `sentence-end'. With argument, repeat.
237
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
426 With negative argument, move backward repeatedly to `sentence-beginning'.
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
427
237
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
428 The variable `sentence-end' is a regular expression that matches ends of
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
429 sentences. Also, every paragraph boundary terminates sentences as well."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
430 (interactive "p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
431 (or arg (setq arg 1))
54977
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
432 (let ((opoint (point))
4c4f4e6f6bbf (sentence-end) <function>: New fun with default value taken
Juri Linkov <juri@jurta.org>
parents: 54014
diff changeset
433 (sentence-end (sentence-end)))
26055
cf5dd9e8bf79 (forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents: 25551
diff changeset
434 (while (< arg 0)
38715
06ad87abb7a4 (forward-sentence): Avoid building
Gerd Moellmann <gerd@gnu.org>
parents: 38412
diff changeset
435 (let ((pos (point))
06ad87abb7a4 (forward-sentence): Avoid building
Gerd Moellmann <gerd@gnu.org>
parents: 38412
diff changeset
436 (par-beg (save-excursion (start-of-paragraph-text) (point))))
06ad87abb7a4 (forward-sentence): Avoid building
Gerd Moellmann <gerd@gnu.org>
parents: 38412
diff changeset
437 (if (and (re-search-backward sentence-end par-beg t)
06ad87abb7a4 (forward-sentence): Avoid building
Gerd Moellmann <gerd@gnu.org>
parents: 38412
diff changeset
438 (or (< (match-end 0) pos)
06ad87abb7a4 (forward-sentence): Avoid building
Gerd Moellmann <gerd@gnu.org>
parents: 38412
diff changeset
439 (re-search-backward sentence-end par-beg t)))
06ad87abb7a4 (forward-sentence): Avoid building
Gerd Moellmann <gerd@gnu.org>
parents: 38412
diff changeset
440 (goto-char (match-end 0))
26055
cf5dd9e8bf79 (forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents: 25551
diff changeset
441 (goto-char par-beg)))
cf5dd9e8bf79 (forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents: 25551
diff changeset
442 (setq arg (1+ arg)))
cf5dd9e8bf79 (forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents: 25551
diff changeset
443 (while (> arg 0)
cf5dd9e8bf79 (forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents: 25551
diff changeset
444 (let ((par-end (save-excursion (end-of-paragraph-text) (point))))
cf5dd9e8bf79 (forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents: 25551
diff changeset
445 (if (re-search-forward sentence-end par-end t)
cf5dd9e8bf79 (forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents: 25551
diff changeset
446 (skip-chars-backward " \t\n")
cf5dd9e8bf79 (forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents: 25551
diff changeset
447 (goto-char par-end)))
cf5dd9e8bf79 (forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents: 25551
diff changeset
448 (setq arg (1- arg)))
cf5dd9e8bf79 (forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents: 25551
diff changeset
449 (constrain-to-field nil opoint t)))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
450
51159
7d324048f346 (repunctuate-sentences): New function.
Richard M. Stallman <rms@gnu.org>
parents: 49949
diff changeset
451 (defun repunctuate-sentences ()
7d324048f346 (repunctuate-sentences): New function.
Richard M. Stallman <rms@gnu.org>
parents: 49949
diff changeset
452 "Put two spaces at the end of sentences from point to the end of buffer.
7d324048f346 (repunctuate-sentences): New function.
Richard M. Stallman <rms@gnu.org>
parents: 49949
diff changeset
453 It works using `query-replace-regexp'."
54014
6296b1d1ae51 * net/telnet.el (telnet-interrupt-subjob): Move doc string to the correct place.
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53721
diff changeset
454 (interactive)
51159
7d324048f346 (repunctuate-sentences): New function.
Richard M. Stallman <rms@gnu.org>
parents: 49949
diff changeset
455 (query-replace-regexp "\\([]\"')]?\\)\\([.?!]\\)\\([]\"')]?\\) +"
7d324048f346 (repunctuate-sentences): New function.
Richard M. Stallman <rms@gnu.org>
parents: 49949
diff changeset
456 "\\1\\2\\3 "))
7d324048f346 (repunctuate-sentences): New function.
Richard M. Stallman <rms@gnu.org>
parents: 49949
diff changeset
457
7d324048f346 (repunctuate-sentences): New function.
Richard M. Stallman <rms@gnu.org>
parents: 49949
diff changeset
458
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
459 (defun backward-sentence (&optional arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
460 "Move backward to start of sentence. With arg, do it arg times.
237
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
461 See `forward-sentence' for more information."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
462 (interactive "p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
463 (or arg (setq arg 1))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
464 (forward-sentence (- arg)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
465
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
466 (defun kill-sentence (&optional arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
467 "Kill from point to end of sentence.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
468 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
469 (interactive "p")
7064
19a84bb30e9e (kill-paragraph): Don't use save-excursion.
Richard M. Stallman <rms@gnu.org>
parents: 5653
diff changeset
470 (kill-region (point) (progn (forward-sentence arg) (point))))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
471
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
472 (defun backward-kill-sentence (&optional arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
473 "Kill back from point to start of sentence.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
474 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
475 (interactive "p")
26055
cf5dd9e8bf79 (forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents: 25551
diff changeset
476 (kill-region (point) (progn (backward-sentence arg) (point))))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
477
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
478 (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
479 "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
480 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
481 ones already marked."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
482 (interactive "p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
483 (push-mark
43301
898b4b31410f * lisp/simple.el (mark-word): Mark more if repeated.
Kai Großjohann <kgrossjo@eu.uu.net>
parents: 41709
diff changeset
484 (save-excursion
898b4b31410f * lisp/simple.el (mark-word): Mark more if repeated.
Kai Großjohann <kgrossjo@eu.uu.net>
parents: 41709
diff changeset
485 (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
486 (goto-char (mark)))
898b4b31410f * lisp/simple.el (mark-word): Mark more if repeated.
Kai Großjohann <kgrossjo@eu.uu.net>
parents: 41709
diff changeset
487 (forward-sentence arg)
898b4b31410f * lisp/simple.el (mark-word): Mark more if repeated.
Kai Großjohann <kgrossjo@eu.uu.net>
parents: 41709
diff changeset
488 (point))
898b4b31410f * lisp/simple.el (mark-word): Mark more if repeated.
Kai Großjohann <kgrossjo@eu.uu.net>
parents: 41709
diff changeset
489 nil t))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
490
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
491 (defun transpose-sentences (arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
492 "Interchange this (next) and previous sentence."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
493 (interactive "*p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
494 (transpose-subr 'forward-sentence arg))
659
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 269
diff changeset
495
49949
098ddf9714e8 (sentence-end): Add Chinese and Japanese characters.
Kenichi Handa <handa@m17n.org>
parents: 49599
diff changeset
496 ;;; Local Variables:
098ddf9714e8 (sentence-end): Add Chinese and Japanese characters.
Kenichi Handa <handa@m17n.org>
parents: 49599
diff changeset
497 ;;; coding: iso-2022-7bit
098ddf9714e8 (sentence-end): Add Chinese and Japanese characters.
Kenichi Handa <handa@m17n.org>
parents: 49599
diff changeset
498 ;;; End:
098ddf9714e8 (sentence-end): Add Chinese and Japanese characters.
Kenichi Handa <handa@m17n.org>
parents: 49599
diff changeset
499
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 51159
diff changeset
500 ;;; arch-tag: e727eb1a-527a-4464-b9d7-9d3ec0d1a575
659
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 269
diff changeset
501 ;;; paragraphs.el ends here