annotate lisp/textmodes/paragraphs.el @ 3492:3e75726d76c7

(x_get_foreign_selection): Handle x_selection_timeout as milliseconds, not as seconds. (syms_of_xselect): Doc fix to match.
author Richard M. Stallman <rms@gnu.org>
date Sat, 05 Jun 1993 08:37:45 +0000
parents abc6df78588f
children 04e78c728252
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
845
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
3 ;; Copyright (C) 1985, 86, 87, 1991 Free Software Foundation, Inc.
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
4
789
71d052f72ac1 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 732
diff changeset
5 ;; Maintainer: FSF
814
38b2499cb3e9 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 804
diff changeset
6 ;; Keywords: wp
789
71d052f72ac1 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 732
diff changeset
7
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
9
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
804
33aaf4b71a1d *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 789
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
13 ;; any later version.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
14
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
19
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
23
2308
f287613dfc28 Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1462
diff changeset
24 ;;; Commentary:
f287613dfc28 Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1462
diff changeset
25
f287613dfc28 Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1462
diff changeset
26 ;; This package provides the paragraph-oriented commands documented in the
f287613dfc28 Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1462
diff changeset
27 ;; Emacs manual.
f287613dfc28 Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1462
diff changeset
28
789
71d052f72ac1 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 732
diff changeset
29 ;;; Code:
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
30
269
2ca8cdb96a9f *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 264
diff changeset
31 (defconst paragraph-start "^[ \t\n\f]" "\
2ca8cdb96a9f *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 264
diff changeset
32 *Regexp for beginning of a line that starts OR separates paragraphs.")
264
7db4ff4204a5 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 237
diff changeset
33
269
2ca8cdb96a9f *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 264
diff changeset
34 (defconst paragraph-separate "^[ \t\f]*$" "\
2ca8cdb96a9f *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 264
diff changeset
35 *Regexp for beginning of a line that separates paragraphs.
2ca8cdb96a9f *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 264
diff changeset
36 If you change this, you may have to change paragraph-start also.")
264
7db4ff4204a5 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 237
diff changeset
37
269
2ca8cdb96a9f *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 264
diff changeset
38 (defconst sentence-end (purecopy "[.?!][]\"')}]*\\($\\| $\\|\t\\| \\)[ \t\n]*") "\
2ca8cdb96a9f *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 264
diff changeset
39 *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
40 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
41
fb3509fdf8b7 Sat Apr 10 00:39:29 1993 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents: 2308
diff changeset
42 In order to be recognized as the end of a sentence, the ending period,
fb3509fdf8b7 Sat Apr 10 00:39:29 1993 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents: 2308
diff changeset
43 question mark, or exclamation point must be followed by two spaces,
fb3509fdf8b7 Sat Apr 10 00:39:29 1993 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents: 2308
diff changeset
44 unless it's inside some sort of quotes or parenthesis.")
264
7db4ff4204a5 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 237
diff changeset
45
269
2ca8cdb96a9f *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 264
diff changeset
46 (defconst page-delimiter "^\014" "\
2ca8cdb96a9f *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 264
diff changeset
47 *Regexp describing line-beginnings that separate pages.")
264
7db4ff4204a5 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 237
diff changeset
48
269
2ca8cdb96a9f *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 264
diff changeset
49 (defvar paragraph-ignore-fill-prefix nil "\
2ca8cdb96a9f *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 264
diff changeset
50 Non-nil means the paragraph commands are not affected by `fill-prefix'.
2ca8cdb96a9f *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 264
diff changeset
51 This is desirable in modes where blank lines are the paragraph delimiters.")
264
7db4ff4204a5 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 237
diff changeset
52
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
53
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
54 (defun forward-paragraph (&optional arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
55 "Move forward to end of paragraph.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
56 With arg N, do it N times; negative arg -N means move forward N paragraphs.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
57
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
58 A line which `paragraph-start' matches either separates paragraphs
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
59 \(if `paragraph-separate' matches it also) or is the first line of a paragraph.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
60 A paragraph end is the beginning of a line which is not part of the paragraph
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
61 to which the end of the previous line belongs, or the end of the buffer."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
62 (interactive "p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
63 (or arg (setq arg 1))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
64 (let* ((fill-prefix-regexp
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
65 (and fill-prefix (not (equal fill-prefix ""))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
66 (not paragraph-ignore-fill-prefix)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
67 (regexp-quote fill-prefix)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
68 (paragraph-separate
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
69 (if fill-prefix-regexp
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
70 (concat paragraph-separate "\\|^"
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
71 fill-prefix-regexp "[ \t]*$")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
72 paragraph-separate)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
73 (while (< arg 0)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
74 (if (and (not (looking-at paragraph-separate))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
75 (re-search-backward "^\n" (max (1- (point)) (point-min)) t))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
76 nil
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
77 (forward-char -1) (beginning-of-line)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
78 (while (and (not (bobp)) (looking-at paragraph-separate))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
79 (forward-line -1))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
80 (end-of-line)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
81 ;; Search back for line that starts or separates paragraphs.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
82 (if (if fill-prefix-regexp
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
83 ;; There is a fill prefix; it overrides paragraph-start.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
84 (progn
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
85 (while (progn (beginning-of-line)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
86 (and (not (bobp))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
87 (not (looking-at paragraph-separate))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
88 (looking-at fill-prefix-regexp)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
89 (forward-line -1))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
90 (not (bobp)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
91 (re-search-backward paragraph-start nil t))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
92 ;; Found one.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
93 (progn
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
94 (while (and (not (eobp)) (looking-at paragraph-separate))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
95 (forward-line 1))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
96 (if (eq (char-after (- (point) 2)) ?\n)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
97 (forward-line -1)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
98 ;; No starter or separator line => use buffer beg.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
99 (goto-char (point-min))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
100 (setq arg (1+ arg)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
101 (while (> arg 0)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
102 (beginning-of-line)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
103 (while (prog1 (and (not (eobp))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
104 (looking-at paragraph-separate))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
105 (forward-line 1)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
106 (if fill-prefix-regexp
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
107 ;; There is a fill prefix; it overrides paragraph-start.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
108 (while (and (not (eobp))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
109 (not (looking-at paragraph-separate))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
110 (looking-at fill-prefix-regexp))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
111 (forward-line 1))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
112 (if (re-search-forward paragraph-start nil t)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
113 (goto-char (match-beginning 0))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
114 (goto-char (point-max))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
115 (setq arg (1- arg)))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
116
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
117 (defun backward-paragraph (&optional arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
118 "Move backward to start of paragraph.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
119 With arg N, do it N times; negative arg -N means move forward N paragraphs.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
120
237
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
121 A paragraph start is the beginning of a line which is a
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
122 `first-line-of-paragraph' or which is ordinary text and follows a
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
123 paragraph-separating line; except: if the first real line of a
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
124 paragraph is preceded by a blank line, the paragraph starts at that
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
125 blank line.
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
126
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
127 See `forward-paragraph' for more information."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
128 (interactive "p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
129 (or arg (setq arg 1))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
130 (forward-paragraph (- arg)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
131
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
132 (defun mark-paragraph ()
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
133 "Put point at beginning of this paragraph, mark at end.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
134 The paragraph marked is the one that contains point or follows point."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
135 (interactive)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
136 (forward-paragraph 1)
2827
0daa9d777306 (mark-paragraph): Activate the mark.
Richard M. Stallman <rms@gnu.org>
parents: 2503
diff changeset
137 (push-mark nil t t)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
138 (backward-paragraph 1))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
139
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
140 (defun kill-paragraph (arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
141 "Kill forward to end of paragraph.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
142 With arg N, kill forward to Nth end of paragraph;
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
143 negative arg -N means kill backward to Nth start of paragraph."
237
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
144 (interactive "p")
1435
4fef92b213f6 (kill-sentence, backward-kill-sentence):
Richard M. Stallman <rms@gnu.org>
parents: 845
diff changeset
145 (kill-region (point) (save-excursion (forward-paragraph arg) (point))))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
146
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
147 (defun backward-kill-paragraph (arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
148 "Kill back to start of paragraph.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
149 With arg N, kill back to Nth start of paragraph;
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
150 negative arg -N means kill forward to Nth end of paragraph."
237
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
151 (interactive "p")
1435
4fef92b213f6 (kill-sentence, backward-kill-sentence):
Richard M. Stallman <rms@gnu.org>
parents: 845
diff changeset
152 (kill-region (point) (save-excursion (backward-paragraph arg) (point))))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
153
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
154 (defun transpose-paragraphs (arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
155 "Interchange this (or next) paragraph with previous one."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
156 (interactive "*p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
157 (transpose-subr 'forward-paragraph arg))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
158
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
159 (defun start-of-paragraph-text ()
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
160 (let ((opoint (point)) npoint)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
161 (forward-paragraph -1)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
162 (setq npoint (point))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
163 (skip-chars-forward " \t\n")
68
7680293d57f3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
164 ;; If the range of blank lines found spans the original start point,
7680293d57f3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
165 ;; try again from the beginning of it.
7680293d57f3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
166 ;; Must be careful to avoid infinite loop
7680293d57f3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
167 ;; when following a single return at start of buffer.
7680293d57f3 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
168 (if (and (>= (point) opoint) (< npoint opoint))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
169 (progn
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
170 (goto-char npoint)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
171 (if (> npoint (point-min))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
172 (start-of-paragraph-text))))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
173
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
174 (defun end-of-paragraph-text ()
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
175 (let ((opoint (point)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
176 (forward-paragraph 1)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
177 (if (eq (preceding-char) ?\n) (forward-char -1))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
178 (if (<= (point) opoint)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
179 (progn
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
180 (forward-char 1)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
181 (if (< (point) (point-max))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
182 (end-of-paragraph-text))))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
183
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
184 (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
185 "Move forward to next `sentence-end'. With argument, repeat.
237
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
186 With negative argument, move backward repeatedly to `sentence-beginning'.
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
187
237
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
188 The variable `sentence-end' is a regular expression that matches ends of
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
189 sentences. Also, every paragraph boundary terminates sentences as well."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
190 (interactive "p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
191 (or arg (setq arg 1))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
192 (while (< arg 0)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
193 (let ((par-beg (save-excursion (start-of-paragraph-text) (point))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
194 (if (re-search-backward (concat sentence-end "[^ \t\n]") par-beg t)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
195 (goto-char (1- (match-end 0)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
196 (goto-char par-beg)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
197 (setq arg (1+ arg)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
198 (while (> arg 0)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
199 (let ((par-end (save-excursion (end-of-paragraph-text) (point))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
200 (if (re-search-forward sentence-end par-end t)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
201 (skip-chars-backward " \t\n")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
202 (goto-char par-end)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
203 (setq arg (1- arg))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
204
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
205 (defun backward-sentence (&optional arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
206 "Move backward to start of sentence. With arg, do it arg times.
237
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
207 See `forward-sentence' for more information."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
208 (interactive "p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
209 (or arg (setq arg 1))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
210 (forward-sentence (- arg)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
211
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
212 (defun kill-sentence (&optional arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
213 "Kill from point to end of sentence.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
214 With arg, repeat; negative arg -N means kill back to Nth start of sentence."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
215 (interactive "*p")
1435
4fef92b213f6 (kill-sentence, backward-kill-sentence):
Richard M. Stallman <rms@gnu.org>
parents: 845
diff changeset
216 (kill-region (point) (save-excursion (forward-sentence arg) (point))))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
217
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
218 (defun backward-kill-sentence (&optional arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
219 "Kill back from point to start of sentence.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
220 With arg, repeat, or kill forward to Nth end of sentence if negative arg -N."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
221 (interactive "*p")
1462
876e54ad6936 (backward-kill-sentence): Fix typo in last change.
Richard M. Stallman <rms@gnu.org>
parents: 1435
diff changeset
222 (kill-region (point) (save-excursion (backward-sentence arg) (point))))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
223
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
224 (defun mark-end-of-sentence (arg)
237
75cec14894db *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 68
diff changeset
225 "Put mark at end of sentence. Arg works as in `forward-sentence'."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
226 (interactive "p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
227 (push-mark
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
228 (save-excursion
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
229 (forward-sentence arg)
2828
abc6df78588f (mark-end-of-sentence): Activate the mark.
Richard M. Stallman <rms@gnu.org>
parents: 2827
diff changeset
230 (point))
abc6df78588f (mark-end-of-sentence): Activate the mark.
Richard M. Stallman <rms@gnu.org>
parents: 2827
diff changeset
231 nil t))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
232
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
233 (defun transpose-sentences (arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
234 "Interchange this (next) and previous sentence."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
235 (interactive "*p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
236 (transpose-subr 'forward-sentence arg))
659
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 269
diff changeset
237
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 269
diff changeset
238 ;;; paragraphs.el ends here