38412
|
1 ;;; paragraphs.el --- paragraph and sentence parsing
|
659
|
2
|
64751
|
3 ;; Copyright (C) 1985, 1986, 1987, 1991, 1994, 1995, 1996, 1997, 1999, 2000,
|
100908
|
4 ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
|
845
|
5
|
789
|
6 ;; Maintainer: FSF
|
814
|
7 ;; Keywords: wp
|
789
|
8
|
36
|
9 ;; This file is part of GNU Emacs.
|
|
10
|
94670
|
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
|
36
|
12 ;; it under the terms of the GNU General Public License as published by
|
94670
|
13 ;; the Free Software Foundation, either version 3 of the License, or
|
|
14 ;; (at your option) any later version.
|
36
|
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
|
94670
|
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
36
|
23
|
2308
|
24 ;;; Commentary:
|
|
25
|
|
26 ;; This package provides the paragraph-oriented commands documented in the
|
|
27 ;; Emacs manual.
|
|
28
|
789
|
29 ;;; Code:
|
36
|
30
|
19475
|
31 (defgroup paragraphs nil
|
|
32 "Paragraph and sentence parsing."
|
|
33 :group 'editing)
|
|
34
|
56941
|
35 (put 'use-hard-newlines 'permanent-local t)
|
40483
|
36 (define-minor-mode use-hard-newlines
|
16019
|
37 "Minor mode to distinguish hard and soft newlines.
|
|
38 When active, the functions `newline' and `open-line' add the
|
|
39 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>
diff
changeset
|
40 only considered as a candidate to match `paragraph-start' or
|
16019
|
41 `paragraph-separate' if it follows a hard newline.
|
|
42
|
|
43 Prefix argument says to turn mode on if positive, off if negative.
|
|
44 When the mode is turned on, if there are newlines in the buffer but no hard
|
49599
|
45 newlines, ask the user whether to mark as hard any newlines preceeding a
|
16019
|
46 `paragraph-start' line. From a program, second arg INSERT specifies whether
|
|
47 to do this; it can be `never' to change nothing, t or `always' to force
|
49599
|
48 marking, `guess' to try to do the right thing with no questions, nil
|
16019
|
49 or anything else to ask the user.
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
50
|
16019
|
51 Newlines not marked hard are called \"soft\", and are always internal
|
|
52 to paragraphs. The fill functions insert and delete only soft newlines."
|
48401
|
53 :group 'paragraphs
|
40483
|
54 :extra-args (insert)
|
|
55 (when use-hard-newlines
|
16019
|
56 ;; Turn mode on
|
|
57 ;; Intuit hard newlines --
|
|
58 ;; mark as hard any newlines preceding a paragraph-start line.
|
|
59 (if (or (eq insert t) (eq insert 'always)
|
|
60 (and (not (eq 'never insert))
|
|
61 (not (text-property-any (point-min) (point-max) 'hard t))
|
|
62 (save-excursion
|
|
63 (goto-char (point-min))
|
|
64 (search-forward "\n" nil t))
|
|
65 (or (eq insert 'guess)
|
|
66 (y-or-n-p "Make newlines between paragraphs hard? "))))
|
|
67 (save-excursion
|
|
68 (goto-char (point-min))
|
|
69 (while (search-forward "\n" nil t)
|
|
70 (let ((pos (point)))
|
|
71 (move-to-left-margin)
|
40483
|
72 (when (looking-at paragraph-start)
|
|
73 (set-hard-newline-properties (1- pos) pos))
|
|
74 ;; If paragraph-separate, newline after it is hard too.
|
|
75 (when (looking-at paragraph-separate)
|
|
76 (set-hard-newline-properties (1- pos) pos)
|
|
77 (end-of-line)
|
|
78 (unless (eobp)
|
|
79 (set-hard-newline-properties (point) (1+ (point)))))))))))
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
80
|
40483
|
81 (defcustom paragraph-start "\f\\|[ \t]*$" "\
|
70270
|
82 Regexp for beginning of a line that starts OR separates paragraphs.
|
4585
|
83 This regexp should match lines that separate paragraphs
|
|
84 and should also match lines that start a paragraph
|
|
85 \(and are part of that paragraph).
|
10424
|
86
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
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>
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>
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>
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>
diff
changeset
|
91
|
4585
|
92 The variable `paragraph-separate' specifies how to distinguish
|
10424
|
93 lines that start paragraphs from lines that separate them.
|
|
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)
|
92948
|
99 (put 'paragraph-start 'safe-local-variable 'stringp)
|
264
|
100
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
101 ;; 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>
diff
changeset
|
102 ;; 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>
diff
changeset
|
103 ;; 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>
diff
changeset
|
104 ;; 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>
diff
changeset
|
105 ;; start a new paragraph).
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
106
|
19475
|
107 (defcustom paragraph-separate "[ \t\f]*$"
|
70270
|
108 "Regexp for beginning of a line that separates paragraphs.
|
24309
|
109 If you change this, you may have to change `paragraph-start' also.
|
10424
|
110
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
111 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>
diff
changeset
|
112 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>
diff
changeset
|
113 ensures that the paragraph functions will work equally within a region of
|
19475
|
114 text indented by a margin setting."
|
|
115 :group 'paragraphs
|
|
116 :type 'regexp)
|
92948
|
117 (put 'paragraph-separate 'safe-local-variable 'stringp)
|
264
|
118
|
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
119 (defcustom sentence-end-double-space t
|
70270
|
120 "Non-nil means a single space does not end a sentence.
|
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
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>
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>
diff
changeset
|
123
|
54977
|
124 This value is used by the function `sentence-end' to construct the
|
57405
|
125 regexp describing the end of a sentence, when the value of the variable
|
|
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>
diff
changeset
|
127 :type 'boolean
|
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
128 :group 'fill)
|
92948
|
129 (put 'sentence-end-double-space 'safe-local-variable 'booleanp)
|
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
130
|
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
131 (defcustom sentence-end-without-period nil
|
70270
|
132 "Non-nil means a sentence will end without a period.
|
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
133 For example, a sentence in Thai text ends with double space but
|
54977
|
134 without a period.
|
|
135
|
|
136 This value is used by the function `sentence-end' to construct the
|
57405
|
137 regexp describing the end of a sentence, when the value of the variable
|
|
138 `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>
diff
changeset
|
139 :type 'boolean
|
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
140 :group 'fill)
|
92948
|
141 (put 'sentence-end-without-period 'safe-local-variable 'booleanp)
|
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
142
|
53721
|
143 (defcustom sentence-end-without-space
|
104323
|
144 "��鐚��鐚�"
|
70270
|
145 "String of characters that end sentence without following spaces.
|
54977
|
146
|
|
147 This value is used by the function `sentence-end' to construct the
|
57405
|
148 regexp describing the end of a sentence, when the value of the variable
|
|
149 `sentence-end' is nil. See Info node `(elisp)Standard Regexps'."
|
53721
|
150 :group 'paragraphs
|
|
151 :type 'string)
|
92948
|
152 (put 'sentence-end-without-space 'safe-local-variable 'stringp)
|
53721
|
153
|
54977
|
154 (defcustom sentence-end nil
|
70270
|
155 "Regexp describing the end of a sentence.
|
37415
|
156 The value includes the whitespace following the sentence.
|
2503
|
157 All paragraph boundaries also end sentences, regardless.
|
|
158
|
54977
|
159 The value nil means to use the default value defined by the
|
|
160 function `sentence-end'. You should always use this function
|
|
161 to obtain the value of this variable."
|
|
162 :group 'paragraphs
|
|
163 :type '(choice regexp (const :tag "Use default value" nil)))
|
92948
|
164 (put 'sentence-end 'safe-local-variable 'string-or-null-p)
|
54977
|
165
|
104323
|
166 (defcustom sentence-end-base "[.?!][]\"'��)}]*"
|
70270
|
167 "Regexp matching the basic end of a sentence, not including following space."
|
66292
|
168 :group 'paragraphs
|
|
169 :type 'string
|
|
170 :version "22.1")
|
92948
|
171 (put 'sentence-end-base 'safe-local-variable 'stringp)
|
66292
|
172
|
54977
|
173 (defun sentence-end ()
|
|
174 "Return the regexp describing the end of a sentence.
|
24472
|
175
|
54977
|
176 This function returns either the value of the variable `sentence-end'
|
|
177 if it is non-nil, or the default value constructed from the
|
66292
|
178 variables `sentence-end-base', `sentence-end-double-space',
|
|
179 `sentence-end-without-period' and `sentence-end-without-space'.
|
|
180
|
|
181 The default value specifies that in order to be recognized as the
|
|
182 end of a sentence, the ending period, question mark, or exclamation point
|
|
183 must be followed by two spaces, with perhaps some closing delimiters
|
|
184 in between. See Info node `(elisp)Standard Regexps'."
|
54977
|
185 (or sentence-end
|
101218
|
186 ;; We accept non-break space along with space.
|
|
187 (concat (if sentence-end-without-period "\\w[ \u00a0][ \u00a0]\\|")
|
66292
|
188 "\\("
|
|
189 sentence-end-base
|
54977
|
190 (if sentence-end-double-space
|
101218
|
191 "\\($\\|[ \u00a0]$\\|\t\\|[ \u00a0][ \u00a0]\\)" "\\($\\|[\t \u00a0]\\)")
|
66292
|
192 "\\|[" sentence-end-without-space "]+"
|
|
193 "\\)"
|
101218
|
194 "[ \u00a0\t\n]*")))
|
264
|
195
|
19475
|
196 (defcustom page-delimiter "^\014"
|
70270
|
197 "Regexp describing line-beginnings that separate pages."
|
19475
|
198 :group 'paragraphs
|
|
199 :type 'regexp)
|
92948
|
200 (put 'page-delimiter 'safe-local-variable 'stringp)
|
264
|
201
|
19475
|
202 (defcustom paragraph-ignore-fill-prefix nil
|
70270
|
203 "Non-nil means the paragraph commands are not affected by `fill-prefix'.
|
19475
|
204 This is desirable in modes where blank lines are the paragraph delimiters."
|
|
205 :group 'paragraphs
|
|
206 :type 'boolean)
|
92948
|
207 (put 'paragraph-ignore-fill-prefix 'safe-local-variable 'booleanp)
|
264
|
208
|
36
|
209 (defun forward-paragraph (&optional arg)
|
|
210 "Move forward to end of paragraph.
|
16757
|
211 With argument ARG, do it ARG times;
|
|
212 a negative argument ARG = -N means move backward N paragraphs.
|
36
|
213
|
|
214 A line which `paragraph-start' matches either separates paragraphs
|
|
215 \(if `paragraph-separate' matches it also) or is the first line of a paragraph.
|
|
216 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>
diff
changeset
|
217 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>
diff
changeset
|
218 Returns the count of paragraphs left to move."
|
93550
|
219 (interactive "^p")
|
36
|
220 (or arg (setq arg 1))
|
26055
|
221 (let* ((opoint (point))
|
|
222 (fill-prefix-regexp
|
36
|
223 (and fill-prefix (not (equal fill-prefix ""))
|
|
224 (not paragraph-ignore-fill-prefix)
|
|
225 (regexp-quote fill-prefix)))
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
226 ;; 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>
diff
changeset
|
227 ;; 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>
diff
changeset
|
228 ;; 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>
diff
changeset
|
229 ;; work normally with indented text.
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
230 ;; 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>
diff
changeset
|
231 (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>
diff
changeset
|
232 (equal ?^ (aref paragraph-start 0)))
|
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
233 (substring paragraph-start 1)
|
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
234 paragraph-start))
|
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
235 (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>
diff
changeset
|
236 (equal ?^ (aref paragraph-separate 0)))
|
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
237 (substring paragraph-separate 1)
|
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
238 paragraph-separate))
|
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
239 (parsep
|
36
|
240 (if fill-prefix-regexp
|
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
241 (concat parsep "\\|"
|
36
|
242 fill-prefix-regexp "[ \t]*$")
|
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
243 parsep))
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
244 ;; 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>
diff
changeset
|
245 (sp-parstart (concat "^[ \t]*\\(?:" parstart "\\|" parsep "\\)"))
|
22953
fbeacfb09096
(forward-paragraph): Fix the logic for handling beginning of buffer
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
246 start found-start)
|
5608
|
247 (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>
diff
changeset
|
248 (if (and (not (looking-at parsep))
|
10424
|
249 (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>
diff
changeset
|
250 (looking-at parsep))
|
47829
353dae5e0134
(forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
251 (setq arg (1+ arg))
|
12717
|
252 (setq start (point))
|
5608
|
253 ;; Move back over paragraph-separating lines.
|
36
|
254 (forward-char -1) (beginning-of-line)
|
10424
|
255 (while (and (not (bobp))
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
256 (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>
diff
changeset
|
257 (looking-at parsep)))
|
34655
|
258 (forward-line -1))
|
5608
|
259 (if (bobp)
|
|
260 nil
|
47829
353dae5e0134
(forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
261 (setq arg (1+ arg))
|
5608
|
262 ;; Go to end of the previous (non-separating) line.
|
|
263 (end-of-line)
|
|
264 ;; Search back for line that starts or separates paragraphs.
|
|
265 (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>
diff
changeset
|
266 ;; There is a fill prefix; it overrides parstart.
|
12717
|
267 (let (multiple-lines)
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
268 (while (and (progn (beginning-of-line) (not (bobp)))
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
269 (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>
diff
changeset
|
270 (not (looking-at parsep)))
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
271 (looking-at fill-prefix-regexp))
|
34655
|
272 (unless (= (point) start)
|
|
273 (setq multiple-lines t))
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
274 (forward-line -1))
|
12717
|
275 (move-to-left-margin)
|
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
276 ;; 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>
diff
changeset
|
277 ;; 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>
diff
changeset
|
278 ;; ;; 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>
diff
changeset
|
279 ;; ;; 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>
diff
changeset
|
280 ;; ;; 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>
diff
changeset
|
281 ;; (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>
diff
changeset
|
282 ;; multiple-lines
|
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
283 ;; (forward-line 1))
|
12717
|
284 (not (bobp)))
|
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
285 (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>
diff
changeset
|
286 (setq found-start t)
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
287 ;; 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>
diff
changeset
|
288 ;; REAL parstart.
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
289 (progn (setq start (point))
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
290 (move-to-left-margin)
|
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
291 (not (looking-at parsep)))
|
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
292 (not (and (looking-at parstart)
|
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
293 (or (not use-hard-newlines)
|
57282
a35c6f55300f
(forward-paragraph): Avoid args-out-of-range error when point winds up
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
294 (bobp)
|
a35c6f55300f
(forward-paragraph): Avoid args-out-of-range error when point winds up
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
295 (get-text-property
|
a35c6f55300f
(forward-paragraph): Avoid args-out-of-range error when point winds up
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
296 (1- start) 'hard)))))
|
22953
fbeacfb09096
(forward-paragraph): Fix the logic for handling beginning of buffer
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
297 (setq found-start nil)
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
298 (goto-char start))
|
22953
fbeacfb09096
(forward-paragraph): Fix the logic for handling beginning of buffer
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
299 found-start)
|
47829
353dae5e0134
(forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
300 ;; Found one.
|
353dae5e0134
(forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
301 (progn
|
5608
|
302 ;; Move forward over paragraph separators.
|
|
303 ;; We know this cannot reach the place we started
|
|
304 ;; 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>
diff
changeset
|
305 (while (and (not (eobp))
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
306 (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>
diff
changeset
|
307 (looking-at parsep)))
|
5608
|
308 (forward-line 1))
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
309 ;; 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>
diff
changeset
|
310 (end-of-line 0)
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
311 (if (> (current-column) (current-left-margin))
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
312 (forward-char 1)
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
313 (skip-chars-backward " \t")
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
314 (if (not (bolp))
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
315 (forward-line 1))))
|
5608
|
316 ;; 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>
diff
changeset
|
317 (goto-char (point-min))))))
|
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
318
|
5608
|
319 (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>
diff
changeset
|
320 ;; Move forward over separator lines...
|
353dae5e0134
(forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
321 (while (and (not (eobp))
|
353dae5e0134
(forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
322 (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>
diff
changeset
|
323 (looking-at parsep))
|
353dae5e0134
(forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
324 (forward-line 1))
|
353dae5e0134
(forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
325 (unless (eobp) (setq arg (1- arg)))
|
353dae5e0134
(forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
326 ;; ... and one more line.
|
353dae5e0134
(forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
327 (forward-line 1)
|
36
|
328 (if fill-prefix-regexp
|
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
329 ;; There is a fill prefix; it overrides parstart.
|
36
|
330 (while (and (not (eobp))
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
331 (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>
diff
changeset
|
332 (not (looking-at parsep))
|
36
|
333 (looking-at fill-prefix-regexp))
|
|
334 (forward-line 1))
|
40485
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
335 (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>
diff
changeset
|
336 (progn (setq start (match-beginning 0))
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
337 (goto-char start)
|
12804
|
338 (not (eobp)))
|
|
339 (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>
diff
changeset
|
340 (not (looking-at parsep)))
|
ca833879aa7b
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
341 (or (not (looking-at parstart))
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
342 (and use-hard-newlines
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
diff
changeset
|
343 (not (get-text-property (1- start) 'hard)))))
|
10424
|
344 (forward-char 1))
|
|
345 (if (< (point) (point-max))
|
47829
353dae5e0134
(forward-paragraph): Keep track of remaining paragraphs to skip more carefully.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
346 (goto-char start))))
|
47750
|
347 (constrain-to-field nil opoint t)
|
|
348 ;; Return the number of steps that could not be done.
|
|
349 arg))
|
36
|
350
|
|
351 (defun backward-paragraph (&optional arg)
|
|
352 "Move backward to start of paragraph.
|
16757
|
353 With argument ARG, do it ARG times;
|
|
354 a negative argument ARG = -N means move forward N paragraphs.
|
36
|
355
|
237
|
356 A paragraph start is the beginning of a line which is a
|
80507
|
357 `paragraph-start' or which is ordinary text and follows a
|
|
358 `paragraph-separate'ing line; except: if the first real line of a
|
237
|
359 paragraph is preceded by a blank line, the paragraph starts at that
|
|
360 blank line.
|
|
361
|
|
362 See `forward-paragraph' for more information."
|
93550
|
363 (interactive "^p")
|
36
|
364 (or arg (setq arg 1))
|
|
365 (forward-paragraph (- arg)))
|
|
366
|
59179
|
367 (defun mark-paragraph (&optional arg allow-extend)
|
36
|
368 "Put point at beginning of this paragraph, mark at end.
|
41709
|
369 The paragraph marked is the one that contains point or follows point.
|
|
370
|
|
371 With argument ARG, puts mark at end of a following paragraph, so that
|
|
372 the number of paragraphs marked equals ARG.
|
|
373
|
|
374 If ARG is negative, point is put at end of this paragraph, mark is put
|
43301
|
375 at beginning of this or a previous paragraph.
|
|
376
|
59179
|
377 Interactively, if this command is repeated
|
64751
|
378 or (in Transient Mark mode) if the mark is active,
|
59179
|
379 it marks the next ARG paragraphs after the ones already marked."
|
|
380 (interactive "p\np")
|
43384
cc3ba2d0d471
* emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
diff
changeset
|
381 (unless arg (setq arg 1))
|
cc3ba2d0d471
* emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
diff
changeset
|
382 (when (zerop arg)
|
cc3ba2d0d471
* emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
diff
changeset
|
383 (error "Cannot mark zero paragraphs"))
|
59179
|
384 (cond ((and allow-extend
|
|
385 (or (and (eq last-command this-command) (mark t))
|
|
386 (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>
diff
changeset
|
387 (set-mark
|
cc3ba2d0d471
* emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
diff
changeset
|
388 (save-excursion
|
cc3ba2d0d471
* emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
diff
changeset
|
389 (goto-char (mark))
|
cc3ba2d0d471
* emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
diff
changeset
|
390 (forward-paragraph arg)
|
cc3ba2d0d471
* emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
diff
changeset
|
391 (point))))
|
cc3ba2d0d471
* emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
diff
changeset
|
392 (t
|
cc3ba2d0d471
* emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
diff
changeset
|
393 (forward-paragraph arg)
|
cc3ba2d0d471
* emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
diff
changeset
|
394 (push-mark nil t t)
|
cc3ba2d0d471
* emacs-lisp/lisp.el (mark-defun): Don't leave multiple marks
Kai Großjohann <kgrossjo@eu.uu.net>
diff
changeset
|
395 (backward-paragraph arg))))
|
36
|
396
|
|
397 (defun kill-paragraph (arg)
|
|
398 "Kill forward to end of paragraph.
|
|
399 With arg N, kill forward to Nth end of paragraph;
|
|
400 negative arg -N means kill backward to Nth start of paragraph."
|
27837
|
401 (interactive "p")
|
7064
|
402 (kill-region (point) (progn (forward-paragraph arg) (point))))
|
36
|
403
|
|
404 (defun backward-kill-paragraph (arg)
|
|
405 "Kill back to start of paragraph.
|
|
406 With arg N, kill back to Nth start of paragraph;
|
|
407 negative arg -N means kill forward to Nth end of paragraph."
|
27837
|
408 (interactive "p")
|
26055
|
409 (kill-region (point) (progn (backward-paragraph arg) (point))))
|
36
|
410
|
|
411 (defun transpose-paragraphs (arg)
|
|
412 "Interchange this (or next) paragraph with previous one."
|
|
413 (interactive "*p")
|
|
414 (transpose-subr 'forward-paragraph arg))
|
|
415
|
|
416 (defun start-of-paragraph-text ()
|
|
417 (let ((opoint (point)) npoint)
|
|
418 (forward-paragraph -1)
|
|
419 (setq npoint (point))
|
|
420 (skip-chars-forward " \t\n")
|
68
|
421 ;; If the range of blank lines found spans the original start point,
|
|
422 ;; try again from the beginning of it.
|
|
423 ;; Must be careful to avoid infinite loop
|
|
424 ;; when following a single return at start of buffer.
|
|
425 (if (and (>= (point) opoint) (< npoint opoint))
|
36
|
426 (progn
|
|
427 (goto-char npoint)
|
|
428 (if (> npoint (point-min))
|
|
429 (start-of-paragraph-text))))))
|
|
430
|
|
431 (defun end-of-paragraph-text ()
|
|
432 (let ((opoint (point)))
|
|
433 (forward-paragraph 1)
|
|
434 (if (eq (preceding-char) ?\n) (forward-char -1))
|
|
435 (if (<= (point) opoint)
|
|
436 (progn
|
|
437 (forward-char 1)
|
|
438 (if (< (point) (point-max))
|
|
439 (end-of-paragraph-text))))))
|
|
440
|
|
441 (defun forward-sentence (&optional arg)
|
79458
|
442 "Move forward to next end of sentence. With argument, repeat.
|
|
443 With negative argument, move backward repeatedly to start of sentence.
|
36
|
444
|
237
|
445 The variable `sentence-end' is a regular expression that matches ends of
|
|
446 sentences. Also, every paragraph boundary terminates sentences as well."
|
93550
|
447 (interactive "^p")
|
36
|
448 (or arg (setq arg 1))
|
54977
|
449 (let ((opoint (point))
|
|
450 (sentence-end (sentence-end)))
|
26055
|
451 (while (< arg 0)
|
38715
|
452 (let ((pos (point))
|
101137
|
453 ;; We used to use (start-of-paragraph-text), but this can
|
|
454 ;; prevent sentence-end from matching if it is anchored at
|
|
455 ;; BOL and the paragraph starts indented.
|
|
456 (par-beg (save-excursion (backward-paragraph) (point))))
|
38715
|
457 (if (and (re-search-backward sentence-end par-beg t)
|
|
458 (or (< (match-end 0) pos)
|
|
459 (re-search-backward sentence-end par-beg t)))
|
|
460 (goto-char (match-end 0))
|
26055
|
461 (goto-char par-beg)))
|
|
462 (setq arg (1+ arg)))
|
|
463 (while (> arg 0)
|
|
464 (let ((par-end (save-excursion (end-of-paragraph-text) (point))))
|
|
465 (if (re-search-forward sentence-end par-end t)
|
|
466 (skip-chars-backward " \t\n")
|
|
467 (goto-char par-end)))
|
|
468 (setq arg (1- arg)))
|
|
469 (constrain-to-field nil opoint t)))
|
36
|
470
|
51159
|
471 (defun repunctuate-sentences ()
|
|
472 "Put two spaces at the end of sentences from point to the end of buffer.
|
|
473 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>
diff
changeset
|
474 (interactive)
|
51159
|
475 (query-replace-regexp "\\([]\"')]?\\)\\([.?!]\\)\\([]\"')]?\\) +"
|
|
476 "\\1\\2\\3 "))
|
|
477
|
|
478
|
36
|
479 (defun backward-sentence (&optional arg)
|
|
480 "Move backward to start of sentence. With arg, do it arg times.
|
237
|
481 See `forward-sentence' for more information."
|
93550
|
482 (interactive "^p")
|
36
|
483 (or arg (setq arg 1))
|
|
484 (forward-sentence (- arg)))
|
|
485
|
|
486 (defun kill-sentence (&optional arg)
|
|
487 "Kill from point to end of sentence.
|
|
488 With arg, repeat; negative arg -N means kill back to Nth start of sentence."
|
27837
|
489 (interactive "p")
|
7064
|
490 (kill-region (point) (progn (forward-sentence arg) (point))))
|
36
|
491
|
|
492 (defun backward-kill-sentence (&optional arg)
|
|
493 "Kill back from point to start of sentence.
|
|
494 With arg, repeat, or kill forward to Nth end of sentence if negative arg -N."
|
27837
|
495 (interactive "p")
|
26055
|
496 (kill-region (point) (progn (backward-sentence arg) (point))))
|
36
|
497
|
|
498 (defun mark-end-of-sentence (arg)
|
43301
|
499 "Put mark at end of sentence. Arg works as in `forward-sentence'.
|
|
500 If this command is repeated, it marks the next ARG sentences after the
|
|
501 ones already marked."
|
36
|
502 (interactive "p")
|
|
503 (push-mark
|
43301
|
504 (save-excursion
|
|
505 (if (and (eq last-command this-command) (mark t))
|
|
506 (goto-char (mark)))
|
|
507 (forward-sentence arg)
|
|
508 (point))
|
|
509 nil t))
|
36
|
510
|
|
511 (defun transpose-sentences (arg)
|
|
512 "Interchange this (next) and previous sentence."
|
|
513 (interactive "*p")
|
|
514 (transpose-subr 'forward-sentence arg))
|
659
|
515
|
66422
|
516 ;; Local Variables:
|
104323
|
517 ;; coding: utf-8
|
66422
|
518 ;; End:
|
49949
|
519
|
66422
|
520 ;; arch-tag: e727eb1a-527a-4464-b9d7-9d3ec0d1a575
|
659
|
521 ;;; paragraphs.el ends here
|