Mercurial > hg > xemacs-beta
annotate lisp/paragraphs.el @ 5908:6174848f3e6c
Use parse_integer() in read_atom(); support bases with ratios like integers
src/ChangeLog addition:
2015-05-08 Aidan Kehoe <kehoea@parhasard.net>
* data.c (init_errors_once_early):
Move the Qunsupported_type here from numbers.c, so it's available
when the majority of our types are not supported.
* general-slots.h: Add it here, too.
* number.c: Remove the definition of Qunsupported_type from here.
* lread.c (read_atom):
Check if the first character could reflect a rational, if so, call
parse_integer(), don't check the syntax of the other
characters. This allows us to accept the non-ASCII digit
characters too.
If that worked partially, but not completely, and the next char is
a slash, try to parse as a ratio.
If that fails, try isfloat_string(), but only if the first
character could plausibly be part of a float.
Otherwise, treat as a symbol.
* lread.c (read_rational):
Rename from read_integer. Handle ratios with the same radix
specification as was used for integers.
* lread.c (read1):
Rename read_integer in this function. Support the Common Lisp
#NNNrMMM syntax for parsing a number MMM of arbitrary radix NNN.
man/ChangeLog addition:
2015-05-08 Aidan Kehoe <kehoea@parhasard.net>
* lispref/numbers.texi (Numbers):
Describe the newly-supported arbitrary-base syntax for rationals
(integers and ratios). Describe that ratios can take the same base
specification as integers, something also new.
tests/ChangeLog addition:
2015-05-08 Aidan Kehoe <kehoea@parhasard.net>
* automated/lisp-reader-tests.el:
Check the arbitrary-base integer reader syntax support, just
added. Check the reader base support for ratios, just added.
Check the non-ASCII-digit support in the reader, just added.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sat, 09 May 2015 00:40:57 +0100 |
parents | 7613e3de80b4 |
children |
rev | line source |
---|---|
2549 | 1 ;;; paragraphs.el --- paragraph and sentence parsing |
428 | 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 | 5 |
6 ;; Maintainer: FSF | |
7 ;; Keywords: wp, dumped | |
8 | |
9 ;; This file is part of XEmacs. | |
10 | |
5495 | 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 | 15 |
16 ;; XEmacs is distributed in the hope that it will be useful, but | |
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 ;; General Public License for more details. | |
20 | |
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 | 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 | 26 |
27 ;;; Commentary: | |
28 | |
29 ;; This file is dumped with XEmacs. | |
30 | |
31 ;; This package provides the paragraph-oriented commands documented in the | |
32 ;; XEmacs Reference Manual. | |
33 | |
34 ;; 06/11/1997 - Use char-(after|before) instead of | |
35 ;; (following|preceding)-char. -slb | |
36 | |
37 ;;; Code: | |
38 | |
2549 | 39 (defgroup paragraphs nil |
40 "Paragraph and sentence parsing." | |
41 :group 'editing) | |
428 | 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 | 44 (define-minor-mode use-hard-newlines |
428 | 45 "Minor mode to distinguish hard and soft newlines. |
46 When active, the functions `newline' and `open-line' add the | |
47 text-property `hard' to newlines that they insert, and a line is | |
48 only considered as a candidate to match `paragraph-start' or | |
49 `paragraph-separate' if it follows a hard newline. | |
50 | |
51 Prefix argument says to turn mode on if positive, off if negative. | |
52 When the mode is turned on, if there are newlines in the buffer but no hard | |
2549 | 53 newlines, ask the user whether to mark as hard any newlines preceeding a |
428 | 54 `paragraph-start' line. From a program, second arg INSERT specifies whether |
55 to do this; it can be `never' to change nothing, t or `always' to force | |
2549 | 56 marking, `guess' to try to do the right thing with no questions, nil |
428 | 57 or anything else to ask the user. |
58 | |
59 Newlines not marked hard are called \"soft\", and are always internal | |
60 to paragraphs. The fill functions insert and delete only soft newlines." | |
2549 | 61 :group 'paragraphs |
62 :extra-args (insert) | |
63 (when use-hard-newlines | |
428 | 64 ;; Turn mode on |
65 ;; Intuit hard newlines -- | |
66 ;; mark as hard any newlines preceding a paragraph-start line. | |
67 (if (or (eq insert t) (eq insert 'always) | |
68 (and (not (eq 'never insert)) | |
69 (not (text-property-any (point-min) (point-max) 'hard t)) | |
70 (save-excursion | |
71 (goto-char (point-min)) | |
72 (search-forward "\n" nil t)) | |
73 (or (eq insert 'guess) | |
74 (y-or-n-p "Make newlines between paragraphs hard? ")))) | |
75 (save-excursion | |
76 (goto-char (point-min)) | |
77 (while (search-forward "\n" nil t) | |
78 (let ((pos (point))) | |
79 (move-to-left-margin) | |
2549 | 80 (when (looking-at paragraph-start) |
81 (set-hard-newline-properties (1- pos) pos)) | |
82 ;; If paragraph-separate, newline after it is hard too. | |
83 (when (looking-at paragraph-separate) | |
84 (set-hard-newline-properties (1- pos) pos) | |
85 (end-of-line) | |
86 (unless (eobp) | |
87 (set-hard-newline-properties (point) (1+ (point))))))))))) | |
428 | 88 |
2549 | 89 (defcustom paragraph-start "\f\\|[ \t]*$" "\ |
428 | 90 *Regexp for beginning of a line that starts OR separates paragraphs. |
91 This regexp should match lines that separate paragraphs | |
92 and should also match lines that start a paragraph | |
93 \(and are part of that paragraph). | |
94 | |
95 This is matched against the text at the left margin, which is not necessarily | |
96 the beginning of the line, so it should never use \"^\" as an anchor. This | |
97 ensures that the paragraph functions will work equally well within a region | |
98 of text indented by a margin setting. | |
99 | |
100 The variable `paragraph-separate' specifies how to distinguish | |
101 lines that start paragraphs from lines that separate them. | |
102 | |
103 If the variable `use-hard-newlines' is non-nil, then only lines following a | |
2549 | 104 hard newline are considered to match." |
105 :group 'paragraphs | |
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 | 108 |
109 ;; paragraph-start requires a hard newline, but paragraph-separate does not: | |
110 ;; It is assumed that paragraph-separate is distinctive enough to be believed | |
111 ;; whenever it occurs, while it is reasonable to set paragraph-start to | |
112 ;; something very minimal, even including "." (which makes every hard newline | |
113 ;; start a new paragraph). | |
114 | |
2549 | 115 (defcustom paragraph-separate "[ \t\f]*$" |
116 "*Regexp for beginning of a line that separates paragraphs. | |
450 | 117 If you change this, you may have to change `paragraph-start' also. |
118 | |
119 A line matching this is not part of any paragraph. | |
428 | 120 |
121 This is matched against the text at the left margin, which is not necessarily | |
122 the beginning of the line, so it should not use \"^\" as an anchor. This | |
123 ensures that the paragraph functions will work equally within a region of | |
2549 | 124 text indented by a margin setting." |
125 :group 'paragraphs | |
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 | 128 |
129 (defcustom sentence-end-double-space t | |
130 "*Non-nil means a single space does not end a sentence. | |
131 This is relevant for filling. See also `sentence-end-without-period' | |
132 and `colon-double-space'. | |
133 | |
134 This variable applies only to filling, not motion commands. To | |
135 change the behavior of motion commands, see `sentence-end'. | |
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 | 140 :type 'boolean |
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 | 143 |
2549 | 144 (defcustom sentence-end-without-period nil |
145 "*Non-nil means a sentence will end without a period. | |
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 | 152 :type 'boolean |
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 | 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 | 173 The value includes the whitespace following the sentence. |
428 | 174 All paragraph boundaries also end sentences, regardless. |
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 |
5740
00a421d2b2ba
Fix no-Mule build.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5495
diff
changeset
|
183 (defcustom sentence-end-base |
00a421d2b2ba
Fix no-Mule build.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5495
diff
changeset
|
184 (concat "[.?!][]\"'" |
5742
7613e3de80b4
Fix stupid omission of cast to string.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5740
diff
changeset
|
185 (if (featurep 'mule) (string (unicode-to-char #x201D)) "") |
5740
00a421d2b2ba
Fix no-Mule build.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5495
diff
changeset
|
186 ")}]*") |
5493
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
187 "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
|
188 :group 'paragraphs |
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
189 :type 'string |
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
190 :version "22.1") |
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
191 (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
|
192 |
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
193 (defun sentence-end () |
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
194 "Return the regexp describing the end of a sentence. |
2549 | 195 |
5493
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
196 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
|
197 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
|
198 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
|
199 `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
|
200 |
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
201 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
|
202 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
|
203 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
|
204 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
|
205 (or sentence-end |
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
206 ;; We accept non-break space along with space. |
5740
00a421d2b2ba
Fix no-Mule build.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5495
diff
changeset
|
207 (concat (if sentence-end-without-period "\\w[ \240][ \240]\\|") |
5493
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
208 "\\(" |
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
209 sentence-end-base |
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
210 (if sentence-end-double-space |
5740
00a421d2b2ba
Fix no-Mule build.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5495
diff
changeset
|
211 "\\($\\|[ \240]$\\|\t\\|[ \240][ \240]\\)" "\\($\\|[\t \240]\\)") |
5493
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
212 "\\|[" sentence-end-without-space "]+" |
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
213 "\\)" |
5740
00a421d2b2ba
Fix no-Mule build.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5495
diff
changeset
|
214 "[ \240\t\n]*"))) |
428 | 215 |
2549 | 216 (defcustom page-delimiter "^\014" |
217 "*Regexp describing line-beginnings that separate pages." | |
218 :group 'paragraphs | |
219 :type 'regexp) | |
5493
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
220 (put 'page-delimiter 'safe-local-variable 'stringp) |
428 | 221 |
2549 | 222 (defcustom paragraph-ignore-fill-prefix nil |
223 "*Non-nil means the paragraph commands are not affected by `fill-prefix'. | |
224 This is desirable in modes where blank lines are the paragraph delimiters." | |
225 :group 'paragraphs | |
226 :type 'boolean) | |
5493
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
227 (put 'paragraph-ignore-fill-prefix 'safe-local-variable 'booleanp) |
428 | 228 |
229 (defun forward-paragraph (&optional arg) | |
230 "Move forward to end of paragraph. | |
2549 | 231 With argument ARG, do it ARG times; |
232 a negative argument ARG = -N means move backward N paragraphs. | |
428 | 233 |
234 A line which `paragraph-start' matches either separates paragraphs | |
235 \(if `paragraph-separate' matches it also) or is the first line of a paragraph. | |
236 A paragraph end is the beginning of a line which is not part of the paragraph | |
2549 | 237 to which the end of the previous line belongs, or the end of the buffer. |
238 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
|
239 ;; #### MERGE! FSF Has (interactive "^p") |
428 | 240 (interactive "_p") ; XEmacs |
241 (or arg (setq arg 1)) | |
2549 | 242 (let* ((opoint (point)) |
243 (fill-prefix-regexp | |
428 | 244 (and fill-prefix (not (equal fill-prefix "")) |
245 (not paragraph-ignore-fill-prefix) | |
246 (regexp-quote fill-prefix))) | |
247 ;; Remove ^ from paragraph-start and paragraph-sep if they are there. | |
248 ;; These regexps shouldn't be anchored, because we look for them | |
249 ;; starting at the left-margin. This allows paragraph commands to | |
250 ;; work normally with indented text. | |
251 ;; This hack will not find problem cases like "whatever\\|^something". | |
2549 | 252 (parstart (if (and (not (equal "" paragraph-start)) |
253 (equal ?^ (aref paragraph-start 0))) | |
254 (substring paragraph-start 1) | |
255 paragraph-start)) | |
256 (parsep (if (and (not (equal "" paragraph-separate)) | |
257 (equal ?^ (aref paragraph-separate 0))) | |
258 (substring paragraph-separate 1) | |
259 paragraph-separate)) | |
260 (parsep | |
428 | 261 (if fill-prefix-regexp |
2549 | 262 (concat parsep "\\|" |
428 | 263 fill-prefix-regexp "[ \t]*$") |
2549 | 264 parsep)) |
428 | 265 ;; This is used for searching. |
2549 | 266 (sp-parstart (concat "^[ \t]*\\(?:" parstart "\\|" parsep "\\)")) |
267 start found-start) | |
428 | 268 (while (and (< arg 0) (not (bobp))) |
2549 | 269 (if (and (not (looking-at parsep)) |
428 | 270 (re-search-backward "^\n" (max (1- (point)) (point-min)) t) |
2549 | 271 (looking-at parsep)) |
272 (setq arg (1+ arg)) | |
428 | 273 (setq start (point)) |
274 ;; Move back over paragraph-separating lines. | |
446 | 275 (backward-char 1) (beginning-of-line) |
428 | 276 (while (and (not (bobp)) |
277 (progn (move-to-left-margin) | |
2549 | 278 (looking-at parsep))) |
279 (forward-line -1)) | |
428 | 280 (if (bobp) |
281 nil | |
2549 | 282 (setq arg (1+ arg)) |
428 | 283 ;; Go to end of the previous (non-separating) line. |
284 (end-of-line) | |
285 ;; Search back for line that starts or separates paragraphs. | |
286 (if (if fill-prefix-regexp | |
2549 | 287 ;; There is a fill prefix; it overrides parstart. |
4103 | 288 (let nil ; (multiple-lines) |
428 | 289 (while (and (progn (beginning-of-line) (not (bobp))) |
290 (progn (move-to-left-margin) | |
2549 | 291 (not (looking-at parsep))) |
428 | 292 (looking-at fill-prefix-regexp)) |
4103 | 293 ; (unless (= (point) start) |
294 ; (setq multiple-lines t)) | |
428 | 295 (forward-line -1)) |
296 (move-to-left-margin) | |
2549 | 297 ;; This deleted code caused a long hanging-indent line |
298 ;; not to be filled together with the following lines. | |
299 ;; ;; Don't move back over a line before the paragraph | |
300 ;; ;; which doesn't start with fill-prefix | |
301 ;; ;; unless that is the only line we've moved over. | |
302 ;; (and (not (looking-at fill-prefix-regexp)) | |
303 ;; multiple-lines | |
304 ;; (forward-line 1)) | |
428 | 305 (not (bobp))) |
2549 | 306 (while (and (re-search-backward sp-parstart nil 1) |
307 (setq found-start t) | |
428 | 308 ;; Found a candidate, but need to check if it is a |
2549 | 309 ;; REAL parstart. |
428 | 310 (progn (setq start (point)) |
311 (move-to-left-margin) | |
2549 | 312 (not (looking-at parsep))) |
313 (not (and (looking-at parstart) | |
314 (or (not use-hard-newlines) | |
5493
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
315 ;; #### XEmacs: We've reversed |
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
316 ;; the order of the following two -- |
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
317 ;; does it matter? |
2549 | 318 (get-text-property (1- start) 'hard) |
319 (bobp))))) | |
320 (setq found-start nil) | |
428 | 321 (goto-char start)) |
2549 | 322 found-start) |
428 | 323 ;; Found one. |
324 (progn | |
325 ;; Move forward over paragraph separators. | |
326 ;; We know this cannot reach the place we started | |
327 ;; because we know we moved back over a non-separator. | |
328 (while (and (not (eobp)) | |
329 (progn (move-to-left-margin) | |
2549 | 330 (looking-at parsep))) |
428 | 331 (forward-line 1)) |
332 ;; If line before paragraph is just margin, back up to there. | |
333 (end-of-line 0) | |
334 (if (> (current-column) (current-left-margin)) | |
335 (forward-char 1) | |
336 (skip-chars-backward " \t") | |
337 (if (not (bolp)) | |
338 (forward-line 1)))) | |
339 ;; No starter or separator line => use buffer beg. | |
2549 | 340 (goto-char (point-min)))))) |
341 | |
428 | 342 (while (and (> arg 0) (not (eobp))) |
2549 | 343 ;; Move forward over separator lines... |
344 (while (and (not (eobp)) | |
345 (progn (move-to-left-margin) (not (eobp))) | |
346 (looking-at parsep)) | |
347 (forward-line 1)) | |
348 (unless (eobp) (setq arg (1- arg))) | |
349 ;; ... and one more line. | |
350 (forward-line 1) | |
428 | 351 (if fill-prefix-regexp |
2549 | 352 ;; There is a fill prefix; it overrides parstart. |
428 | 353 (while (and (not (eobp)) |
354 (progn (move-to-left-margin) (not (eobp))) | |
2549 | 355 (not (looking-at parsep)) |
428 | 356 (looking-at fill-prefix-regexp)) |
357 (forward-line 1)) | |
2549 | 358 (while (and (re-search-forward sp-parstart nil 1) |
428 | 359 (progn (setq start (match-beginning 0)) |
360 (goto-char start) | |
361 (not (eobp))) | |
362 (progn (move-to-left-margin) | |
2549 | 363 (not (looking-at parsep))) |
364 (or (not (looking-at parstart)) | |
428 | 365 (and use-hard-newlines |
366 (not (get-text-property (1- start) 'hard))))) | |
367 (forward-char 1)) | |
368 (if (< (point) (point-max)) | |
2549 | 369 (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
|
370 (if-fboundp 'constrain-to-field |
4103 | 371 (constrain-to-field nil opoint t) |
372 (error | |
373 'void-function | |
374 "constrain-to-field not available; is xemacs-base installed?")) | |
2549 | 375 ;; Return the number of steps that could not be done. |
376 arg)) | |
428 | 377 |
378 (defun backward-paragraph (&optional arg) | |
379 "Move backward to start of paragraph. | |
2549 | 380 With argument ARG, do it ARG times; |
381 a negative argument ARG = -N means move forward N paragraphs. | |
428 | 382 |
383 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
|
384 `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
|
385 `paragraph-separate'ing line; except: if the first real line of a |
428 | 386 paragraph is preceded by a blank line, the paragraph starts at that |
387 blank line. | |
388 | |
389 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
|
390 ;; #### MERGE! FSF Has (interactive "^p") |
428 | 391 (interactive "_p") ; XEmacs |
392 (or arg (setq arg 1)) | |
393 (forward-paragraph (- arg))) | |
394 | |
5493
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
395 (defun mark-paragraph (&optional arg allow-extend) |
428 | 396 "Put point at beginning of this paragraph, mark at end. |
687 | 397 The paragraph marked is the one that contains point or follows point. |
2549 | 398 |
399 With argument ARG, puts mark at end of a following paragraph, so that | |
400 the number of paragraphs marked equals ARG. | |
401 | |
402 If ARG is negative, point is put at end of this paragraph, mark is put | |
403 at beginning of this or a previous paragraph. | |
404 | |
405 If this command is repeated, it marks the next ARG paragraphs after (or | |
406 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
|
407 (interactive "p\np") |
687 | 408 (unless arg (setq arg 1)) |
409 (when (zerop arg) | |
410 (error "Cannot mark zero paragraphs")) | |
5493
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
411 (cond ((and allow-extend |
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
412 (eq last-command this-command) (mark t)) |
2549 | 413 (set-mark |
414 (save-excursion | |
415 (goto-char (mark)) | |
416 (forward-paragraph arg) | |
417 (point)))) | |
418 (t | |
419 (forward-paragraph arg) | |
420 (push-mark nil t t) | |
421 (backward-paragraph arg)))) | |
428 | 422 |
423 (defun kill-paragraph (arg) | |
424 "Kill forward to end of paragraph. | |
425 With arg N, kill forward to Nth end of paragraph; | |
426 negative arg -N means kill backward to Nth start of paragraph." | |
427 (interactive "*p") ; XEmacs | |
428 (kill-region (point) (progn (forward-paragraph arg) (point)))) | |
429 | |
430 (defun backward-kill-paragraph (arg) | |
431 "Kill back to start of paragraph. | |
432 With arg N, kill back to Nth start of paragraph; | |
433 negative arg -N means kill forward to Nth end of paragraph." | |
434 (interactive "*p") ; XEmacs | |
435 (kill-region (point) (progn (backward-paragraph arg) (point)))) | |
436 | |
437 (defun transpose-paragraphs (arg) | |
438 "Interchange this (or next) paragraph with previous one." | |
439 (interactive "*p") | |
440 (transpose-subr 'forward-paragraph arg)) | |
441 | |
442 (defun start-of-paragraph-text () | |
443 (let ((opoint (point)) npoint) | |
444 (forward-paragraph -1) | |
445 (setq npoint (point)) | |
446 (skip-chars-forward " \t\n") | |
447 ;; If the range of blank lines found spans the original start point, | |
448 ;; try again from the beginning of it. | |
449 ;; Must be careful to avoid infinite loop | |
450 ;; when following a single return at start of buffer. | |
451 (if (and (>= (point) opoint) (< npoint opoint)) | |
452 (progn | |
453 (goto-char npoint) | |
454 (if (> npoint (point-min)) | |
455 (start-of-paragraph-text)))))) | |
456 | |
457 (defun end-of-paragraph-text () | |
458 (let ((opoint (point))) | |
459 (forward-paragraph 1) | |
446 | 460 (if (eq (char-before (point)) ?\n) (backward-char 1)) |
428 | 461 (if (<= (point) opoint) |
462 (progn | |
463 (forward-char 1) | |
464 (if (< (point) (point-max)) | |
465 (end-of-paragraph-text)))))) | |
466 | |
467 (defun forward-sentence (&optional arg) | |
5493
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
468 "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
|
469 With negative argument, move backward repeatedly to start of sentence. |
428 | 470 |
471 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
|
472 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
|
473 ;; #### MERGE! FSF Has (interactive "^p") |
428 | 474 (interactive "_p") ; XEmacs |
475 (or arg (setq arg 1)) | |
5493
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
476 (let ((opoint (point)) |
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
477 (sentence-end (sentence-end))) |
2549 | 478 (while (< arg 0) |
479 (let ((pos (point)) | |
5493
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
480 ;; 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
|
481 ;; 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
|
482 ;; BOL and the paragraph starts indented. |
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
483 (par-beg (save-excursion (backward-paragraph) (point)))) |
2549 | 484 (if (and (re-search-backward sentence-end par-beg t) |
485 (or (< (match-end 0) pos) | |
486 (re-search-backward sentence-end par-beg t))) | |
487 (goto-char (match-end 0)) | |
488 (goto-char par-beg))) | |
489 (setq arg (1+ arg))) | |
490 (while (> arg 0) | |
491 (let ((par-end (save-excursion (end-of-paragraph-text) (point)))) | |
492 (if (re-search-forward sentence-end par-end t) | |
493 (skip-chars-backward " \t\n") | |
494 (goto-char par-end))) | |
495 (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
|
496 (if-fboundp 'constrain-to-field |
4103 | 497 (constrain-to-field nil opoint t) |
498 (error | |
499 'void-function | |
500 "constrain-to-field not available; is xemacs-base installed?")))) | |
428 | 501 |
5493
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
502 (defun repunctuate-sentences () |
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
503 "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
|
504 It works using `query-replace-regexp'." |
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
505 (interactive) |
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
506 (query-replace-regexp "\\([]\"')]?\\)\\([.?!]\\)\\([]\"')]?\\) +" |
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
507 "\\1\\2\\3 ")) |
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
508 |
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
509 |
428 | 510 (defun backward-sentence (&optional arg) |
511 "Move backward to start of sentence. With arg, do it arg times. | |
512 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
|
513 ;; #### MERGE! FSF Has (interactive "^p") |
428 | 514 (interactive "_p") ; XEmacs |
515 (or arg (setq arg 1)) | |
516 (forward-sentence (- arg))) | |
517 | |
518 (defun kill-sentence (&optional arg) | |
519 "Kill from point to end of sentence. | |
520 With arg, repeat; negative arg -N means kill back to Nth start of sentence." | |
521 (interactive "*p") ; XEmacs | |
522 (kill-region (point) (progn (forward-sentence arg) (point)))) | |
523 | |
524 (defun backward-kill-sentence (&optional arg) | |
525 "Kill back from point to start of sentence. | |
526 With arg, repeat, or kill forward to Nth end of sentence if negative arg -N." | |
527 (interactive "*p") ; XEmacs | |
528 (kill-region (point) (progn (backward-sentence arg) (point)))) | |
529 | |
530 (defun mark-end-of-sentence (arg) | |
2549 | 531 "Put mark at end of sentence. Arg works as in `forward-sentence'. |
532 If this command is repeated, it marks the next ARG sentences after the | |
533 ones already marked." | |
428 | 534 (interactive "p") |
535 ;; FSF Version: | |
2549 | 536 ; (push-mark |
537 ; (save-excursion | |
538 ; (if (and (eq last-command this-command) (mark t)) | |
539 ; (goto-char (mark))) | |
540 ; (forward-sentence arg) | |
541 ; (point)) | |
542 ; nil t)) | |
428 | 543 (mark-something 'mark-end-of-sentence 'forward-sentence arg)) |
544 | |
545 (defun mark-end-of-line (arg) | |
546 "Put mark at end of line. Arg works as in `end-of-line'." | |
547 (interactive "p") | |
548 (mark-something 'mark-end-of-line 'end-of-line arg)) | |
549 | |
550 (defun transpose-sentences (arg) | |
551 "Interchange this (next) and previous sentence." | |
552 (interactive "*p") | |
553 (transpose-subr 'forward-sentence arg)) | |
554 | |
5493
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
555 ;; Local Variables: |
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
556 ;; coding: utf-8 |
f62141fe007d
Sync paragraphs.el to FSF 23.1.92
Ben Wing <ben@xemacs.org>
parents:
4103
diff
changeset
|
557 ;; End: |
2549 | 558 |
428 | 559 ;;; paragraphs.el ends here |