annotate lisp/paragraphs.el @ 5553:62edcc6a11ec

Add an assertion about argument order to #'apply-partially compiler macro lisp/ChangeLog addition: 2011-08-24 Aidan Kehoe <kehoea@parhasard.net> * cl-macs.el (apply-partially): Add an assertion to this compiler macro, requiring that the order of the placeholders corresponding to the arguments in the constants vector of the constructed compiled function be the same as the order of the arguments to #'apply-partially. tests/ChangeLog addition: 2011-08-24 Aidan Kehoe <kehoea@parhasard.net> * automated/lisp-tests.el: Add a test of apply partially that depends on the relative order of its arguments.
author Aidan Kehoe <kehoea@parhasard.net>
date Wed, 24 Aug 2011 11:06:41 +0100
parents 1f0b15040456
children 00a421d2b2ba
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
1 ;;; paragraphs.el --- paragraph and sentence parsing
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
3 ;; Copyright (C) 1985-87, 1991, 1994-97, 1999-2010 Free Software Foundation, Inc.
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
4 ;; Copyright (C) 2010 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 ;; Maintainer: FSF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 ;; Keywords: wp, dumped
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
5495
Aidan Kehoe <kehoea@parhasard.net>
parents: 5493 5474
diff changeset
11 ;; XEmacs is free software: you can redistribute it and/or modify
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
14 ;; (at your option) any later version.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 ;; General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5229
diff changeset
22 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
24 ;;; Synced up with: FSF 23.1.92.
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
25 ;;; Synced by: Ben Wing, 2-17-10.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 ;; This file is dumped with XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 ;; This package provides the paragraph-oriented commands documented in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 ;; XEmacs Reference Manual.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 ;; 06/11/1997 - Use char-(after|before) instead of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 ;; (following|preceding)-char. -slb
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 ;;; Code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
39 (defgroup paragraphs nil
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
40 "Paragraph and sentence parsing."
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
41 :group 'editing)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
43 (put 'use-hard-newlines 'permanent-local t)
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
44 (define-minor-mode use-hard-newlines
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 "Minor mode to distinguish hard and soft newlines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 When active, the functions `newline' and `open-line' add the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 text-property `hard' to newlines that they insert, and a line is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 only considered as a candidate to match `paragraph-start' or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 `paragraph-separate' if it follows a hard newline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 Prefix argument says to turn mode on if positive, off if negative.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 When the mode is turned on, if there are newlines in the buffer but no hard
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
53 newlines, ask the user whether to mark as hard any newlines preceeding a
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 `paragraph-start' line. From a program, second arg INSERT specifies whether
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 to do this; it can be `never' to change nothing, t or `always' to force
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
56 marking, `guess' to try to do the right thing with no questions, nil
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 or anything else to ask the user.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 Newlines not marked hard are called \"soft\", and are always internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 to paragraphs. The fill functions insert and delete only soft newlines."
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
61 :group 'paragraphs
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
62 :extra-args (insert)
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
63 (when use-hard-newlines
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 ;; Turn mode on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 ;; Intuit hard newlines --
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 ;; mark as hard any newlines preceding a paragraph-start line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 (if (or (eq insert t) (eq insert 'always)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 (and (not (eq 'never insert))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 (not (text-property-any (point-min) (point-max) 'hard t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 (search-forward "\n" nil t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 (or (eq insert 'guess)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 (y-or-n-p "Make newlines between paragraphs hard? "))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 (while (search-forward "\n" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 (let ((pos (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 (move-to-left-margin)
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
80 (when (looking-at paragraph-start)
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
81 (set-hard-newline-properties (1- pos) pos))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
82 ;; If paragraph-separate, newline after it is hard too.
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
83 (when (looking-at paragraph-separate)
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
84 (set-hard-newline-properties (1- pos) pos)
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
85 (end-of-line)
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
86 (unless (eobp)
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
87 (set-hard-newline-properties (point) (1+ (point)))))))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
89 (defcustom paragraph-start "\f\\|[ \t]*$" "\
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 *Regexp for beginning of a line that starts OR separates paragraphs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 This regexp should match lines that separate paragraphs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 and should also match lines that start a paragraph
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 \(and are part of that paragraph).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 This is matched against the text at the left margin, which is not necessarily
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 the beginning of the line, so it should never use \"^\" as an anchor. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 ensures that the paragraph functions will work equally well within a region
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 of text indented by a margin setting.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 The variable `paragraph-separate' specifies how to distinguish
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 lines that start paragraphs from lines that separate them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 If the variable `use-hard-newlines' is non-nil, then only lines following a
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
104 hard newline are considered to match."
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
105 :group 'paragraphs
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
106 :type 'regexp)
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
107 (put 'paragraph-start 'safe-local-variable 'stringp)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 ;; paragraph-start requires a hard newline, but paragraph-separate does not:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 ;; It is assumed that paragraph-separate is distinctive enough to be believed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 ;; whenever it occurs, while it is reasonable to set paragraph-start to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 ;; something very minimal, even including "." (which makes every hard newline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 ;; start a new paragraph).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
115 (defcustom paragraph-separate "[ \t\f]*$"
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
116 "*Regexp for beginning of a line that separates paragraphs.
450
98528da0b7fc Import from CVS: tag r21-2-40
cvs
parents: 446
diff changeset
117 If you change this, you may have to change `paragraph-start' also.
98528da0b7fc Import from CVS: tag r21-2-40
cvs
parents: 446
diff changeset
118
98528da0b7fc Import from CVS: tag r21-2-40
cvs
parents: 446
diff changeset
119 A line matching this is not part of any paragraph.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 This is matched against the text at the left margin, which is not necessarily
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 the beginning of the line, so it should not use \"^\" as an anchor. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 ensures that the paragraph functions will work equally within a region of
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
124 text indented by a margin setting."
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
125 :group 'paragraphs
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
126 :type 'regexp)
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
127 (put 'paragraph-separate 'safe-local-variable 'stringp)
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
128
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
129 (defcustom sentence-end-double-space t
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
130 "*Non-nil means a single space does not end a sentence.
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
131 This is relevant for filling. See also `sentence-end-without-period'
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
132 and `colon-double-space'.
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
133
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
134 This variable applies only to filling, not motion commands. To
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
135 change the behavior of motion commands, see `sentence-end'.
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
136
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
137 This value is used by the function `sentence-end' to construct the
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
138 regexp describing the end of a sentence, when the value of the variable
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
139 `sentence-end' is nil. See Info node `(lispref)Standard Regexps'."
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
140 :type 'boolean
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
141 :group 'fill)
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
142 (put 'sentence-end-double-space 'safe-local-variable 'booleanp)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
144 (defcustom sentence-end-without-period nil
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
145 "*Non-nil means a sentence will end without a period.
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
146 For example, a sentence in Thai text ends with double space but
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
147 without a period.
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
148
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
149 This value is used by the function `sentence-end' to construct the
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
150 regexp describing the end of a sentence, when the value of the variable
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
151 `sentence-end' is nil. See Info node `(lispref)Standard Regexps'."
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
152 :type 'boolean
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
153 :group 'fill)
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
154 (put 'sentence-end-without-period 'safe-local-variable 'booleanp)
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
155
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
156 (defcustom sentence-end-without-space
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
157 (cond ((featurep 'unicode-internal)
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
158 (decode-coding-string "\343\200\202\357\274\216\357\274\237\357\274\201" 'utf-8))
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
159 ((featurep 'mule)
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
160 (decode-coding-string "\033$B!#!%!)!*\033$A!##.#?#!\033$(0!$!%!)!*\033$(G!$!%!)!*\033(B" 'iso-2022-7bit))
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
161 (t ""))
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
162 "String of characters that end sentence without following spaces.
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
163
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
164 This value is used by the function `sentence-end' to construct the
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
165 regexp describing the end of a sentence, when the value of the variable
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
166 `sentence-end' is nil. See Info node `(lispref)Standard Regexps'."
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
167 :group 'paragraphs
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
168 :type 'string)
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
169 (put 'sentence-end-without-space 'safe-local-variable 'stringp)
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
170
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
171 (defcustom sentence-end nil
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
172 "Regexp describing the end of a sentence.
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
173 The value includes the whitespace following the sentence.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 All paragraph boundaries also end sentences, regardless.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
176 The value nil means to use the default value defined by the
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
177 function `sentence-end'. You should always use this function
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
178 to obtain the value of this variable."
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
179 :group 'paragraphs
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
180 :type '(choice regexp (const :tag "Use default value" nil)))
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
181 (put 'sentence-end 'safe-local-variable 'string-or-null-p)
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
182
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
183 (defcustom sentence-end-base "[.?!][]\"'”)}]*"
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
184 "Regexp matching the basic end of a sentence, not including following space."
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
185 :group 'paragraphs
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
186 :type 'string
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
187 :version "22.1")
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
188 (put 'sentence-end-base 'safe-local-variable 'stringp)
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
189
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
190 (defun sentence-end ()
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
191 "Return the regexp describing the end of a sentence.
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
192
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
193 This function returns either the value of the variable `sentence-end'
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
194 if it is non-nil, or the default value constructed from the
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
195 variables `sentence-end-base', `sentence-end-double-space',
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
196 `sentence-end-without-period' and `sentence-end-without-space'.
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
197
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
198 The default value specifies that in order to be recognized as the
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
199 end of a sentence, the ending period, question mark, or exclamation point
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
200 must be followed by two spaces, with perhaps some closing delimiters
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
201 in between. See Info node `(elisp)Standard Regexps'."
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
202 (or sentence-end
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
203 ;; We accept non-break space along with space.
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
204 (concat (if sentence-end-without-period "\\w[ \u00a0][ \u00a0]\\|")
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
205 "\\("
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
206 sentence-end-base
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
207 (if sentence-end-double-space
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
208 "\\($\\|[ \u00a0]$\\|\t\\|[ \u00a0][ \u00a0]\\)" "\\($\\|[\t \u00a0]\\)")
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
209 "\\|[" sentence-end-without-space "]+"
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
210 "\\)"
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
211 "[ \u00a0\t\n]*")))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
213 (defcustom page-delimiter "^\014"
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
214 "*Regexp describing line-beginnings that separate pages."
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
215 :group 'paragraphs
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
216 :type 'regexp)
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
217 (put 'page-delimiter 'safe-local-variable 'stringp)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
219 (defcustom paragraph-ignore-fill-prefix nil
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
220 "*Non-nil means the paragraph commands are not affected by `fill-prefix'.
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
221 This is desirable in modes where blank lines are the paragraph delimiters."
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
222 :group 'paragraphs
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
223 :type 'boolean)
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
224 (put 'paragraph-ignore-fill-prefix 'safe-local-variable 'booleanp)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 (defun forward-paragraph (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 "Move forward to end of paragraph.
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
228 With argument ARG, do it ARG times;
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
229 a negative argument ARG = -N means move backward N paragraphs.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 A line which `paragraph-start' matches either separates paragraphs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 \(if `paragraph-separate' matches it also) or is the first line of a paragraph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 A paragraph end is the beginning of a line which is not part of the paragraph
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
234 to which the end of the previous line belongs, or the end of the buffer.
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
235 Returns the count of paragraphs left to move."
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
236 ;; #### MERGE! FSF Has (interactive "^p")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 (interactive "_p") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 (or arg (setq arg 1))
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
239 (let* ((opoint (point))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
240 (fill-prefix-regexp
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 (and fill-prefix (not (equal fill-prefix ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 (not paragraph-ignore-fill-prefix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 (regexp-quote fill-prefix)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 ;; Remove ^ from paragraph-start and paragraph-sep if they are there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 ;; These regexps shouldn't be anchored, because we look for them
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 ;; starting at the left-margin. This allows paragraph commands to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 ;; work normally with indented text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 ;; This hack will not find problem cases like "whatever\\|^something".
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
249 (parstart (if (and (not (equal "" paragraph-start))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
250 (equal ?^ (aref paragraph-start 0)))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
251 (substring paragraph-start 1)
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
252 paragraph-start))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
253 (parsep (if (and (not (equal "" paragraph-separate))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
254 (equal ?^ (aref paragraph-separate 0)))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
255 (substring paragraph-separate 1)
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
256 paragraph-separate))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
257 (parsep
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 (if fill-prefix-regexp
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
259 (concat parsep "\\|"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 fill-prefix-regexp "[ \t]*$")
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
261 parsep))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 ;; This is used for searching.
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
263 (sp-parstart (concat "^[ \t]*\\(?:" parstart "\\|" parsep "\\)"))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
264 start found-start)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 (while (and (< arg 0) (not (bobp)))
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
266 (if (and (not (looking-at parsep))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 (re-search-backward "^\n" (max (1- (point)) (point-min)) t)
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
268 (looking-at parsep))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
269 (setq arg (1+ arg))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 (setq start (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 ;; Move back over paragraph-separating lines.
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
272 (backward-char 1) (beginning-of-line)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 (while (and (not (bobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 (progn (move-to-left-margin)
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
275 (looking-at parsep)))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
276 (forward-line -1))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 (if (bobp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 nil
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
279 (setq arg (1+ arg))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 ;; Go to end of the previous (non-separating) line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 (end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 ;; Search back for line that starts or separates paragraphs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 (if (if fill-prefix-regexp
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
284 ;; There is a fill prefix; it overrides parstart.
4103
b4f4e0cc90f1 [xemacs-hg @ 2007-08-07 23:08:47 by aidan]
aidan
parents: 2578
diff changeset
285 (let nil ; (multiple-lines)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 (while (and (progn (beginning-of-line) (not (bobp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 (progn (move-to-left-margin)
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
288 (not (looking-at parsep)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 (looking-at fill-prefix-regexp))
4103
b4f4e0cc90f1 [xemacs-hg @ 2007-08-07 23:08:47 by aidan]
aidan
parents: 2578
diff changeset
290 ; (unless (= (point) start)
b4f4e0cc90f1 [xemacs-hg @ 2007-08-07 23:08:47 by aidan]
aidan
parents: 2578
diff changeset
291 ; (setq multiple-lines t))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 (forward-line -1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 (move-to-left-margin)
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
294 ;; This deleted code caused a long hanging-indent line
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
295 ;; not to be filled together with the following lines.
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
296 ;; ;; Don't move back over a line before the paragraph
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
297 ;; ;; which doesn't start with fill-prefix
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
298 ;; ;; unless that is the only line we've moved over.
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
299 ;; (and (not (looking-at fill-prefix-regexp))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
300 ;; multiple-lines
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
301 ;; (forward-line 1))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 (not (bobp)))
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
303 (while (and (re-search-backward sp-parstart nil 1)
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
304 (setq found-start t)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 ;; Found a candidate, but need to check if it is a
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
306 ;; REAL parstart.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 (progn (setq start (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 (move-to-left-margin)
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
309 (not (looking-at parsep)))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
310 (not (and (looking-at parstart)
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
311 (or (not use-hard-newlines)
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
312 ;; #### XEmacs: We've reversed
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
313 ;; the order of the following two --
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
314 ;; does it matter?
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
315 (get-text-property (1- start) 'hard)
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
316 (bobp)))))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
317 (setq found-start nil)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 (goto-char start))
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
319 found-start)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 ;; Found one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 ;; Move forward over paragraph separators.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 ;; We know this cannot reach the place we started
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 ;; because we know we moved back over a non-separator.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 (while (and (not (eobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 (progn (move-to-left-margin)
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
327 (looking-at parsep)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 (forward-line 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 ;; If line before paragraph is just margin, back up to there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 (end-of-line 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 (if (> (current-column) (current-left-margin))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 (forward-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 (skip-chars-backward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 (if (not (bolp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 (forward-line 1))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 ;; No starter or separator line => use buffer beg.
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
337 (goto-char (point-min))))))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
338
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 (while (and (> arg 0) (not (eobp)))
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
340 ;; Move forward over separator lines...
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
341 (while (and (not (eobp))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
342 (progn (move-to-left-margin) (not (eobp)))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
343 (looking-at parsep))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
344 (forward-line 1))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
345 (unless (eobp) (setq arg (1- arg)))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
346 ;; ... and one more line.
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
347 (forward-line 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 (if fill-prefix-regexp
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
349 ;; There is a fill prefix; it overrides parstart.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 (while (and (not (eobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 (progn (move-to-left-margin) (not (eobp)))
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
352 (not (looking-at parsep))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 (looking-at fill-prefix-regexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 (forward-line 1))
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
355 (while (and (re-search-forward sp-parstart nil 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 (progn (setq start (match-beginning 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 (goto-char start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 (not (eobp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 (progn (move-to-left-margin)
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
360 (not (looking-at parsep)))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
361 (or (not (looking-at parstart))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 (and use-hard-newlines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 (not (get-text-property (1- start) 'hard)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 (forward-char 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 (if (< (point) (point-max))
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
366 (goto-char start))))
5368
ed74d2ca7082 Use ', not #', when a given symbol may not have a function binding at read time
Aidan Kehoe <kehoea@parhasard.net>
parents: 5229
diff changeset
367 (if-fboundp 'constrain-to-field
4103
b4f4e0cc90f1 [xemacs-hg @ 2007-08-07 23:08:47 by aidan]
aidan
parents: 2578
diff changeset
368 (constrain-to-field nil opoint t)
b4f4e0cc90f1 [xemacs-hg @ 2007-08-07 23:08:47 by aidan]
aidan
parents: 2578
diff changeset
369 (error
b4f4e0cc90f1 [xemacs-hg @ 2007-08-07 23:08:47 by aidan]
aidan
parents: 2578
diff changeset
370 'void-function
b4f4e0cc90f1 [xemacs-hg @ 2007-08-07 23:08:47 by aidan]
aidan
parents: 2578
diff changeset
371 "constrain-to-field not available; is xemacs-base installed?"))
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
372 ;; Return the number of steps that could not be done.
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
373 arg))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 (defun backward-paragraph (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 "Move backward to start of paragraph.
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
377 With argument ARG, do it ARG times;
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
378 a negative argument ARG = -N means move forward N paragraphs.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 A paragraph start is the beginning of a line which is a
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
381 `paragraph-start' or which is ordinary text and follows a
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
382 `paragraph-separate'ing line; except: if the first real line of a
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 paragraph is preceded by a blank line, the paragraph starts at that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 blank line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 See `forward-paragraph' for more information."
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
387 ;; #### MERGE! FSF Has (interactive "^p")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 (interactive "_p") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 (or arg (setq arg 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 (forward-paragraph (- arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
392 (defun mark-paragraph (&optional arg allow-extend)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 "Put point at beginning of this paragraph, mark at end.
687
d8c768dcca7a [xemacs-hg @ 2001-12-05 04:09:24 by youngs]
youngs
parents: 450
diff changeset
394 The paragraph marked is the one that contains point or follows point.
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
395
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
396 With argument ARG, puts mark at end of a following paragraph, so that
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
397 the number of paragraphs marked equals ARG.
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
398
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
399 If ARG is negative, point is put at end of this paragraph, mark is put
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
400 at beginning of this or a previous paragraph.
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
401
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
402 If this command is repeated, it marks the next ARG paragraphs after (or
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
403 before, if arg is negative) the ones already marked."
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
404 (interactive "p\np")
687
d8c768dcca7a [xemacs-hg @ 2001-12-05 04:09:24 by youngs]
youngs
parents: 450
diff changeset
405 (unless arg (setq arg 1))
d8c768dcca7a [xemacs-hg @ 2001-12-05 04:09:24 by youngs]
youngs
parents: 450
diff changeset
406 (when (zerop arg)
d8c768dcca7a [xemacs-hg @ 2001-12-05 04:09:24 by youngs]
youngs
parents: 450
diff changeset
407 (error "Cannot mark zero paragraphs"))
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
408 (cond ((and allow-extend
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
409 (eq last-command this-command) (mark t))
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
410 (set-mark
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
411 (save-excursion
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
412 (goto-char (mark))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
413 (forward-paragraph arg)
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
414 (point))))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
415 (t
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
416 (forward-paragraph arg)
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
417 (push-mark nil t t)
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
418 (backward-paragraph arg))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 (defun kill-paragraph (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 "Kill forward to end of paragraph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 With arg N, kill forward to Nth end of paragraph;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 negative arg -N means kill backward to Nth start of paragraph."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 (interactive "*p") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 (kill-region (point) (progn (forward-paragraph arg) (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 (defun backward-kill-paragraph (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 "Kill back to start of paragraph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 With arg N, kill back to Nth start of paragraph;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 negative arg -N means kill forward to Nth end of paragraph."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 (interactive "*p") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 (kill-region (point) (progn (backward-paragraph arg) (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 (defun transpose-paragraphs (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 "Interchange this (or next) paragraph with previous one."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 (interactive "*p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 (transpose-subr 'forward-paragraph arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 (defun start-of-paragraph-text ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 (let ((opoint (point)) npoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 (forward-paragraph -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 (setq npoint (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 (skip-chars-forward " \t\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 ;; If the range of blank lines found spans the original start point,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 ;; try again from the beginning of it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 ;; Must be careful to avoid infinite loop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 ;; when following a single return at start of buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 (if (and (>= (point) opoint) (< npoint opoint))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 (goto-char npoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 (if (> npoint (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 (start-of-paragraph-text))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 (defun end-of-paragraph-text ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 (let ((opoint (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 (forward-paragraph 1)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
457 (if (eq (char-before (point)) ?\n) (backward-char 1))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 (if (<= (point) opoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 (forward-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 (if (< (point) (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 (end-of-paragraph-text))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 (defun forward-sentence (&optional arg)
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
465 "Move forward to next end of sentence. With argument, repeat.
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
466 With negative argument, move backward repeatedly to start of sentence.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 The variable `sentence-end' is a regular expression that matches ends of
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
469 sentences. Also, every paragraph boundary terminates sentences as well."
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
470 ;; #### MERGE! FSF Has (interactive "^p")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 (interactive "_p") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 (or arg (setq arg 1))
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
473 (let ((opoint (point))
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
474 (sentence-end (sentence-end)))
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
475 (while (< arg 0)
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
476 (let ((pos (point))
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
477 ;; We used to use (start-of-paragraph-text), but this can
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
478 ;; prevent sentence-end from matching if it is anchored at
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
479 ;; BOL and the paragraph starts indented.
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
480 (par-beg (save-excursion (backward-paragraph) (point))))
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
481 (if (and (re-search-backward sentence-end par-beg t)
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
482 (or (< (match-end 0) pos)
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
483 (re-search-backward sentence-end par-beg t)))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
484 (goto-char (match-end 0))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
485 (goto-char par-beg)))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
486 (setq arg (1+ arg)))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
487 (while (> arg 0)
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
488 (let ((par-end (save-excursion (end-of-paragraph-text) (point))))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
489 (if (re-search-forward sentence-end par-end t)
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
490 (skip-chars-backward " \t\n")
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
491 (goto-char par-end)))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
492 (setq arg (1- arg)))
5368
ed74d2ca7082 Use ', not #', when a given symbol may not have a function binding at read time
Aidan Kehoe <kehoea@parhasard.net>
parents: 5229
diff changeset
493 (if-fboundp 'constrain-to-field
4103
b4f4e0cc90f1 [xemacs-hg @ 2007-08-07 23:08:47 by aidan]
aidan
parents: 2578
diff changeset
494 (constrain-to-field nil opoint t)
b4f4e0cc90f1 [xemacs-hg @ 2007-08-07 23:08:47 by aidan]
aidan
parents: 2578
diff changeset
495 (error
b4f4e0cc90f1 [xemacs-hg @ 2007-08-07 23:08:47 by aidan]
aidan
parents: 2578
diff changeset
496 'void-function
b4f4e0cc90f1 [xemacs-hg @ 2007-08-07 23:08:47 by aidan]
aidan
parents: 2578
diff changeset
497 "constrain-to-field not available; is xemacs-base installed?"))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
499 (defun repunctuate-sentences ()
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
500 "Put two spaces at the end of sentences from point to the end of buffer.
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
501 It works using `query-replace-regexp'."
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
502 (interactive)
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
503 (query-replace-regexp "\\([]\"')]?\\)\\([.?!]\\)\\([]\"')]?\\) +"
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
504 "\\1\\2\\3 "))
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
505
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
506
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 (defun backward-sentence (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 "Move backward to start of sentence. With arg, do it arg times.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 See `forward-sentence' for more information."
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
510 ;; #### MERGE! FSF Has (interactive "^p")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 (interactive "_p") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 (or arg (setq arg 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 (forward-sentence (- arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 (defun kill-sentence (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 "Kill from point to end of sentence.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 With arg, repeat; negative arg -N means kill back to Nth start of sentence."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 (interactive "*p") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 (kill-region (point) (progn (forward-sentence arg) (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 (defun backward-kill-sentence (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 "Kill back from point to start of sentence.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 With arg, repeat, or kill forward to Nth end of sentence if negative arg -N."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 (interactive "*p") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 (kill-region (point) (progn (backward-sentence arg) (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 (defun mark-end-of-sentence (arg)
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
528 "Put mark at end of sentence. Arg works as in `forward-sentence'.
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
529 If this command is repeated, it marks the next ARG sentences after the
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
530 ones already marked."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 ;; FSF Version:
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
533 ; (push-mark
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
534 ; (save-excursion
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
535 ; (if (and (eq last-command this-command) (mark t))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
536 ; (goto-char (mark)))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
537 ; (forward-sentence arg)
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
538 ; (point))
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
539 ; nil t))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 (mark-something 'mark-end-of-sentence 'forward-sentence arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 (defun mark-end-of-line (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 "Put mark at end of line. Arg works as in `end-of-line'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 (mark-something 'mark-end-of-line 'end-of-line arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 (defun transpose-sentences (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 "Interchange this (next) and previous sentence."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 (interactive "*p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 (transpose-subr 'forward-sentence arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551
5493
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
552 ;; Local Variables:
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
553 ;; coding: utf-8
f62141fe007d Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents: 4103
diff changeset
554 ;; End:
2549
9ec13301bb30 [xemacs-hg @ 2005-02-03 07:15:56 by ben]
ben
parents: 687
diff changeset
555
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 ;;; paragraphs.el ends here