aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-02-04 04:45:52 +0000
committerRichard M. Stallman1994-02-04 04:45:52 +0000
commit8f985fe23c11999783a51210da71c8cf2547c537 (patch)
treee829649eb6a61f0ddd56efc91aa11dd881e2f914
parent756811fb0bfda595b7c96eb3c59a94152c35a708 (diff)
downloademacs-8f985fe23c11999783a51210da71c8cf2547c537.tar.gz
emacs-8f985fe23c11999783a51210da71c8cf2547c537.zip
(sentence-end-double-space): New variable.
(fill-region-as-paragraph): Handle it.
-rw-r--r--lisp/textmodes/fill.el56
1 files changed, 35 insertions, 21 deletions
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el
index 3ef81b87e1c..bf49fe88429 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -32,10 +32,13 @@
32Non-nil means changing indent doesn't end a paragraph. 32Non-nil means changing indent doesn't end a paragraph.
33That mode can handle paragraphs with extra indentation on the first line, 33That mode can handle paragraphs with extra indentation on the first line,
34but it requires separator lines between paragraphs. 34but it requires separator lines between paragraphs.
35Nil means that any change in indentation starts a new paragraph.") 35A value of nil means that any change in indentation starts a new paragraph.")
36
37(defconst sentence-end-double-space t
38 "*Non-nil means a single space does not end a sentence.")
36 39
37(defun set-fill-prefix () 40(defun set-fill-prefix ()
38 "Set the fill-prefix to the current line up to point. 41 "Set the fill prefix to the current line up to point.
39Filling expects lines to start with the fill prefix and 42Filling expects lines to start with the fill prefix and
40reinserts the fill prefix in each resulting line." 43reinserts the fill prefix in each resulting line."
41 (interactive) 44 (interactive)
@@ -58,8 +61,10 @@ on the second line of a paragraph is used as the standard indentation
58for the paragraph.") 61for the paragraph.")
59 62
60(defun fill-region-as-paragraph (from to &optional justify-flag) 63(defun fill-region-as-paragraph (from to &optional justify-flag)
61 "Fill region as one paragraph: break lines to fit fill-column. 64 "Fill region as one paragraph: break lines to fit `fill-column'.
62Prefix arg means justify too. 65Prefix arg means justify too.
66If `sentence-end-double-space' is non-nil, then period followed by one
67space does not end a sentence, so don't break a line there.
63From program, pass args FROM, TO and JUSTIFY-FLAG." 68From program, pass args FROM, TO and JUSTIFY-FLAG."
64 (interactive "r\nP") 69 (interactive "r\nP")
65 ;; Arrange for undoing the fill to restore point. 70 ;; Arrange for undoing the fill to restore point.
@@ -126,17 +131,18 @@ From program, pass args FROM, TO and JUSTIFY-FLAG."
126 ;; Flush excess spaces, except in the paragraph indentation. 131 ;; Flush excess spaces, except in the paragraph indentation.
127 (goto-char from) 132 (goto-char from)
128 (skip-chars-forward " \t") 133 (skip-chars-forward " \t")
129 ;; nuke tabs while we're at it; they get screwed up in a fill 134 ;; Nuke tabs while we're at it; they get screwed up in a fill.
130 ;; this is quick, but loses when a sole tab follows the end of a sentence. 135 ;; This is quick, but loses when a tab follows the end of a sentence.
131 ;; actually, it is difficult to tell that from "Mr.\tSmith". 136 ;; Actually, it is difficult to tell that from "Mr.\tSmith".
132 ;; blame the typist. 137 ;; Blame the typist.
133 (subst-char-in-region (point) (point-max) ?\t ?\ ) 138 (subst-char-in-region (point) (point-max) ?\t ?\ )
134 (while (re-search-forward " *" nil t) 139 (while (re-search-forward " *" nil t)
135 (delete-region 140 (delete-region
136 (+ (match-beginning 0) 141 (+ (match-beginning 0)
137 (if (save-excursion 142 (if (and sentence-end-double-space
138 (skip-chars-backward " ]})\"'") 143 (save-excursion
139 (memq (preceding-char) '(?. ?? ?!))) 144 (skip-chars-backward " ]})\"'")
145 (memq (preceding-char) '(?. ?? ?!))))
140 2 1)) 146 2 1))
141 (match-end 0))) 147 (match-end 0)))
142 (goto-char (point-max)) 148 (goto-char (point-max))
@@ -159,12 +165,13 @@ From program, pass args FROM, TO and JUSTIFY-FLAG."
159 ;; further fills will assume it ends a sentence. 165 ;; further fills will assume it ends a sentence.
160 ;; If we now know it does not end a sentence, 166 ;; If we now know it does not end a sentence,
161 ;; avoid putting it at the end of the line. 167 ;; avoid putting it at the end of the line.
162 (while (and (> (point) (+ linebeg 2)) 168 (if sentence-end-double-space
163 (eq (preceding-char) ?\ ) 169 (while (and (> (point) (+ linebeg 2))
164 (not (eq (following-char) ?\ )) 170 (eq (preceding-char) ?\ )
165 (eq (char-after (- (point) 2)) ?\.)) 171 (not (eq (following-char) ?\ ))
166 (forward-char -2) 172 (eq (char-after (- (point) 2)) ?\.))
167 (skip-chars-backward "^ \n" linebeg)) 173 (forward-char -2)
174 (skip-chars-backward "^ \n" linebeg)))
168 (if (if (zerop prefixcol) 175 (if (if (zerop prefixcol)
169 (save-excursion 176 (save-excursion
170 (skip-chars-backward " " linebeg) 177 (skip-chars-backward " " linebeg)
@@ -178,9 +185,10 @@ From program, pass args FROM, TO and JUSTIFY-FLAG."
178 (while (and (not (eobp)) 185 (while (and (not (eobp))
179 (or first 186 (or first
180 (and (not (bobp)) 187 (and (not (bobp))
188 sentence-end-double-space
181 (save-excursion (forward-char -1) 189 (save-excursion (forward-char -1)
182 (looking-at "\\. ") 190 (and (looking-at "\\. ")
183 (not (looking-at "\\. ")))))) 191 (not (looking-at "\\. ")))))))
184 (skip-chars-forward " ") 192 (skip-chars-forward " ")
185 (skip-chars-forward "^ \n") 193 (skip-chars-forward "^ \n")
186 (setq first nil))) 194 (setq first nil)))
@@ -197,8 +205,10 @@ From program, pass args FROM, TO and JUSTIFY-FLAG."
197 (while (and (not (eobp)) 205 (while (and (not (eobp))
198 (or first 206 (or first
199 (and (not (bobp)) 207 (and (not (bobp))
208 sentence-end-double-space
200 (save-excursion (forward-char -1) 209 (save-excursion (forward-char -1)
201 (looking-at "\\. "))))) 210 (and (looking-at "\\. ")
211 (not (looking-at "\\. ")))))))
202 (skip-chars-forward " ") 212 (skip-chars-forward " ")
203 (skip-chars-forward "^ \n") 213 (skip-chars-forward "^ \n")
204 (setq first nil))))) 214 (setq first nil)))))
@@ -222,7 +232,9 @@ From program, pass args FROM, TO and JUSTIFY-FLAG."
222 (forward-line 1)))))))) 232 (forward-line 1))))))))
223 233
224(defun fill-paragraph (arg) 234(defun fill-paragraph (arg)
225 "Fill paragraph at or after point. Prefix arg means justify as well." 235 "Fill paragraph at or after point. Prefix arg means justify as well.
236If `sentence-end-double-space' is non-nil, then period followed by one
237space does not end a sentence, so don't break a line there."
226 (interactive "P") 238 (interactive "P")
227 (let ((before (point))) 239 (let ((before (point)))
228 (save-excursion 240 (save-excursion
@@ -235,7 +247,9 @@ From program, pass args FROM, TO and JUSTIFY-FLAG."
235 247
236(defun fill-region (from to &optional justify-flag) 248(defun fill-region (from to &optional justify-flag)
237 "Fill each of the paragraphs in the region. 249 "Fill each of the paragraphs in the region.
238Prefix arg (non-nil third arg, if called from program) means justify as well." 250Prefix arg (non-nil third arg, if called from program) means justify as well.
251If `sentence-end-double-space' is non-nil, then period followed by one
252space does not end a sentence, so don't break a line there."
239 (interactive "r\nP") 253 (interactive "r\nP")
240 (save-restriction 254 (save-restriction
241 (narrow-to-region from to) 255 (narrow-to-region from to)