Mercurial > emacs
annotate lisp/textmodes/paragraphs.el @ 28923:dcafe3c9cd6c
(sh-while-getopts) <sh>: Handle case that
user-specified option string is empty.
| author | Gerd Moellmann <gerd@gnu.org> |
|---|---|
| date | Mon, 15 May 2000 20:14:39 +0000 |
| parents | 46fedf13d52e |
| children | 858c5f92cae6 |
| rev | line source |
|---|---|
|
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
269
diff
changeset
|
1 ;;; paragraphs.el --- paragraph and sentence parsing. |
|
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
269
diff
changeset
|
2 |
|
26055
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
3 ;; Copyright (C) 1985, 86, 87, 91, 94, 95, 96, 1997, 1999 |
| 19475 | 4 ;; Free Software Foundation, Inc. |
| 845 | 5 |
|
789
71d052f72ac1
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
6 ;; Maintainer: FSF |
|
814
38b2499cb3e9
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
804
diff
changeset
|
7 ;; Keywords: wp |
|
789
71d052f72ac1
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
8 |
| 36 | 9 ;; This file is part of GNU Emacs. |
| 10 | |
| 11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
| 12 ;; it under the terms of the GNU General Public License as published by | |
| 804 | 13 ;; the Free Software Foundation; either version 2, or (at your option) |
| 36 | 14 ;; any later version. |
| 15 | |
| 16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
| 17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 19 ;; GNU General Public License for more details. | |
| 20 | |
| 21 ;; You should have received a copy of the GNU General Public License | |
| 14169 | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
| 23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
| 24 ;; Boston, MA 02111-1307, USA. | |
| 36 | 25 |
|
2308
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1462
diff
changeset
|
26 ;;; Commentary: |
|
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1462
diff
changeset
|
27 |
|
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1462
diff
changeset
|
28 ;; This package provides the paragraph-oriented commands documented in the |
|
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1462
diff
changeset
|
29 ;; Emacs manual. |
|
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1462
diff
changeset
|
30 |
|
789
71d052f72ac1
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
31 ;;; Code: |
| 36 | 32 |
| 19475 | 33 (defgroup paragraphs nil |
| 34 "Paragraph and sentence parsing." | |
| 35 :group 'editing) | |
| 36 | |
|
19527
cec6bad39e23
(use-hard-newlines): Un-customized.
Richard M. Stallman <rms@gnu.org>
parents:
19475
diff
changeset
|
37 ;; It isn't useful to use defcustom for this variable |
|
cec6bad39e23
(use-hard-newlines): Un-customized.
Richard M. Stallman <rms@gnu.org>
parents:
19475
diff
changeset
|
38 ;; because it is always buffer-local. |
|
cec6bad39e23
(use-hard-newlines): Un-customized.
Richard M. Stallman <rms@gnu.org>
parents:
19475
diff
changeset
|
39 (defvar use-hard-newlines nil |
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
40 "Non-nil means to distinguish hard and soft newlines. |
| 23245 | 41 See also the documentation for the function `use-hard-newlines'.") |
|
16019
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
42 (make-variable-buffer-local 'use-hard-newlines) |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
43 |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
44 (defun use-hard-newlines (&optional arg insert) |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
45 "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
|
46 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
|
47 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
|
48 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
|
49 `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
|
50 |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
51 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
|
52 When the mode is turned on, if there are newlines in the buffer but no hard |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
53 newlines, ask the user whether to mark as hard any newlines preceeding a |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
54 `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
|
55 to do this; it can be `never' to change nothing, t or `always' to force |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
56 marking, `guess' to try to do the right thing with no questions, nil |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
57 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
|
58 |
|
16019
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
59 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
|
60 to paragraphs. The fill functions insert and delete only soft newlines." |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
61 (interactive (list current-prefix-arg nil)) |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
62 (if (or (<= (prefix-numeric-value arg) 0) |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
63 (and use-hard-newlines (null arg))) |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
64 ;; Turn mode off |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
65 (setq use-hard-newlines nil) |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
66 ;; Turn mode on |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
67 ;; Intuit hard newlines -- |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
68 ;; 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
|
69 (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
|
70 (and (not (eq 'never insert)) |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
71 (not use-hard-newlines) |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
72 (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
|
73 (save-excursion |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
74 (goto-char (point-min)) |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
75 (search-forward "\n" nil t)) |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
76 (or (eq insert 'guess) |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
77 (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
|
78 (save-excursion |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
79 (goto-char (point-min)) |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
80 (while (search-forward "\n" nil t) |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
81 (let ((pos (point))) |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
82 (move-to-left-margin) |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
83 (if (looking-at paragraph-start) |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
84 (progn |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
85 (set-hard-newline-properties (1- pos) pos) |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
86 ;; If paragraph-separate, newline after it is hard too. |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
87 (if (looking-at paragraph-separate) |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
88 (progn |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
89 (end-of-line) |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
90 (if (not (eobp)) |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
91 (set-hard-newline-properties |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
92 (point) (1+ (point)))))))))))) |
|
99cc9a8dd157
(use-hard-newlines): New minor mode function.
Richard M. Stallman <rms@gnu.org>
parents:
14378
diff
changeset
|
93 (setq use-hard-newlines t))) |
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
94 |
| 19475 | 95 (defcustom paragraph-start "[ \t\n\f]" "\ |
|
4585
04e78c728252
(paragraph-start): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
2828
diff
changeset
|
96 *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
|
97 This regexp should match lines that separate paragraphs |
|
04e78c728252
(paragraph-start): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
2828
diff
changeset
|
98 and should also match lines that start a paragraph |
|
04e78c728252
(paragraph-start): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
2828
diff
changeset
|
99 \(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
|
100 |
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
101 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
|
102 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
|
103 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
|
104 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
|
105 |
|
4585
04e78c728252
(paragraph-start): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
2828
diff
changeset
|
106 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
|
107 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
|
108 |
|
6bcb93cec6f8
(forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents:
9169
diff
changeset
|
109 If the variable `use-hard-newlines' is nonnil, then only lines following a |
| 19475 | 110 hard newline are considered to match." |
| 111 :group 'paragraphs | |
| 112 :type 'regexp) | |
| 264 | 113 |
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
114 ;; 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
|
115 ;; 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
|
116 ;; 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
|
117 ;; 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
|
118 ;; start a new paragraph). |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
119 |
| 19475 | 120 (defcustom paragraph-separate "[ \t\f]*$" |
| 121 "*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
|
122 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
|
123 |
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
124 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
|
125 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
|
126 ensures that the paragraph functions will work equally within a region of |
| 19475 | 127 text indented by a margin setting." |
| 128 :group 'paragraphs | |
| 129 :type 'regexp) | |
| 264 | 130 |
| 19475 | 131 (defcustom sentence-end (purecopy "[.?!][]\"')}]*\\($\\| $\\|\t\\| \\)[ \t\n]*") |
| 132 "*Regexp describing the end of a sentence. | |
|
2503
fb3509fdf8b7
Sat Apr 10 00:39:29 1993 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
2308
diff
changeset
|
133 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
|
134 |
| 24472 | 135 The default value specifies that in order to be recognized as the end |
| 136 of a sentence, the ending period, question mark, or exclamation point | |
| 137 must be followed by two spaces, unless it's inside some sort of quotes | |
| 138 or parenthesis. | |
| 139 | |
| 140 See also the variable `sentence-end-double-space' and Info node `Sentences'." | |
| 19475 | 141 :group 'paragraphs |
| 142 :type 'regexp) | |
| 264 | 143 |
| 19475 | 144 (defcustom page-delimiter "^\014" |
| 145 "*Regexp describing line-beginnings that separate pages." | |
| 146 :group 'paragraphs | |
| 147 :type 'regexp) | |
| 264 | 148 |
| 19475 | 149 (defcustom paragraph-ignore-fill-prefix nil |
| 150 "*Non-nil means the paragraph commands are not affected by `fill-prefix'. | |
| 151 This is desirable in modes where blank lines are the paragraph delimiters." | |
| 152 :group 'paragraphs | |
| 153 :type 'boolean) | |
| 264 | 154 |
| 36 | 155 (defun forward-paragraph (&optional arg) |
| 156 "Move forward to end of paragraph. | |
|
16757
e1c2e9a44236
(forward-paragraph, backward-paragraph): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
16687
diff
changeset
|
157 With argument ARG, do it ARG times; |
|
e1c2e9a44236
(forward-paragraph, backward-paragraph): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
16687
diff
changeset
|
158 a negative argument ARG = -N means move backward N paragraphs. |
| 36 | 159 |
| 160 A line which `paragraph-start' matches either separates paragraphs | |
| 161 \(if `paragraph-separate' matches it also) or is the first line of a paragraph. | |
| 162 A paragraph end is the beginning of a line which is not part of the paragraph | |
| 163 to which the end of the previous line belongs, or the end of the buffer." | |
| 164 (interactive "p") | |
| 165 (or arg (setq arg 1)) | |
|
26055
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
166 (let* ((opoint (point)) |
|
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
167 (fill-prefix-regexp |
| 36 | 168 (and fill-prefix (not (equal fill-prefix "")) |
| 169 (not paragraph-ignore-fill-prefix) | |
| 170 (regexp-quote fill-prefix))) | |
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
171 ;; 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
|
172 ;; 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
|
173 ;; 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
|
174 ;; work normally with indented text. |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
175 ;; This hack will not find problem cases like "whatever\\|^something". |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
176 (paragraph-start (if (and (not (equal "" paragraph-start)) |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
177 (equal ?^ (aref paragraph-start 0))) |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
178 (substring paragraph-start 1) |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
179 paragraph-start)) |
|
17569
834a1033dc76
(forward-paragraph): Fix editing error
Richard M. Stallman <rms@gnu.org>
parents:
16757
diff
changeset
|
180 (paragraph-separate (if (and (not (equal "" paragraph-separate)) |
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
181 (equal ?^ (aref paragraph-separate 0))) |
|
17569
834a1033dc76
(forward-paragraph): Fix editing error
Richard M. Stallman <rms@gnu.org>
parents:
16757
diff
changeset
|
182 (substring paragraph-separate 1) |
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
183 paragraph-separate)) |
| 36 | 184 (paragraph-separate |
| 185 (if fill-prefix-regexp | |
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
186 (concat paragraph-separate "\\|" |
| 36 | 187 fill-prefix-regexp "[ \t]*$") |
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
188 paragraph-separate)) |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
189 ;; This is used for searching. |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
190 (sp-paragraph-start (concat "^[ \t]*\\(" paragraph-start "\\)")) |
|
22953
fbeacfb09096
(forward-paragraph): Fix the logic for handling beginning of buffer
Richard M. Stallman <rms@gnu.org>
parents:
19527
diff
changeset
|
191 start found-start) |
|
5608
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
192 (while (and (< arg 0) (not (bobp))) |
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
193 (if (and (not (looking-at paragraph-separate)) |
|
10424
6bcb93cec6f8
(forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents:
9169
diff
changeset
|
194 (re-search-backward "^\n" (max (1- (point)) (point-min)) t) |
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
195 (looking-at paragraph-separate)) |
| 36 | 196 nil |
|
12717
8e153c7bbd90
(forward-paragraph): Don't move back over a line
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
197 (setq start (point)) |
|
5608
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
198 ;; Move back over paragraph-separating lines. |
| 36 | 199 (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
|
200 (while (and (not (bobp)) |
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
201 (progn (move-to-left-margin) |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
202 (looking-at paragraph-separate))) |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
203 (forward-line -1)) |
|
5608
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
204 (if (bobp) |
|
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
205 nil |
|
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
206 ;; 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
|
207 (end-of-line) |
|
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
208 ;; 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
|
209 (if (if fill-prefix-regexp |
|
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
210 ;; There is a fill prefix; it overrides paragraph-start. |
|
12717
8e153c7bbd90
(forward-paragraph): Don't move back over a line
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
211 (let (multiple-lines) |
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
212 (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
|
213 (progn (move-to-left-margin) |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
214 (not (looking-at paragraph-separate))) |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
215 (looking-at fill-prefix-regexp)) |
|
12717
8e153c7bbd90
(forward-paragraph): Don't move back over a line
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
216 (if (not (= (point) start)) |
|
8e153c7bbd90
(forward-paragraph): Don't move back over a line
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
217 (setq multiple-lines t)) |
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
218 (forward-line -1)) |
|
12717
8e153c7bbd90
(forward-paragraph): Don't move back over a line
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
219 (move-to-left-margin) |
|
16328
5aff0b539ae0
(forward-paragraph): Don't ever move forward again across a line if we
Richard M. Stallman <rms@gnu.org>
parents:
16022
diff
changeset
|
220 ;;; This deleted code caused a long hanging-indent line |
|
5aff0b539ae0
(forward-paragraph): Don't ever move forward again across a line if we
Richard M. Stallman <rms@gnu.org>
parents:
16022
diff
changeset
|
221 ;;; not to be filled together with the following lines. |
|
5aff0b539ae0
(forward-paragraph): Don't ever move forward again across a line if we
Richard M. Stallman <rms@gnu.org>
parents:
16022
diff
changeset
|
222 ;;; ;; Don't move back over a line before the paragraph |
|
5aff0b539ae0
(forward-paragraph): Don't ever move forward again across a line if we
Richard M. Stallman <rms@gnu.org>
parents:
16022
diff
changeset
|
223 ;;; ;; which doesn't start with fill-prefix |
|
5aff0b539ae0
(forward-paragraph): Don't ever move forward again across a line if we
Richard M. Stallman <rms@gnu.org>
parents:
16022
diff
changeset
|
224 ;;; ;; unless that is the only line we've moved over. |
|
5aff0b539ae0
(forward-paragraph): Don't ever move forward again across a line if we
Richard M. Stallman <rms@gnu.org>
parents:
16022
diff
changeset
|
225 ;;; (and (not (looking-at fill-prefix-regexp)) |
|
5aff0b539ae0
(forward-paragraph): Don't ever move forward again across a line if we
Richard M. Stallman <rms@gnu.org>
parents:
16022
diff
changeset
|
226 ;;; multiple-lines |
|
5aff0b539ae0
(forward-paragraph): Don't ever move forward again across a line if we
Richard M. Stallman <rms@gnu.org>
parents:
16022
diff
changeset
|
227 ;;; (forward-line 1)) |
|
12717
8e153c7bbd90
(forward-paragraph): Don't move back over a line
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
228 (not (bobp))) |
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
229 (while (and (re-search-backward sp-paragraph-start nil 1) |
|
22953
fbeacfb09096
(forward-paragraph): Fix the logic for handling beginning of buffer
Richard M. Stallman <rms@gnu.org>
parents:
19527
diff
changeset
|
230 (setq found-start t) |
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
231 ;; Found a candidate, but need to check if it is a |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
232 ;; REAL paragraph-start. |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
233 (progn (setq start (point)) |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
234 (move-to-left-margin) |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
235 (not (looking-at paragraph-separate))) |
|
22953
fbeacfb09096
(forward-paragraph): Fix the logic for handling beginning of buffer
Richard M. Stallman <rms@gnu.org>
parents:
19527
diff
changeset
|
236 (not (and (looking-at paragraph-start) |
|
fbeacfb09096
(forward-paragraph): Fix the logic for handling beginning of buffer
Richard M. Stallman <rms@gnu.org>
parents:
19527
diff
changeset
|
237 (not |
|
fbeacfb09096
(forward-paragraph): Fix the logic for handling beginning of buffer
Richard M. Stallman <rms@gnu.org>
parents:
19527
diff
changeset
|
238 (and use-hard-newlines |
|
fbeacfb09096
(forward-paragraph): Fix the logic for handling beginning of buffer
Richard M. Stallman <rms@gnu.org>
parents:
19527
diff
changeset
|
239 (not (bobp)) |
|
fbeacfb09096
(forward-paragraph): Fix the logic for handling beginning of buffer
Richard M. Stallman <rms@gnu.org>
parents:
19527
diff
changeset
|
240 (not (get-text-property (1- start) |
|
fbeacfb09096
(forward-paragraph): Fix the logic for handling beginning of buffer
Richard M. Stallman <rms@gnu.org>
parents:
19527
diff
changeset
|
241 'hard))))))) |
|
fbeacfb09096
(forward-paragraph): Fix the logic for handling beginning of buffer
Richard M. Stallman <rms@gnu.org>
parents:
19527
diff
changeset
|
242 (setq found-start nil) |
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
243 (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
|
244 found-start) |
|
5608
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
245 ;; Found one. |
|
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
246 (progn |
|
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
247 ;; Move forward over paragraph separators. |
|
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
248 ;; 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
|
249 ;; 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
|
250 (while (and (not (eobp)) |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
251 (progn (move-to-left-margin) |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
252 (looking-at paragraph-separate))) |
|
5608
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
253 (forward-line 1)) |
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
254 ;; 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
|
255 (end-of-line 0) |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
256 (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
|
257 (forward-char 1) |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
258 (skip-chars-backward " \t") |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
259 (if (not (bolp)) |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
260 (forward-line 1)))) |
|
5608
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
261 ;; No starter or separator line => use buffer beg. |
|
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
262 (goto-char (point-min))))) |
| 36 | 263 (setq arg (1+ arg))) |
|
5608
c4c662362d39
(forward-paragraph): If moving back we find nothing
Richard M. Stallman <rms@gnu.org>
parents:
4585
diff
changeset
|
264 (while (and (> arg 0) (not (eobp))) |
|
14378
2110ae3ef540
(forward-paragraph): Comment change.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
265 ;; Move forward over separator lines, and one more line. |
| 36 | 266 (while (prog1 (and (not (eobp)) |
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
267 (progn (move-to-left-margin) (not (eobp))) |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
268 (looking-at paragraph-separate)) |
|
10424
6bcb93cec6f8
(forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents:
9169
diff
changeset
|
269 (forward-line 1))) |
| 36 | 270 (if fill-prefix-regexp |
| 271 ;; There is a fill prefix; it overrides paragraph-start. | |
| 272 (while (and (not (eobp)) | |
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
273 (progn (move-to-left-margin) (not (eobp))) |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
274 (not (looking-at paragraph-separate)) |
| 36 | 275 (looking-at fill-prefix-regexp)) |
| 276 (forward-line 1)) | |
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
277 (while (and (re-search-forward sp-paragraph-start nil 1) |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
278 (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
|
279 (goto-char start) |
|
12804
1619fcabdb99
(forward-paragraph): Don't overlook a paragraph-start
Richard M. Stallman <rms@gnu.org>
parents:
12717
diff
changeset
|
280 (not (eobp))) |
|
1619fcabdb99
(forward-paragraph): Don't overlook a paragraph-start
Richard M. Stallman <rms@gnu.org>
parents:
12717
diff
changeset
|
281 (progn (move-to-left-margin) |
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
282 (not (looking-at paragraph-separate))) |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
283 (or (not (looking-at paragraph-start)) |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
284 (and use-hard-newlines |
|
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
285 (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
|
286 (forward-char 1)) |
|
6bcb93cec6f8
(forward-paragraph): Notice use-hard-newlines value.
Richard M. Stallman <rms@gnu.org>
parents:
9169
diff
changeset
|
287 (if (< (point) (point-max)) |
|
10864
33769cbeb58e
(paragraph-start, paragraph-separate): Default values no longer start
Boris Goldowsky <boris@gnu.org>
parents:
10464
diff
changeset
|
288 (goto-char start))) |
|
25551
5cd9adabaee5
(backward-kill-sentence): Don't test minibuffer-prompt-end here.
Richard M. Stallman <rms@gnu.org>
parents:
25361
diff
changeset
|
289 (setq arg (1- arg))) |
|
26055
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
290 (constrain-to-field nil opoint t))) |
| 36 | 291 |
| 292 (defun backward-paragraph (&optional arg) | |
| 293 "Move backward to start of paragraph. | |
|
16757
e1c2e9a44236
(forward-paragraph, backward-paragraph): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
16687
diff
changeset
|
294 With argument ARG, do it ARG times; |
|
e1c2e9a44236
(forward-paragraph, backward-paragraph): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
16687
diff
changeset
|
295 a negative argument ARG = -N means move forward N paragraphs. |
| 36 | 296 |
| 237 | 297 A paragraph start is the beginning of a line which is a |
| 298 `first-line-of-paragraph' or which is ordinary text and follows a | |
| 299 paragraph-separating line; except: if the first real line of a | |
| 300 paragraph is preceded by a blank line, the paragraph starts at that | |
| 301 blank line. | |
| 302 | |
| 303 See `forward-paragraph' for more information." | |
| 36 | 304 (interactive "p") |
| 305 (or arg (setq arg 1)) | |
| 306 (forward-paragraph (- arg))) | |
| 307 | |
| 308 (defun mark-paragraph () | |
| 309 "Put point at beginning of this paragraph, mark at end. | |
| 310 The paragraph marked is the one that contains point or follows point." | |
| 311 (interactive) | |
| 312 (forward-paragraph 1) | |
|
2827
0daa9d777306
(mark-paragraph): Activate the mark.
Richard M. Stallman <rms@gnu.org>
parents:
2503
diff
changeset
|
313 (push-mark nil t t) |
| 36 | 314 (backward-paragraph 1)) |
| 315 | |
| 316 (defun kill-paragraph (arg) | |
| 317 "Kill forward to end of paragraph. | |
| 318 With arg N, kill forward to Nth end of paragraph; | |
| 319 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
|
320 (interactive "p") |
|
7064
19a84bb30e9e
(kill-paragraph): Don't use save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
5653
diff
changeset
|
321 (kill-region (point) (progn (forward-paragraph arg) (point)))) |
| 36 | 322 |
| 323 (defun backward-kill-paragraph (arg) | |
| 324 "Kill back to start of paragraph. | |
| 325 With arg N, kill back to Nth start of paragraph; | |
| 326 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
|
327 (interactive "p") |
|
26055
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
328 (kill-region (point) (progn (backward-paragraph arg) (point)))) |
| 36 | 329 |
| 330 (defun transpose-paragraphs (arg) | |
| 331 "Interchange this (or next) paragraph with previous one." | |
| 332 (interactive "*p") | |
| 333 (transpose-subr 'forward-paragraph arg)) | |
| 334 | |
| 335 (defun start-of-paragraph-text () | |
| 336 (let ((opoint (point)) npoint) | |
| 337 (forward-paragraph -1) | |
| 338 (setq npoint (point)) | |
| 339 (skip-chars-forward " \t\n") | |
| 68 | 340 ;; If the range of blank lines found spans the original start point, |
| 341 ;; try again from the beginning of it. | |
| 342 ;; Must be careful to avoid infinite loop | |
| 343 ;; when following a single return at start of buffer. | |
| 344 (if (and (>= (point) opoint) (< npoint opoint)) | |
| 36 | 345 (progn |
| 346 (goto-char npoint) | |
| 347 (if (> npoint (point-min)) | |
| 348 (start-of-paragraph-text)))))) | |
| 349 | |
| 350 (defun end-of-paragraph-text () | |
| 351 (let ((opoint (point))) | |
| 352 (forward-paragraph 1) | |
| 353 (if (eq (preceding-char) ?\n) (forward-char -1)) | |
| 354 (if (<= (point) opoint) | |
| 355 (progn | |
| 356 (forward-char 1) | |
| 357 (if (< (point) (point-max)) | |
| 358 (end-of-paragraph-text)))))) | |
| 359 | |
| 360 (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
|
361 "Move forward to next `sentence-end'. With argument, repeat. |
| 237 | 362 With negative argument, move backward repeatedly to `sentence-beginning'. |
| 36 | 363 |
| 237 | 364 The variable `sentence-end' is a regular expression that matches ends of |
| 365 sentences. Also, every paragraph boundary terminates sentences as well." | |
| 36 | 366 (interactive "p") |
| 367 (or arg (setq arg 1)) | |
|
26055
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
368 (let ((opoint (point))) |
|
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
369 (while (< arg 0) |
|
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
370 (let ((par-beg (save-excursion (start-of-paragraph-text) (point)))) |
|
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
371 (if (re-search-backward (concat sentence-end "[^ \t\n]") par-beg t) |
|
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
372 (goto-char (1- (match-end 0))) |
|
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
373 (goto-char par-beg))) |
|
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
374 (setq arg (1+ arg))) |
|
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
375 (while (> arg 0) |
|
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
376 (let ((par-end (save-excursion (end-of-paragraph-text) (point)))) |
|
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
377 (if (re-search-forward sentence-end par-end t) |
|
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
378 (skip-chars-backward " \t\n") |
|
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
379 (goto-char par-end))) |
|
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
380 (setq arg (1- arg))) |
|
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
381 (constrain-to-field nil opoint t))) |
| 36 | 382 |
| 383 (defun backward-sentence (&optional arg) | |
| 384 "Move backward to start of sentence. With arg, do it arg times. | |
| 237 | 385 See `forward-sentence' for more information." |
| 36 | 386 (interactive "p") |
| 387 (or arg (setq arg 1)) | |
| 388 (forward-sentence (- arg))) | |
| 389 | |
| 390 (defun kill-sentence (&optional arg) | |
| 391 "Kill from point to end of sentence. | |
| 392 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
|
393 (interactive "p") |
|
7064
19a84bb30e9e
(kill-paragraph): Don't use save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
5653
diff
changeset
|
394 (kill-region (point) (progn (forward-sentence arg) (point)))) |
| 36 | 395 |
| 396 (defun backward-kill-sentence (&optional arg) | |
| 397 "Kill back from point to start of sentence. | |
| 398 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
|
399 (interactive "p") |
|
26055
cf5dd9e8bf79
(forward-sentence, forward-paragraph):
Gerd Moellmann <gerd@gnu.org>
parents:
25551
diff
changeset
|
400 (kill-region (point) (progn (backward-sentence arg) (point)))) |
| 36 | 401 |
| 402 (defun mark-end-of-sentence (arg) | |
| 237 | 403 "Put mark at end of sentence. Arg works as in `forward-sentence'." |
| 36 | 404 (interactive "p") |
| 405 (push-mark | |
| 406 (save-excursion | |
| 407 (forward-sentence arg) | |
|
2828
abc6df78588f
(mark-end-of-sentence): Activate the mark.
Richard M. Stallman <rms@gnu.org>
parents:
2827
diff
changeset
|
408 (point)) |
|
abc6df78588f
(mark-end-of-sentence): Activate the mark.
Richard M. Stallman <rms@gnu.org>
parents:
2827
diff
changeset
|
409 nil t)) |
| 36 | 410 |
| 411 (defun transpose-sentences (arg) | |
| 412 "Interchange this (next) and previous sentence." | |
| 413 (interactive "*p") | |
| 414 (transpose-subr 'forward-sentence arg)) | |
|
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
269
diff
changeset
|
415 |
|
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
269
diff
changeset
|
416 ;;; paragraphs.el ends here |
