aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/textmodes
diff options
context:
space:
mode:
authorRichard M. Stallman1993-03-28 22:07:36 +0000
committerRichard M. Stallman1993-03-28 22:07:36 +0000
commitcc1344d5cf511bf95a3776084b84bcbeda0cc385 (patch)
tree60a11579770e105c733df7f0455ffd49a48f8e0b /lisp/textmodes
parent4c53bd2bb08b166f271b3acfb8381064dc3e8089 (diff)
downloademacs-cc1344d5cf511bf95a3776084b84bcbeda0cc385.tar.gz
emacs-cc1344d5cf511bf95a3776084b84bcbeda0cc385.zip
Cancel previous change; this version should be identical to version 1.17.
Diffstat (limited to 'lisp/textmodes')
-rw-r--r--lisp/textmodes/fill.el64
1 files changed, 25 insertions, 39 deletions
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el
index f1669d7b049..a905bef78d1 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -66,7 +66,7 @@ From program, pass args FROM, TO and JUSTIFY-FLAG."
66 (if (and buffer-undo-list (not (eq buffer-undo-list t))) 66 (if (and buffer-undo-list (not (eq buffer-undo-list t)))
67 (setq buffer-undo-list (cons (point) buffer-undo-list))) 67 (setq buffer-undo-list (cons (point) buffer-undo-list)))
68 ;; Don't let Adaptive Fill mode alter the fill prefix permanently. 68 ;; Don't let Adaptive Fill mode alter the fill prefix permanently.
69 (let ((fill-prefix fill-prefix) spc) 69 (let ((fill-prefix fill-prefix))
70 ;; Figure out how this paragraph is indented, if desired. 70 ;; Figure out how this paragraph is indented, if desired.
71 (if (and adaptive-fill-mode 71 (if (and adaptive-fill-mode
72 (or (null fill-prefix) (string= fill-prefix ""))) 72 (or (null fill-prefix) (string= fill-prefix "")))
@@ -114,48 +114,34 @@ From program, pass args FROM, TO and JUSTIFY-FLAG."
114 ;; from is now before the text to fill, 114 ;; from is now before the text to fill,
115 ;; but after any fill prefix on the first line. 115 ;; but after any fill prefix on the first line.
116 116
117 ;; spc (our filler character) is normally SPC;
118 ;; if SPC does not have syntax class whitespace, find a filler that does.
119 (if (= (char-syntax ?\ ) ?\ )
120 (setq spc ?\ )
121 (setq spc 0)
122 (while (not (= (char-syntax spc) ?\ ))
123 (setq spc (1+ spc))))
124
125 ;; Make sure sentences ending at end of line get an extra space. 117 ;; Make sure sentences ending at end of line get an extra space.
126 ;; loses on split abbrevs ("Mr.\nSmith"). This is fairly specific 118 ;; loses on split abbrevs ("Mr.\nSmith")
127 ;; to text mode.
128 (goto-char from) 119 (goto-char from)
129 (while (re-search-forward "[.?!][])}\"']*$" nil t) 120 (while (re-search-forward "[.?!][])}\"']*$" nil t)
130 (insert spc)) 121 (insert ? ))
131 122
132 ;; Then change all newlines to spaces. 123 ;; Then change all newlines to spaces.
133 (subst-char-in-region from to ?\n spc) 124 (subst-char-in-region from (point-max) ?\n ?\ )
134 125
135 ;; Go to beginning of paragraph (after indent) 126 ;; Flush excess spaces, except in the paragraph indentation.
136 (goto-char from) 127 (goto-char from)
137 (skip-syntax-forward " ") 128 (skip-chars-forward " \t")
138 129 ;; nuke tabs while we're at it; they get screwed up in a fill
139 ;; If tabs have whitespace class, nuke them; they get screwed up 130 ;; this is quick, but loses when a sole tab follows the end of a sentence.
140 ;; in a fill. This is quick, but loses when a sole tab follows 131 ;; actually, it is difficult to tell that from "Mr.\tSmith".
141 ;; the end of a sentence. actually, it is difficult to tell 132 ;; blame the typist.
142 ;; that from "Mr.\tSmith". Blame the typist. 133 (subst-char-in-region (point) (point-max) ?\t ?\ )
143 (if (= (char-syntax ?\t) ?\ ) 134 (while (re-search-forward " *" nil t)
144 (subst-char-in-region (point) to ?\t spc))
145
146 ;; Flush excess whitespace, except in the paragraph indentation.
147 (while (re-search-forward "\\s-\\s-\\s-*" nil t)
148 (delete-region 135 (delete-region
149 (+ (match-beginning 0) 136 (+ (match-beginning 0)
150 (if (save-excursion 137 (if (save-excursion
151 (skip-syntax-backward " ).") 138 (skip-chars-backward " ]})\"'")
152 (memq (preceding-char) '(?. ?? ?!))) 139 (memq (preceding-char) '(?. ?? ?!)))
153 2 1)) 140 2 1))
154 (match-end 0))) 141 (match-end 0)))
155 (goto-char (point-max)) 142 (goto-char (point-max))
156 (delete-horizontal-space) 143 (delete-horizontal-space)
157 (insert spc) 144 (insert " ")
158 (insert spc)
159 (goto-char (point-min)) 145 (goto-char (point-min))
160 146
161 ;; This is the actual filling loop. 147 ;; This is the actual filling loop.
@@ -166,7 +152,7 @@ From program, pass args FROM, TO and JUSTIFY-FLAG."
166 (if (eobp) 152 (if (eobp)
167 nil 153 nil
168 ;; Move back to start of word. 154 ;; Move back to start of word.
169 (skip-syntax-backward "^ " linebeg) 155 (skip-chars-backward "^ \n" linebeg)
170 ;; Don't break after a period followed by just one space. 156 ;; Don't break after a period followed by just one space.
171 ;; Move back to the previous place to break. 157 ;; Move back to the previous place to break.
172 ;; The reason is that if a period ends up at the end of a line, 158 ;; The reason is that if a period ends up at the end of a line,
@@ -174,16 +160,16 @@ From program, pass args FROM, TO and JUSTIFY-FLAG."
174 ;; If we now know it does not end a sentence, 160 ;; If we now know it does not end a sentence,
175 ;; avoid putting it at the end of the line. 161 ;; avoid putting it at the end of the line.
176 (while (and (> (point) (+ linebeg 2)) 162 (while (and (> (point) (+ linebeg 2))
177 (eq (char-syntax (preceding-char)) ?\ ) 163 (eq (preceding-char) ?\ )
178 (eq (char-after (- (point) 2)) ?\.)) 164 (eq (char-after (- (point) 2)) ?\.))
179 (forward-char -2) 165 (forward-char -2)
180 (skip-syntax-backward "^ " linebeg)) 166 (skip-chars-backward "^ \n" linebeg))
181 (if (if (zerop prefixcol) (bolp) (>= prefixcol (current-column))) 167 (if (if (zerop prefixcol) (bolp) (>= prefixcol (current-column)))
182 ;; Keep at least one word even if fill prefix exceeds margin. 168 ;; Keep at least one word even if fill prefix exceeds margin.
183 ;; This handles all but the first line of the paragraph. 169 ;; This handles all but the first line of the paragraph.
184 (progn 170 (progn
185 (skip-syntax-forward " ") 171 (skip-chars-forward " ")
186 (skip-syntax-forward "^ ")) 172 (skip-chars-forward "^ \n"))
187 ;; Normally, move back over the single space between the words. 173 ;; Normally, move back over the single space between the words.
188 (forward-char -1))) 174 (forward-char -1)))
189 (if (and fill-prefix (zerop prefixcol) 175 (if (and fill-prefix (zerop prefixcol)
@@ -193,12 +179,12 @@ From program, pass args FROM, TO and JUSTIFY-FLAG."
193 ;; Keep at least one word even if fill prefix exceeds margin. 179 ;; Keep at least one word even if fill prefix exceeds margin.
194 ;; This handles the first line of the paragraph. 180 ;; This handles the first line of the paragraph.
195 (progn 181 (progn
196 (skip-syntax-forward " ") 182 (skip-chars-forward " ")
197 (skip-syntax-forward "^ "))) 183 (skip-chars-forward "^ \n")))
198 ;; Replace all whitespace here with one newline. 184 ;; Replace all whitespace here with one newline.
199 ;; Insert before deleting, so we don't forget which side of 185 ;; Insert before deleting, so we don't forget which side of
200 ;; the whitespace point or markers used to be on. 186 ;; the whitespace point or markers used to be on.
201 (skip-syntax-backward " ") 187 (skip-chars-backward " ")
202 (insert ?\n) 188 (insert ?\n)
203 (delete-horizontal-space) 189 (delete-horizontal-space)
204 ;; Insert the fill prefix at start of each line. 190 ;; Insert the fill prefix at start of each line.
@@ -250,17 +236,17 @@ Prefix arg (non-nil third arg, if called from program) means justify as well."
250 (let (ncols beg indent) 236 (let (ncols beg indent)
251 (beginning-of-line) 237 (beginning-of-line)
252 (forward-char (length fill-prefix)) 238 (forward-char (length fill-prefix))
253 (skip-syntax-forward " " (save-excursion (end-of-line) (point))) 239 (skip-chars-forward " \t")
254 (setq indent (current-column)) 240 (setq indent (current-column))
255 (setq beg (point)) 241 (setq beg (point))
256 (end-of-line) 242 (end-of-line)
257 (narrow-to-region beg (point)) 243 (narrow-to-region beg (point))
258 (goto-char beg) 244 (goto-char beg)
259 (while (re-search-forward "\\s-\\s-\\s-*" nil t) 245 (while (re-search-forward " *" nil t)
260 (delete-region 246 (delete-region
261 (+ (match-beginning 0) 247 (+ (match-beginning 0)
262 (if (save-excursion 248 (if (save-excursion
263 (skip-syntax-backward " ).") 249 (skip-chars-backward " ])\"'")
264 (memq (preceding-char) '(?. ?? ?!))) 250 (memq (preceding-char) '(?. ?? ?!)))
265 2 1)) 251 2 1))
266 (match-end 0))) 252 (match-end 0)))