Mercurial > hg > xemacs-beta
annotate lisp/fill.el @ 5587:3fde0e346ad7
Prevent assert at frame.c, l. 6311 by initializing glyph cachels.
* frame.c (Fmake_frame): Ensure that reset_glyph_cachels gets called.
(setup_minibuffer_frame): Improve header comment.
* redisplay.c (redisplay_window): Update comment.
Remove code checking for uninitialized face_cachels and glyph_cachels.
Can't happen in theory, and guarded by asserts in practice.
* window.c (allocate_window): Update comment on reset_*_cachels.
author | Stephen J. Turnbull <stephen@xemacs.org> |
---|---|
date | Sat, 29 Oct 2011 00:35:33 +0900 |
parents | 308d34e9f07d |
children |
rev | line source |
---|---|
428 | 1 ;;; fill.el --- fill commands for XEmacs. |
2 | |
3 ;; Copyright (C) 1985, 86, 92, 94, 95, 1997 Free Software Foundation, Inc. | |
4 | |
5 ;; Maintainer: XEmacs Development Team | |
6 ;; Keywords: wp, dumped | |
7 | |
8 ;; This file is part of XEmacs. | |
9 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2510
diff
changeset
|
10 ;; XEmacs is free software: you can redistribute it and/or modify it |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2510
diff
changeset
|
11 ;; under the terms of the GNU General Public License as published by the |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2510
diff
changeset
|
12 ;; Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2510
diff
changeset
|
13 ;; option) any later version. |
428 | 14 |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2510
diff
changeset
|
15 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2510
diff
changeset
|
16 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2510
diff
changeset
|
17 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2510
diff
changeset
|
18 ;; for more details. |
428 | 19 |
20 ;; 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:
2510
diff
changeset
|
21 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
428 | 22 |
23 ;;; Synched up with: FSF 19.34. | |
2510 | 24 ;;; NOTE: Merging past 19.34 is currently impossible. Later versions |
25 ;;; contain FSF's own Kinsoku processing, conflicting with the current code | |
26 ;;; and depending on various features of their Mule implementation that | |
27 ;;; do not currently exist. | |
428 | 28 |
29 ;;; Commentary: | |
30 | |
31 ;; This file is dumped with XEmacs. | |
32 | |
33 ;; All the commands for filling text. These are documented in the XEmacs | |
34 ;; Reference Manual. | |
35 | |
36 ;; 97/3/14 Jareth Hein (jhod@po.iijnet.or.jp) added functions for kinsoku (asian text | |
37 ;; line break processing) | |
38 ;; 97/06/11 Steve Baur (steve@xemacs.org) converted broken | |
39 ;; following-char/preceding-char calls to char-after/char-before. | |
40 | |
41 ;;; Code: | |
42 | |
43 (defgroup fill nil | |
44 "Indenting and filling text." | |
45 :group 'editing) | |
46 | |
47 (defcustom fill-individual-varying-indent nil | |
48 "*Controls criterion for a new paragraph in `fill-individual-paragraphs'. | |
49 Non-nil means changing indent doesn't end a paragraph. | |
50 That mode can handle paragraphs with extra indentation on the first line, | |
51 but it requires separator lines between paragraphs. | |
52 A value of nil means that any change in indentation starts a new paragraph." | |
53 :type 'boolean | |
54 :group 'fill) | |
55 | |
56 (defcustom sentence-end-double-space t | |
57 "*Non-nil means a single space does not end a sentence. | |
58 This variable applies only to filling, not motion commands. To | |
59 change the behavior of motion commands, see `sentence-end'." | |
60 :type 'boolean | |
61 :group 'fill) | |
62 | |
63 (defcustom colon-double-space nil | |
64 "*Non-nil means put two spaces after a colon when filling." | |
65 :type 'boolean | |
66 :group 'fill) | |
67 | |
68 (defvar fill-paragraph-function nil | |
69 "Mode-specific function to fill a paragraph, or nil if there is none. | |
70 If the function returns nil, then `fill-paragraph' does its normal work.") | |
71 | |
72 (defun set-fill-prefix () | |
73 "Set the fill prefix to the current line up to point. | |
74 Filling expects lines to start with the fill prefix and | |
75 reinserts the fill prefix in each resulting line." | |
76 (interactive) | |
77 (setq fill-prefix (buffer-substring | |
78 (save-excursion (move-to-left-margin) (point)) | |
79 (point))) | |
80 (if (equal fill-prefix "") | |
81 (setq fill-prefix nil)) | |
82 (if fill-prefix | |
83 (message "fill-prefix: \"%s\"" fill-prefix) | |
84 (message "fill-prefix cancelled"))) | |
85 | |
86 (defcustom adaptive-fill-mode t | |
87 "*Non-nil means determine a paragraph's fill prefix from its text." | |
88 :type 'boolean | |
89 :group 'fill) | |
90 | |
91 ;; #### - this is still weak. Yeah, there's filladapt, but this should | |
92 ;; still be better... --Stig | |
444 | 93 (defcustom adaptive-fill-regexp "[ \t]*\\([#;>*]+ +\\)?" |
428 | 94 "*Regexp to match text at start of line that constitutes indentation. |
95 If Adaptive Fill mode is enabled, whatever text matches this pattern | |
96 on the second line of a paragraph is used as the standard indentation | |
97 for the paragraph. If the paragraph has just one line, the indentation | |
98 is taken from that line." | |
99 :type 'regexp | |
100 :group 'fill) | |
101 | |
102 (defcustom adaptive-fill-function nil | |
103 "*Function to call to choose a fill prefix for a paragraph. | |
104 This function is used when `adaptive-fill-regexp' does not match." | |
105 :type 'function | |
106 :group 'fill) | |
107 | |
444 | 108 ;; Added for kinsoku processing. Use this instead of |
428 | 109 ;; (skip-chars-backward "^ \t\n") |
110 ;; (skip-chars-backward "^ \n" linebeg) | |
111 (defun fill-move-backward-to-break-point (regexp &optional lim) | |
112 (let ((opoint (point))) | |
113 ;; 93.8.23 by kawamoto@ics.es.osaka-u.ac.jp | |
114 ;; case of first 'word' being longer than fill-column | |
115 (if (not (re-search-backward regexp lim 'move)) | |
116 nil | |
117 ;; we have skipped backward SPC or WAN (word-across-newline). So move point forward again. | |
118 (forward-char) | |
119 (if (< opoint (point)) | |
120 (forward-char -1))))) | |
121 | |
122 ;; Added for kinsoku processing. Use instead of | |
123 ;; (re-search-forward "[ \t]" opoint t) | |
124 ;; (skip-chars-forward "^ \n") | |
125 ;; (skip-chars-forward "^ \n") | |
126 (defun fill-move-forward-to-break-point (regexp &optional lim) | |
127 (let ((opoint (point))) | |
128 (if (not (re-search-forward regexp lim 'move)) | |
129 nil | |
130 (forward-char -1) | |
131 (if (< (point) opoint) | |
132 (forward-char)))) | |
502 | 133 (if (featurep 'mule) (declare-fboundp (kinsoku-process-extend)))) |
428 | 134 |
135 (defun fill-end-of-sentence-p () | |
136 (save-excursion | |
137 (skip-chars-backward " ]})\"'") | |
138 (memq (char-before (point)) '(?. ?? ?!)))) | |
139 | |
140 (defun current-fill-column () | |
141 "Return the fill-column to use for this line. | |
142 The fill-column to use for a buffer is stored in the variable `fill-column', | |
143 but can be locally modified by the `right-margin' text property, which is | |
144 subtracted from `fill-column'. | |
145 | |
146 The fill column to use for a line is the first column at which the column | |
147 number equals or exceeds the local fill-column - right-margin difference." | |
148 (save-excursion | |
149 (if fill-column | |
150 (let* ((here (progn (beginning-of-line) (point))) | |
151 (here-col 0) | |
152 (eol (progn (end-of-line) (point))) | |
153 margin fill-col change col) | |
154 ;; Look separately at each region of line with a different right-margin. | |
155 (while (and (setq margin (get-text-property here 'right-margin) | |
156 fill-col (- fill-column (or margin 0)) | |
157 change (text-property-not-all | |
158 here eol 'right-margin margin)) | |
159 (progn (goto-char (1- change)) | |
160 (setq col (current-column)) | |
161 (< col fill-col))) | |
162 (setq here change | |
163 here-col col)) | |
164 (max here-col fill-col))))) | |
165 | |
444 | 166 (defun canonically-space-region (start end) |
428 | 167 "Remove extra spaces between words in region. |
168 Leave one space between words, two at end of sentences or after colons | |
169 \(depending on values of `sentence-end-double-space' and `colon-double-space'). | |
170 Remove indentation from each line." | |
171 (interactive "r") | |
172 ;;;### 97/3/14 jhod: Do I have to add anything here for kinsoku? | |
173 (save-excursion | |
444 | 174 (goto-char start) |
428 | 175 ;; XEmacs - (ENE/stig from fa-extras.el): Skip the start of a comment. |
176 (and comment-start-skip | |
177 (looking-at comment-start-skip) | |
178 (goto-char (match-end 0))) | |
179 ;; Nuke tabs; they get screwed up in a fill. | |
180 ;; This is quick, but loses when a tab follows the end of a sentence. | |
181 ;; Actually, it is difficult to tell that from "Mr.\tSmith". | |
182 ;; Blame the typist. | |
444 | 183 (subst-char-in-region start end ?\t ?\ ) |
428 | 184 (while (and (< (point) end) |
185 (re-search-forward " *" end t)) | |
186 (delete-region | |
187 (+ (match-beginning 0) | |
188 ;; Determine number of spaces to leave: | |
189 (save-excursion | |
190 (skip-chars-backward " ]})\"'") | |
191 (cond ((and sentence-end-double-space | |
192 (memq (char-before (point)) '(?. ?? ?!))) 2) | |
193 ((and colon-double-space | |
194 (eq (char-before (point)) ?:)) 2) | |
195 ((char-equal (char-before (point)) ?\n) 0) | |
196 (t 1)))) | |
197 (match-end 0))) | |
198 ;; Make sure sentences ending at end of line get an extra space. | |
199 ;; loses on split abbrevs ("Mr.\nSmith") | |
444 | 200 (goto-char start) |
428 | 201 (while (and (< (point) end) |
202 (re-search-forward "[.?!][])}\"']*$" end t)) | |
203 ;; We insert before markers in case a caller such as | |
204 ;; do-auto-fill has done a save-excursion with point at the end | |
205 ;; of the line and wants it to stay at the end of the line. | |
2510 | 206 (insert-before-markers-and-inherit ? )))) |
428 | 207 |
208 ;; XEmacs -- added DONT-SKIP-FIRST. Port of older code changes by Stig. | |
209 ;; #### probably this junk is broken -- do-auto-fill doesn't actually use | |
210 ;; it. If so, it should be removed. | |
211 | |
212 (defun fill-context-prefix (from to &optional first-line-regexp | |
213 dont-skip-first) | |
214 "Compute a fill prefix from the text between FROM and TO. | |
215 This uses the variables `adaptive-fill-prefix' and `adaptive-fill-function'. | |
216 If FIRST-LINE-REGEXP is non-nil, then when taking a prefix from the | |
217 first line, insist it must match FIRST-LINE-REGEXP." | |
218 (save-excursion | |
219 (goto-char from) | |
220 (if (eolp) (forward-line 1)) | |
221 ;; Move to the second line unless there is just one. | |
222 (let ((firstline (point)) | |
223 ;; Non-nil if we are on the second line. | |
224 at-second | |
225 result) | |
226 ;; XEmacs change | |
227 (if (not dont-skip-first) | |
228 (forward-line 1)) | |
229 (cond ((>= (point) to) | |
230 (goto-char firstline)) | |
231 ((/= (point) from) | |
232 (setq at-second t))) | |
233 (move-to-left-margin) | |
234 ;; XEmacs change | |
235 (let ((start (point)) | |
236 ; jhod: no longer used? | |
237 ;(eol (save-excursion (end-of-line) (point))) | |
238 ) | |
239 (setq result | |
240 (if (or dont-skip-first (not (looking-at paragraph-start))) | |
241 (cond ((and adaptive-fill-regexp (looking-at adaptive-fill-regexp)) | |
242 (buffer-substring-no-properties start (match-end 0))) | |
243 (adaptive-fill-function (funcall adaptive-fill-function))))) | |
244 (and result | |
245 (or at-second | |
246 (null first-line-regexp) | |
247 (string-match first-line-regexp result)) | |
248 result))))) | |
249 | |
250 ;; XEmacs (stig) - this is pulled out of fill-region-as-paragraph so that it | |
251 ;; can also be called from do-auto-fill | |
252 ;; #### But it's not used there. Chuck pulled it out because it broke things. | |
253 (defun maybe-adapt-fill-prefix (&optional from to dont-skip-first) | |
254 (if (and adaptive-fill-mode | |
255 (or (null fill-prefix) (string= fill-prefix ""))) | |
256 (setq fill-prefix (fill-context-prefix from to nil dont-skip-first)))) | |
257 | |
258 (defun fill-region-as-paragraph (from to &optional justify | |
259 nosqueeze squeeze-after) | |
260 "Fill the region as one paragraph. | |
261 It removes any paragraph breaks in the region and extra newlines at the end, | |
262 indents and fills lines between the margins given by the | |
263 `current-left-margin' and `current-fill-column' functions. | |
264 It leaves point at the beginning of the line following the paragraph. | |
265 | |
266 Normally performs justification according to the `current-justification' | |
267 function, but with a prefix arg, does full justification instead. | |
268 | |
269 From a program, optional third arg JUSTIFY can specify any type of | |
270 justification. Fourth arg NOSQUEEZE non-nil means not to make spaces | |
271 between words canonical before filling. Fifth arg SQUEEZE-AFTER, if non-nil, | |
272 means don't canonicalize spaces before that position. | |
273 | |
274 If `sentence-end-double-space' is non-nil, then period followed by one | |
275 space does not end a sentence, so don't break a line there." | |
276 (interactive | |
277 (progn | |
278 ;; XEmacs addition: | |
279 (barf-if-buffer-read-only nil (region-beginning) (region-end)) | |
280 (list (region-beginning) (region-end) | |
281 (if current-prefix-arg 'full)))) | |
282 ;; Arrange for undoing the fill to restore point. | |
283 (if (and buffer-undo-list (not (eq buffer-undo-list t))) | |
284 (setq buffer-undo-list (cons (point) buffer-undo-list))) | |
285 | |
286 ;; Make sure "to" is the endpoint. | |
287 (goto-char (min from to)) | |
288 (setq to (max from to)) | |
289 ;; Ignore blank lines at beginning of region. | |
290 (skip-chars-forward " \t\n") | |
291 | |
292 (let ((from-plus-indent (point)) | |
293 (oneleft nil)) | |
294 | |
295 (beginning-of-line) | |
296 (setq from (point)) | |
444 | 297 |
428 | 298 ;; Delete all but one soft newline at end of region. |
299 ;; And leave TO before that one. | |
300 (goto-char to) | |
301 (while (and (> (point) from) (eq ?\n (char-after (1- (point))))) | |
302 (if (and oneleft | |
303 (not (and use-hard-newlines | |
304 (get-text-property (1- (point)) 'hard)))) | |
305 (delete-backward-char 1) | |
306 (backward-char 1) | |
307 (setq oneleft t))) | |
308 (setq to (point)) | |
309 | |
310 ;; If there was no newline, and there is text in the paragraph, then | |
311 ;; create a newline. | |
312 (if (and (not oneleft) (> to from-plus-indent)) | |
313 (newline)) | |
314 (goto-char from-plus-indent)) | |
315 | |
316 (if (not (> to (point))) | |
317 nil ; There is no paragraph, only whitespace: exit now. | |
318 | |
319 (or justify (setq justify (current-justification))) | |
320 | |
321 ;; Don't let Adaptive Fill mode alter the fill prefix permanently. | |
322 (let ((fill-prefix fill-prefix)) | |
323 ;; Figure out how this paragraph is indented, if desired. | |
324 ;; XEmacs: move some code here to a separate function. | |
325 (maybe-adapt-fill-prefix from to t) | |
326 | |
327 (save-restriction | |
328 (goto-char from) | |
329 (beginning-of-line) | |
330 (narrow-to-region (point) to) | |
331 | |
332 (if (not justify) ; filling disabled: just check indentation | |
333 (progn | |
334 (goto-char from) | |
335 (while (not (eobp)) | |
336 (if (and (not (eolp)) | |
337 (< (current-indentation) (current-left-margin))) | |
338 (indent-to-left-margin)) | |
339 (forward-line 1))) | |
340 | |
341 (if use-hard-newlines | |
342 (remove-text-properties from (point-max) '(hard nil))) | |
343 ;; Make sure first line is indented (at least) to left margin... | |
344 (if (or (memq justify '(right center)) | |
345 (< (current-indentation) (current-left-margin))) | |
346 (indent-to-left-margin)) | |
347 ;; Delete the fill prefix from every line except the first. | |
348 ;; The first line may not even have a fill prefix. | |
349 (goto-char from) | |
350 (let ((fpre (and fill-prefix (not (equal fill-prefix "")) | |
351 (concat "[ \t]*" | |
352 (regexp-quote fill-prefix) | |
353 "[ \t]*")))) | |
354 (and fpre | |
355 (progn | |
356 (if (>= (+ (current-left-margin) (length fill-prefix)) | |
357 (current-fill-column)) | |
358 (error "fill-prefix too long for specified width")) | |
359 (goto-char from) | |
360 (forward-line 1) | |
361 (while (not (eobp)) | |
362 (if (looking-at fpre) | |
363 (delete-region (point) (match-end 0))) | |
364 (forward-line 1)) | |
365 (goto-char from) | |
366 (if (looking-at fpre) | |
367 (goto-char (match-end 0))) | |
368 (setq from (point))))) | |
369 ;; Remove indentation from lines other than the first. | |
370 (beginning-of-line 2) | |
371 (indent-region (point) (point-max) 0) | |
372 (goto-char from) | |
373 | |
374 ;; FROM, and point, are now before the text to fill, | |
375 ;; but after any fill prefix on the first line. | |
376 | |
377 ;; Make sure sentences ending at end of line get an extra space. | |
378 ;; loses on split abbrevs ("Mr.\nSmith") | |
379 (while (re-search-forward "[.?!][])}\"']*$" nil t) | |
2510 | 380 (or (eobp) (insert-and-inherit ?\ ?\ ))) |
428 | 381 (goto-char from) |
382 (skip-chars-forward " \t") | |
383 ;; Then change all newlines to spaces. | |
384 ;;; 97/3/14 jhod: Kinsoku change | |
440 | 385 ;; Spacing is not necessary for characters of no word-separator. |
428 | 386 ;; The regexp word-across-newline is used for this check. |
387 (defvar word-across-newline) | |
388 (if (not (and (featurep 'mule) | |
389 (stringp word-across-newline))) | |
390 (subst-char-in-region from (point-max) ?\n ?\ ) | |
391 ;; | |
392 ;; WAN +NL+WAN --> WAN + WAN | |
393 ;; not(WAN)+NL+WAN --> not(WAN) + WAN | |
394 ;; WAN +NL+not(WAN) --> WAN + not(WAN) | |
395 ;; SPC +NL+not(WAN) --> SPC + not(WAN) | |
396 ;; not(WAN)+NL+not(WAN) --> not(WAN) + SPC + not(WAN) | |
397 ;; | |
398 (goto-char from) | |
399 (end-of-line) | |
400 (while (not (eobp)) | |
401 ;; Insert SPC only when point is between nonWAN. Insert | |
402 ;; before deleting to preserve marker if possible. | |
403 (if (or (prog2 ; check following char. | |
404 (forward-char) ; skip newline | |
405 (or (eobp) | |
406 (looking-at word-across-newline)) | |
407 (forward-char -1)) | |
408 (prog2 ; check previous char. | |
409 (forward-char -1) | |
410 (or (eq (char-after (point)) ?\ ) | |
411 (looking-at word-across-newline)) | |
412 (forward-char))) | |
413 nil | |
414 (insert ?\ )) | |
415 (delete-char 1) ; delete newline | |
416 (end-of-line))) | |
417 ;; end patch | |
418 (goto-char from) | |
419 (skip-chars-forward " \t") | |
420 (if (and nosqueeze (not (eq justify 'full))) | |
421 nil | |
422 (canonically-space-region (or squeeze-after (point)) (point-max)) | |
423 (goto-char (point-max)) | |
424 (delete-horizontal-space) | |
2510 | 425 (insert-and-inherit " ")) |
428 | 426 (goto-char (point-min)) |
427 | |
428 ;; This is the actual filling loop. | |
429 (let ((prefixcol 0) linebeg | |
430 (re-break-point (if (featurep 'mule) | |
431 (concat "[ \n\t]\\|" word-across-newline | |
432 ".\\|." word-across-newline) | |
433 "[ \n\t]"))) | |
434 (while (not (eobp)) | |
435 (setq linebeg (point)) | |
436 (move-to-column (1+ (current-fill-column))) | |
437 (if (eobp) | |
438 (or nosqueeze (delete-horizontal-space)) | |
439 ;; Move back to start of word. | |
440 ;; 97/3/14 jhod: Kinsoku | |
441 ;(skip-chars-backward "^ \n" linebeg) | |
442 (fill-move-backward-to-break-point re-break-point linebeg) | |
443 ;; end patch | |
444 ;; Don't break after a period followed by just one space. | |
445 ;; Move back to the previous place to break. | |
446 ;; The reason is that if a period ends up at the end of a line, | |
447 ;; further fills will assume it ends a sentence. | |
448 ;; If we now know it does not end a sentence, | |
449 ;; avoid putting it at the end of the line. | |
450 (if sentence-end-double-space | |
451 (while (and (> (point) (+ linebeg 2)) | |
452 (eq (char-before (point)) ?\ ) | |
453 (not (eq (char-after (point)) ?\ )) | |
454 (eq (char-after (- (point) 2)) ?\.)) | |
455 (forward-char -2) | |
456 ;; 97/3/14 jhod: Kinsoku | |
457 ;(skip-chars-backward "^ \n" linebeg))) | |
458 (fill-move-backward-to-break-point re-break-point linebeg))) | |
502 | 459 (if (featurep 'mule) (declare-fboundp (kinsoku-process))) |
428 | 460 ;end patch |
461 | |
462 ;; If the left margin and fill prefix by themselves | |
463 ;; pass the fill-column. or if they are zero | |
464 ;; but we have no room for even one word, | |
465 ;; keep at least one word anyway. | |
466 ;; This handles ALL BUT the first line of the paragraph. | |
467 (if (if (zerop prefixcol) | |
468 (save-excursion | |
469 (skip-chars-backward " \t" linebeg) | |
470 (bolp)) | |
471 (>= prefixcol (current-column))) | |
472 ;; Ok, skip at least one word. | |
473 ;; Meanwhile, don't stop at a period followed by one space. | |
474 (let ((first t)) | |
475 (move-to-column prefixcol) | |
476 (while (and (not (eobp)) | |
477 (or first | |
478 (and (not (bobp)) | |
479 sentence-end-double-space | |
480 (save-excursion (forward-char -1) | |
481 (and (looking-at "\\. ") | |
482 (not (looking-at "\\. "))))))) | |
483 (skip-chars-forward " \t") | |
484 ;; 94/3/14 jhod: Kinsoku | |
485 ;(skip-chars-forward "^ \n\t") | |
486 (fill-move-forward-to-break-point re-break-point) | |
487 ;; end patch | |
488 (setq first nil))) | |
489 ;; Normally, move back over the single space between the words. | |
490 (if (eq (char-before (point)) ?\ ) | |
491 (forward-char -1))) | |
492 ;; If the left margin and fill prefix by themselves | |
493 ;; pass the fill-column, keep at least one word. | |
494 ;; This handles the first line of the paragraph. | |
495 (if (and (zerop prefixcol) | |
496 (let ((fill-point (point)) nchars) | |
497 (save-excursion | |
498 (move-to-left-margin) | |
499 (setq nchars (- fill-point (point))) | |
500 (or (< nchars 0) | |
501 (and fill-prefix | |
502 (< nchars (length fill-prefix)) | |
503 (string= (buffer-substring (point) fill-point) | |
504 (substring fill-prefix 0 nchars))))))) | |
505 ;; Ok, skip at least one word. But | |
506 ;; don't stop at a period followed by just one space. | |
507 (let ((first t)) | |
508 (while (and (not (eobp)) | |
509 (or first | |
510 (and (not (bobp)) | |
511 sentence-end-double-space | |
512 (save-excursion (forward-char -1) | |
513 (and (looking-at "\\. ") | |
514 (not (looking-at "\\. "))))))) | |
515 (skip-chars-forward " \t") | |
516 ;; 97/3/14 jhod: Kinsoku | |
517 ;(skip-chars-forward "^ \t\n") | |
518 (fill-move-forward-to-break-point re-break-point) | |
519 ;; end patch | |
520 (setq first nil)))) | |
521 ;; Check again to see if we got to the end of the paragraph. | |
522 (if (save-excursion (skip-chars-forward " \t") (eobp)) | |
523 (or nosqueeze (delete-horizontal-space)) | |
524 ;; Replace whitespace here with one newline, then indent to left | |
525 ;; margin. | |
526 (skip-chars-backward " \t") | |
527 ;; 97/3/14 jhod: More kinsoku stuff | |
528 (if (featurep 'mule) | |
529 ;; WAN means chars which match word-across-newline. | |
530 ;; (0) | SPC + SPC* <EOB> --> NL | |
531 ;; (1) WAN | SPC + SPC* --> WAN + SPC + NL | |
532 ;; (2) | SPC + SPC* + WAN --> SPC + NL + WAN | |
533 ;; (3) '.' | SPC + nonSPC --> '.' + SPC + NL + nonSPC | |
534 ;; (4) '.' | SPC + SPC --> '.' + NL | |
535 ;; (5) | SPC* --> NL | |
536 (let ((start (point)) ; 92.6.30 by K.Handa | |
537 (ch (char-after (point)))) | |
538 (if (and (= ch ? ) | |
539 (progn ; not case (0) -- 92.6.30 by K.Handa | |
540 (skip-chars-forward " \t") | |
541 (not (eobp))) | |
542 (or | |
543 (progn ; case (1) | |
544 (goto-char start) | |
545 (forward-char -1) | |
546 (looking-at word-across-newline)) | |
547 (progn ; case (2) | |
548 (goto-char start) | |
549 (skip-chars-forward " \t") | |
550 (and (not (eobp)) | |
551 (looking-at word-across-newline) | |
552 ;; never leave space after the end of sentence | |
553 (not (fill-end-of-sentence-p)))) | |
554 (progn ; case (3) | |
555 (goto-char (1+ start)) | |
556 (and (not (eobp)) | |
557 (not (eq (char-after (point)) ? )) | |
558 (fill-end-of-sentence-p))))) | |
559 ;; We should keep one SPACE before NEWLINE. (1),(2),(3) | |
560 (goto-char (1+ start)) | |
561 ;; We should delete all SPACES around break point. (4),(5) | |
562 (goto-char start)))) | |
563 ;; end of patch | |
564 (insert ?\n) | |
565 ;; Give newline the properties of the space(s) it replaces | |
566 (set-text-properties (1- (point)) (point) | |
567 (text-properties-at (point))) | |
568 (indent-to-left-margin) | |
569 ;; Insert the fill prefix after indentation. | |
570 ;; Set prefixcol so whitespace in the prefix won't get lost. | |
571 (and fill-prefix (not (equal fill-prefix "")) | |
572 (progn | |
2510 | 573 (insert-and-inherit fill-prefix) |
428 | 574 (setq prefixcol (current-column)))))) |
575 ;; Justify the line just ended, if desired. | |
576 (if justify | |
577 (if (save-excursion (skip-chars-forward " \t") (eobp)) | |
578 (progn | |
579 (delete-horizontal-space) | |
580 (justify-current-line justify t t)) | |
581 (forward-line -1) | |
582 (justify-current-line justify nil t) | |
583 (forward-line 1)))))) | |
584 ;; Leave point after final newline. | |
585 (goto-char (point-max))) | |
586 (forward-char 1)))) | |
587 | |
588 (defun fill-paragraph (arg) | |
589 "Fill paragraph at or after point. Prefix arg means justify as well. | |
590 If `sentence-end-double-space' is non-nil, then period followed by one | |
591 space does not end a sentence, so don't break a line there. | |
592 | |
593 If `fill-paragraph-function' is non-nil, we call it (passing our | |
594 argument to it), and if it returns non-nil, we simply return its value." | |
595 (interactive (list (if current-prefix-arg 'full))) | |
596 (or (and fill-paragraph-function | |
597 (let ((function fill-paragraph-function) | |
598 fill-paragraph-function) | |
599 (funcall function arg))) | |
600 (let ((before (point))) | |
601 (save-excursion | |
602 (forward-paragraph) | |
603 (or (bolp) (newline 1)) | |
604 (let ((end (point)) | |
444 | 605 (start (progn (backward-paragraph) (point)))) |
428 | 606 (goto-char before) |
607 (if use-hard-newlines | |
608 ;; Can't use fill-region-as-paragraph, since this paragraph may | |
609 ;; still contain hard newlines. See fill-region. | |
444 | 610 (fill-region start end arg) |
611 (fill-region-as-paragraph start end arg))))))) | |
428 | 612 |
613 (defun fill-region (from to &optional justify nosqueeze to-eop) | |
614 "Fill each of the paragraphs in the region. | |
615 Prefix arg (non-nil third arg, if called from program) means justify as well. | |
616 | |
617 Noninteractively, fourth arg NOSQUEEZE non-nil means to leave | |
618 whitespace other than line breaks untouched, and fifth arg TO-EOP | |
619 non-nil means to keep filling to the end of the paragraph (or next | |
620 hard newline, if `use-hard-newlines' is on). | |
621 | |
622 If `sentence-end-double-space' is non-nil, then period followed by one | |
623 space does not end a sentence, so don't break a line there." | |
624 (interactive | |
625 (progn | |
626 ;; XEmacs addition: | |
627 (barf-if-buffer-read-only nil (region-beginning) (region-end)) | |
628 (list (region-beginning) (region-end) | |
629 (if current-prefix-arg 'full)))) | |
444 | 630 (let (end start) |
428 | 631 (save-restriction |
632 (goto-char (max from to)) | |
633 (if to-eop | |
634 (progn (skip-chars-backward "\n") | |
635 (forward-paragraph))) | |
636 (setq end (point)) | |
444 | 637 (goto-char (setq start (min from to))) |
428 | 638 (beginning-of-line) |
639 (narrow-to-region (point) end) | |
640 (while (not (eobp)) | |
641 (let ((initial (point)) | |
642 end) | |
643 ;; If using hard newlines, break at every one for filling | |
444 | 644 ;; purposes rather than using paragraph breaks. |
428 | 645 (if use-hard-newlines |
444 | 646 (progn |
428 | 647 (while (and (setq end (text-property-any (point) (point-max) |
648 'hard t)) | |
649 (not (eq ?\n (char-after end))) | |
650 (not (= end (point-max)))) | |
651 (goto-char (1+ end))) | |
652 (setq end (if end (min (point-max) (1+ end)) (point-max))) | |
653 (goto-char initial)) | |
654 (forward-paragraph 1) | |
655 (setq end (point)) | |
656 (forward-paragraph -1)) | |
444 | 657 (if (< (point) start) |
658 (goto-char start)) | |
428 | 659 (if (>= (point) initial) |
660 (fill-region-as-paragraph (point) end justify nosqueeze) | |
661 (goto-char end))))))) | |
662 | |
663 (defun fill-paragraph-or-region (arg) | |
664 "Fill the current region, if it's active; otherwise, fill the paragraph. | |
665 See `fill-paragraph' and `fill-region' for more information." | |
666 (interactive "*P") | |
667 (if (region-active-p) | |
502 | 668 (call-interactively 'fill-region) |
669 (call-interactively 'fill-paragraph))) | |
428 | 670 |
444 | 671 |
428 | 672 (defconst default-justification 'left |
673 "*Method of justifying text not otherwise specified. | |
674 Possible values are `left', `right', `full', `center', or `none'. | |
675 The requested kind of justification is done whenever lines are filled. | |
676 The `justification' text-property can locally override this variable. | |
677 This variable automatically becomes buffer-local when set in any fashion.") | |
678 (make-variable-buffer-local 'default-justification) | |
679 | |
680 (defun current-justification () | |
681 "How should we justify this line? | |
682 This returns the value of the text-property `justification', | |
683 or the variable `default-justification' if there is no text-property. | |
684 However, it returns nil rather than `none' to mean \"don't justify\"." | |
444 | 685 (let ((j (or (get-text-property |
428 | 686 ;; Make sure we're looking at paragraph body. |
444 | 687 (save-excursion (skip-chars-forward " \t") |
428 | 688 (if (and (eobp) (not (bobp))) |
689 (1- (point)) (point))) | |
690 'justification) | |
691 default-justification))) | |
692 (if (eq 'none j) | |
693 nil | |
694 j))) | |
695 | |
696 (defun set-justification (begin end value &optional whole-par) | |
697 "Set the region's justification style. | |
698 The kind of justification to use is prompted for. | |
699 If the mark is not active, this command operates on the current paragraph. | |
700 If the mark is active, the region is used. However, if the beginning and end | |
701 of the region are not at paragraph breaks, they are moved to the beginning and | |
702 end of the paragraphs they are in. | |
703 If `use-hard-newlines' is true, all hard newlines are taken to be paragraph | |
704 breaks. | |
705 | |
706 When calling from a program, operates just on region between BEGIN and END, | |
707 unless optional fourth arg WHOLE-PAR is non-nil. In that case bounds are | |
708 extended to include entire paragraphs as in the interactive command." | |
709 ;; XEmacs change (was mark-active) | |
710 (interactive (list (if (region-active-p) (region-beginning) (point)) | |
711 (if (region-active-p) (region-end) (point)) | |
712 (let ((s (completing-read | |
713 "Set justification to: " | |
714 '(("left") ("right") ("full") | |
715 ("center") ("none")) | |
716 nil t))) | |
717 (if (equal s "") (error "")) | |
718 (intern s)) | |
719 t)) | |
720 (save-excursion | |
721 (save-restriction | |
722 (if whole-par | |
723 (let ((paragraph-start (if use-hard-newlines "." paragraph-start)) | |
444 | 724 (paragraph-ignore-fill-prefix (if use-hard-newlines t |
428 | 725 paragraph-ignore-fill-prefix))) |
726 (goto-char begin) | |
727 (while (and (bolp) (not (eobp))) (forward-char 1)) | |
728 (backward-paragraph) | |
729 (setq begin (point)) | |
730 (goto-char end) | |
731 (skip-chars-backward " \t\n" begin) | |
732 (forward-paragraph) | |
733 (setq end (point)))) | |
734 | |
735 (narrow-to-region (point-min) end) | |
736 (unjustify-region begin (point-max)) | |
737 (put-text-property begin (point-max) 'justification value) | |
738 (fill-region begin (point-max) nil t)))) | |
739 | |
740 (defun set-justification-none (b e) | |
741 "Disable automatic filling for paragraphs in the region. | |
742 If the mark is not active, this applies to the current paragraph." | |
743 ;; XEmacs change (was mark-active) | |
744 (interactive (list (if (region-active-p) (region-beginning) (point)) | |
745 (if (region-active-p) (region-end) (point)))) | |
746 (set-justification b e 'none t)) | |
747 | |
748 (defun set-justification-left (b e) | |
749 "Make paragraphs in the region left-justified. | |
750 This is usually the default, but see the variable `default-justification'. | |
751 If the mark is not active, this applies to the current paragraph." | |
752 ;; XEmacs change (was mark-active) | |
753 (interactive (list (if (region-active-p) (region-beginning) (point)) | |
754 (if (region-active-p) (region-end) (point)))) | |
755 (set-justification b e 'left t)) | |
756 | |
757 (defun set-justification-right (b e) | |
758 "Make paragraphs in the region right-justified: | |
759 Flush at the right margin and ragged on the left. | |
760 If the mark is not active, this applies to the current paragraph." | |
761 ;; XEmacs change (was mark-active) | |
762 (interactive (list (if (region-active-p) (region-beginning) (point)) | |
763 (if (region-active-p) (region-end) (point)))) | |
764 (set-justification b e 'right t)) | |
765 | |
766 (defun set-justification-full (b e) | |
767 "Make paragraphs in the region fully justified: | |
768 This makes lines flush on both margins by inserting spaces between words. | |
769 If the mark is not active, this applies to the current paragraph." | |
770 ;; XEmacs change (was mark-active) | |
771 (interactive (list (if (region-active-p) (region-beginning) (point)) | |
772 (if (region-active-p) (region-end) (point)))) | |
773 (set-justification b e 'full t)) | |
774 | |
775 (defun set-justification-center (b e) | |
776 "Make paragraphs in the region centered. | |
777 If the mark is not active, this applies to the current paragraph." | |
778 ;; XEmacs change (was mark-active) | |
779 (interactive (list (if (region-active-p) (region-beginning) (point)) | |
780 (if (region-active-p) (region-end) (point)))) | |
781 (set-justification b e 'center t)) | |
782 | |
783 ;; 97/3/14 jhod: This functions are added for Kinsoku support | |
784 (defun find-space-insertable-point () | |
444 | 785 "Search backward for a permissible point for inserting justification spaces." |
776 | 786 (if-boundp 'space-insertable |
787 (if (re-search-backward space-insertable nil t) | |
428 | 788 (progn (forward-char 1) |
789 t) | |
790 nil) | |
791 (search-backward " " nil t))) | |
792 | |
793 ;; A line has up to six parts: | |
794 ;; | |
444 | 795 ;; >>> hello. |
428 | 796 ;; [Indent-1][FP][ Indent-2 ][text][trailing whitespace][newline] |
797 ;; | |
798 ;; "Indent-1" is the left-margin indentation; normally it ends at column | |
799 ;; given by the `current-left-margin' function. | |
800 ;; "FP" is the fill-prefix. It can be any string, including whitespace. | |
801 ;; "Indent-2" is added to justify a line if the `current-justification' is | |
802 ;; `center' or `right'. In `left' and `full' justification regions, any | |
803 ;; whitespace there is part of the line's text, and should not be changed. | |
804 ;; Trailing whitespace is not counted as part of the line length when | |
805 ;; center- or right-justifying. | |
806 ;; | |
444 | 807 ;; All parts of the line are optional, although the final newline can |
428 | 808 ;; only be missing on the last line of the buffer. |
809 | |
810 (defun justify-current-line (&optional how eop nosqueeze) | |
811 "Do some kind of justification on this line. | |
812 Normally does full justification: adds spaces to the line to make it end at | |
813 the column given by `current-fill-column'. | |
814 Optional first argument HOW specifies alternate type of justification: | |
444 | 815 it can be `left', `right', `full', `center', or `none'. |
428 | 816 If HOW is t, will justify however the `current-justification' function says to. |
817 If HOW is nil or missing, full justification is done by default. | |
818 Second arg EOP non-nil means that this is the last line of the paragraph, so | |
819 it will not be stretched by full justification. | |
820 Third arg NOSQUEEZE non-nil means to leave interior whitespace unchanged, | |
821 otherwise it is made canonical." | |
822 (interactive) | |
823 (if (eq t how) (setq how (or (current-justification) 'none)) | |
824 (if (null how) (setq how 'full) | |
825 (or (memq how '(none left right center)) | |
826 (setq how 'full)))) | |
827 (or (memq how '(none left)) ; No action required for these. | |
828 (let ((fc (current-fill-column)) | |
829 (pos (point-marker)) | |
830 fp-end ; point at end of fill prefix | |
444 | 831 start ; point at beginning of line's text |
428 | 832 end ; point at end of line's text |
444 | 833 indent ; column of `start' |
428 | 834 endcol ; column of `end' |
835 ncols) ; new indent point or offset | |
836 (end-of-line) | |
837 ;; Check if this is the last line of the paragraph. | |
444 | 838 (if (and use-hard-newlines (null eop) |
428 | 839 (get-text-property (point) 'hard)) |
840 (setq eop t)) | |
841 (skip-chars-backward " \t") | |
842 ;; Quick exit if it appears to be properly justified already | |
843 ;; or there is no text. | |
844 (if (or (bolp) | |
845 (and (memq how '(full right)) | |
846 (= (current-column) fc))) | |
847 nil | |
848 (setq end (point)) | |
849 (beginning-of-line) | |
850 (skip-chars-forward " \t") | |
851 ;; Skip over fill-prefix. | |
444 | 852 (if (and fill-prefix |
428 | 853 (not (string-equal fill-prefix "")) |
854 (equal fill-prefix | |
444 | 855 (buffer-substring |
428 | 856 (point) (min (point-max) (+ (length fill-prefix) |
857 (point)))))) | |
858 (forward-char (length fill-prefix)) | |
444 | 859 (if (and adaptive-fill-mode |
428 | 860 (looking-at adaptive-fill-regexp)) |
861 (goto-char (match-end 0)))) | |
862 (setq fp-end (point)) | |
863 (skip-chars-forward " \t") | |
864 ;; This is beginning of the line's text. | |
865 (setq indent (current-column)) | |
444 | 866 (setq start (point)) |
428 | 867 (goto-char end) |
868 (setq endcol (current-column)) | |
869 | |
870 ;; HOW can't be null or left--we would have exited already | |
444 | 871 (cond ((eq 'right how) |
428 | 872 (setq ncols (- fc endcol)) |
873 (if (< ncols 0) | |
874 ;; Need to remove some indentation | |
444 | 875 (delete-region |
428 | 876 (progn (goto-char fp-end) |
877 (if (< (current-column) (+ indent ncols)) | |
878 (move-to-column (+ indent ncols) t)) | |
879 (point)) | |
880 (progn (move-to-column indent) (point))) | |
881 ;; Need to add some | |
444 | 882 (goto-char start) |
428 | 883 (indent-to (+ indent ncols)) |
884 ;; If point was at beginning of text, keep it there. | |
444 | 885 (if (= start pos) |
428 | 886 (move-marker pos (point))))) |
887 | |
888 ((eq 'center how) | |
889 ;; Figure out how much indentation is needed | |
890 (setq ncols (+ (current-left-margin) | |
891 (/ (- fc (current-left-margin) ;avail. space | |
892 (- endcol indent)) ;text width | |
893 2))) | |
894 (if (< ncols indent) | |
895 ;; Have too much indentation - remove some | |
896 (delete-region | |
897 (progn (goto-char fp-end) | |
898 (if (< (current-column) ncols) | |
899 (move-to-column ncols t)) | |
900 (point)) | |
901 (progn (move-to-column indent) (point))) | |
902 ;; Have too little - add some | |
444 | 903 (goto-char start) |
428 | 904 (indent-to ncols) |
905 ;; If point was at beginning of text, keep it there. | |
444 | 906 (if (= start pos) |
428 | 907 (move-marker pos (point))))) |
908 | |
909 ((eq 'full how) | |
910 ;; Insert extra spaces between words to justify line | |
911 (save-restriction | |
444 | 912 (narrow-to-region start end) |
428 | 913 (or nosqueeze |
444 | 914 (canonically-space-region start end)) |
428 | 915 (goto-char (point-max)) |
916 (setq ncols (- fc endcol)) | |
917 ;; Ncols is number of additional spaces needed | |
918 (if (> ncols 0) | |
919 (if (and (not eop) | |
920 ;; 97/3/14 jhod: Kinsoku | |
921 (find-space-insertable-point)) ;(search-backward " " nil t)) | |
922 (while (> ncols 0) | |
923 (let ((nmove (+ 3 (random 3)))) | |
924 (while (> nmove 0) | |
925 (or (find-space-insertable-point) ;(search-backward " " nil t) | |
926 (progn | |
927 (goto-char (point-max)) | |
928 (find-space-insertable-point))) ;(search-backward " "))) | |
929 (skip-chars-backward " ") | |
930 (setq nmove (1- nmove)))) | |
2510 | 931 (insert-and-inherit " ") |
428 | 932 (skip-chars-backward " ") |
933 (setq ncols (1- ncols))))))) | |
934 (t (error "Unknown justification value")))) | |
935 (goto-char pos) | |
936 (move-marker pos nil))) | |
937 nil) | |
938 | |
939 (defun unjustify-current-line () | |
940 "Remove justification whitespace from current line. | |
941 If the line is centered or right-justified, this function removes any | |
942 indentation past the left margin. If the line is full-justified, it removes | |
943 extra spaces between words. It does nothing in other justification modes." | |
944 (let ((justify (current-justification))) | |
945 (cond ((eq 'left justify) nil) | |
946 ((eq nil justify) nil) | |
947 ((eq 'full justify) ; full justify: remove extra spaces | |
948 (beginning-of-line-text) | |
949 (canonically-space-region | |
950 (point) (save-excursion (end-of-line) (point)))) | |
951 ((memq justify '(center right)) | |
952 (save-excursion | |
953 (move-to-left-margin nil t) | |
954 ;; Position ourselves after any fill-prefix. | |
444 | 955 (if (and fill-prefix |
428 | 956 (not (string-equal fill-prefix "")) |
957 (equal fill-prefix | |
444 | 958 (buffer-substring |
428 | 959 (point) (min (point-max) (+ (length fill-prefix) |
960 (point)))))) | |
961 (forward-char (length fill-prefix))) | |
962 (delete-region (point) (progn (skip-chars-forward " \t") | |
963 (point)))))))) | |
964 | |
965 (defun unjustify-region (&optional begin end) | |
966 "Remove justification whitespace from region. | |
967 For centered or right-justified regions, this function removes any indentation | |
444 | 968 past the left margin from each line. For full-justified lines, it removes |
428 | 969 extra spaces between words. It does nothing in other justification modes. |
970 Arguments BEGIN and END are optional; default is the whole buffer." | |
971 (save-excursion | |
972 (save-restriction | |
973 (if end (narrow-to-region (point-min) end)) | |
974 (goto-char (or begin (point-min))) | |
975 (while (not (eobp)) | |
976 (unjustify-current-line) | |
977 (forward-line 1))))) | |
978 | |
979 | |
980 (defun fill-nonuniform-paragraphs (min max &optional justifyp mailp) | |
981 "Fill paragraphs within the region, allowing varying indentation within each. | |
982 This command divides the region into \"paragraphs\", | |
983 only at paragraph-separator lines, then fills each paragraph | |
984 using as the fill prefix the smallest indentation of any line | |
985 in the paragraph. | |
986 | |
987 When calling from a program, pass range to fill as first two arguments. | |
988 | |
989 Optional third and fourth arguments JUSTIFY and MAIL-FLAG: | |
990 JUSTIFY to justify paragraphs (prefix arg), | |
991 MAIL-FLAG for a mail message, i. e. don't fill header lines." | |
992 (interactive (list (region-beginning) (region-end) | |
993 (if current-prefix-arg 'full))) | |
994 (let ((fill-individual-varying-indent t)) | |
995 (fill-individual-paragraphs min max justifyp mailp))) | |
996 | |
997 (defun fill-individual-paragraphs (min max &optional justify mailp) | |
998 "Fill paragraphs of uniform indentation within the region. | |
999 This command divides the region into \"paragraphs\", | |
1000 treating every change in indentation level as a paragraph boundary, | |
1001 then fills each paragraph using its indentation level as the fill prefix. | |
1002 | |
1003 When calling from a program, pass range to fill as first two arguments. | |
1004 | |
1005 Optional third and fourth arguments JUSTIFY and MAIL-FLAG: | |
1006 JUSTIFY to justify paragraphs (prefix arg), | |
1007 MAIL-FLAG for a mail message, i. e. don't fill header lines." | |
1008 (interactive (list (region-beginning) (region-end) | |
1009 (if current-prefix-arg 'full))) | |
1010 (save-restriction | |
1011 (save-excursion | |
1012 (goto-char min) | |
1013 (beginning-of-line) | |
1014 (narrow-to-region (point) max) | |
444 | 1015 (if mailp |
428 | 1016 (while (and (not (eobp)) |
1017 (or (looking-at "[ \t]*[^ \t\n]+:") | |
1018 (looking-at "[ \t]*$"))) | |
1019 (if (looking-at "[ \t]*[^ \t\n]+:") | |
1020 (search-forward "\n\n" nil 'move) | |
1021 (forward-line 1)))) | |
1022 (narrow-to-region (point) max) | |
1023 ;; Loop over paragraphs. | |
1024 (while (progn (skip-chars-forward " \t\n") (not (eobp))) | |
1025 (move-to-left-margin) | |
1026 (let ((start (point)) | |
1027 fill-prefix fill-prefix-regexp) | |
1028 ;; Find end of paragraph, and compute the smallest fill-prefix | |
1029 ;; that fits all the lines in this paragraph. | |
1030 (while (progn | |
1031 ;; Update the fill-prefix on the first line | |
1032 ;; and whenever the prefix good so far is too long. | |
1033 (if (not (and fill-prefix | |
1034 (looking-at fill-prefix-regexp))) | |
1035 (setq fill-prefix | |
1036 (if (and adaptive-fill-mode adaptive-fill-regexp | |
1037 (looking-at adaptive-fill-regexp)) | |
1038 (match-string 0) | |
444 | 1039 (buffer-substring |
428 | 1040 (point) |
1041 (save-excursion (skip-chars-forward " \t") | |
1042 (point)))) | |
1043 fill-prefix-regexp (regexp-quote fill-prefix))) | |
1044 (forward-line 1) | |
1045 (if (bolp) | |
2510 | 1046 ;; If forward-line went past a newline, |
428 | 1047 ;; move further to the left margin. |
1048 (move-to-left-margin)) | |
1049 ;; Now stop the loop if end of paragraph. | |
1050 (and (not (eobp)) | |
1051 (if fill-individual-varying-indent | |
1052 ;; If this line is a separator line, with or | |
1053 ;; without prefix, end the paragraph. | |
444 | 1054 (and |
428 | 1055 (not (looking-at paragraph-separate)) |
1056 (save-excursion | |
1057 (not (and (looking-at fill-prefix-regexp) | |
1058 ;; XEmacs change | |
1059 (progn | |
1060 (forward-char (length fill-prefix)) | |
1061 (looking-at paragraph-separate)))))) | |
1062 ;; If this line has more or less indent | |
1063 ;; than the fill prefix wants, end the paragraph. | |
1064 (and (looking-at fill-prefix-regexp) | |
1065 (save-excursion | |
1066 (not | |
1067 (progn | |
1068 (forward-char (length fill-prefix)) | |
1069 (or (looking-at paragraph-separate) | |
1070 (looking-at paragraph-start)))))))))) | |
1071 ;; Fill this paragraph, but don't add a newline at the end. | |
1072 (let ((had-newline (bolp))) | |
1073 (fill-region-as-paragraph start (point) justify) | |
1074 (or had-newline (delete-char -1)))))))) | |
1075 | |
1076 ;;; fill.el ends here |