comparison lisp/prim/fill.el @ 2:ac2d302a0011 r19-15b2

Import from CVS: tag r19-15b2
author cvs
date Mon, 13 Aug 2007 08:46:35 +0200
parents 376386a54a3c
children b82b59fe008d
comparison
equal deleted inserted replaced
1:c0c6a60d29db 2:ac2d302a0011
1 ;;; fill.el --- fill commands for XEmacs. 1 ;;; fill.el --- fill commands for XEmacs.
2 2
3 ;; Copyright (C) 1985, 1986, 1992-1995 Free Software Foundation, Inc. 3 ;; Copyright (C) 1985, 86, 92, 94, 95, 1996 Free Software Foundation, Inc.
4 4
5 ;; Keywords: wp 5 ;; Keywords: wp
6 6
7 ;; This file is part of XEmacs. 7 ;; This file is part of XEmacs.
8 8
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 ;; General Public License for more details. 17 ;; General Public License for more details.
18 18
19 ;; You should have received a copy of the GNU General Public License 19 ;; You should have received a copy of the GNU General Public License
20 ;; along with XEmacs; see the file COPYING. If not, write to the Free 20 ;; along with XEmacs; see the file COPYING. If not, write to the Free
21 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 21 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 22 ;; 02111-1307, USA.
23 ;;; Synched up with: FSF 19.30. 23
24 ;;; Synched up with: FSF 19.34.
24 25
25 ;;; Commentary: 26 ;;; Commentary:
26 27
27 ;; All the commands for filling text. These are documented in the XEmacs 28 ;; All the commands for filling text. These are documented in the XEmacs
28 ;; Reference Manual. 29 ;; Reference Manual.
29 30
30 ;;; Code: 31 ;;; Code:
31 32
32 (defvar fill-individual-varying-indent nil 33 (defconst fill-individual-varying-indent nil
33 "*Controls criterion for a new paragraph in `fill-individual-paragraphs'. 34 "*Controls criterion for a new paragraph in `fill-individual-paragraphs'.
34 Non-nil means changing indent doesn't end a paragraph. 35 Non-nil means changing indent doesn't end a paragraph.
35 That mode can handle paragraphs with extra indentation on the first line, 36 That mode can handle paragraphs with extra indentation on the first line,
36 but it requires separator lines between paragraphs. 37 but it requires separator lines between paragraphs.
37 A value of nil means that any change in indentation starts a new paragraph.") 38 A value of nil means that any change in indentation starts a new paragraph.")
38 39
39 (defvar sentence-end-double-space t 40 (defconst sentence-end-double-space t
40 "*Non-nil means a single space does not end a sentence.") 41 "*Non-nil means a single space does not end a sentence.")
41 42
42 (defconst colon-double-space nil 43 (defconst colon-double-space nil
43 "*Non-nil means put two spaces after a colon when filling.") 44 "*Non-nil means put two spaces after a colon when filling.")
44 45
45 (defvar fill-paragraph-function nil 46 (defvar fill-paragraph-function nil
46 "Mode-specific function to fill a paragraph.") 47 "Mode-specific function to fill a paragraph, or nil if there is none.
48 If the function returns nil, then `fill-paragraph' does its normal work.")
47 49
48 (defun set-fill-prefix () 50 (defun set-fill-prefix ()
49 "Set the fill prefix to the current line up to point. 51 "Set the fill prefix to the current line up to point.
50 Filling expects lines to start with the fill prefix 52 Filling expects lines to start with the fill prefix and
51 and reinserts the fill prefix in each resulting line." 53 reinserts the fill prefix in each resulting line."
52 (interactive) 54 (interactive)
53 (setq fill-prefix (buffer-substring 55 (setq fill-prefix (buffer-substring
54 (save-excursion (move-to-left-margin) (point)) 56 (save-excursion (move-to-left-margin) (point))
55 (point))) 57 (point)))
56 (if (equal fill-prefix "") 58 (if (equal fill-prefix "")
57 (setq fill-prefix nil)) 59 (setq fill-prefix nil))
58 (if fill-prefix 60 (if fill-prefix
59 (message "fill-prefix: \"%s\"" fill-prefix) 61 (message "fill-prefix: \"%s\"" fill-prefix)
60 (message "fill-prefix cancelled"))) 62 (message "fill-prefix cancelled")))
61 63
62 (defvar adaptive-fill-mode t 64 (defconst adaptive-fill-mode t
63 "*Non-nil means determine a paragraph's fill prefix from its text.") 65 "*Non-nil means determine a paragraph's fill prefix from its text.")
64 66
65 ;; #### - this is still weak. Yeah, there's filladapt, but this should 67 ;; #### - this is still weak. Yeah, there's filladapt, but this should
66 ;; still be better... --Stig 68 ;; still be better... --Stig
67 (defvar adaptive-fill-regexp (purecopy "[ \t]*\\([#;>*]+ +\\)?") 69 (defconst adaptive-fill-regexp (purecopy "[ \t]*\\([#;>*]+ +\\)?")
68 "*Regexp to match text at start of line that constitutes indentation. 70 "*Regexp to match text at start of line that constitutes indentation.
69 If Adaptive Fill mode is enabled, whatever text matches this pattern 71 If Adaptive Fill mode is enabled, whatever text matches this pattern
70 on the second line of a paragraph is used as the standard indentation 72 on the second line of a paragraph is used as the standard indentation
71 for the paragraph. If the paragraph has just one line, the indentation 73 for the paragraph. If the paragraph has just one line, the indentation
72 is taken from that line.") 74 is taken from that line.")
101 here-col col)) 103 here-col col))
102 (max here-col fill-col))))) 104 (max here-col fill-col)))))
103 105
104 (defun canonically-space-region (beg end) 106 (defun canonically-space-region (beg end)
105 "Remove extra spaces between words in region. 107 "Remove extra spaces between words in region.
106 Puts one space between words in region; two between sentences. 108 Leave one space between words, two at end of sentences or after colons
107 Remove indentation from each line." 109 (depending on values of `sentence-end-double-space' and `colon-double-space').
110 Remove indentation from each line."
108 (interactive "r") 111 (interactive "r")
109 (save-excursion 112 (save-excursion
110 (goto-char beg) 113 (goto-char beg)
111 ;; XEmacs - (ENE/stig from fa-extras.el): Skip the start of a comment. 114 ;; XEmacs - (ENE/stig from fa-extras.el): Skip the start of a comment.
112 (and comment-start-skip 115 (and comment-start-skip
134 ;; Make sure sentences ending at end of line get an extra space. 137 ;; Make sure sentences ending at end of line get an extra space.
135 ;; loses on split abbrevs ("Mr.\nSmith") 138 ;; loses on split abbrevs ("Mr.\nSmith")
136 (goto-char beg) 139 (goto-char beg)
137 (while (and (< (point) end) 140 (while (and (< (point) end)
138 (re-search-forward "[.?!][])}\"']*$" end t)) 141 (re-search-forward "[.?!][])}\"']*$" end t))
142 ;; We insert before markers in case a caller such as
143 ;; do-auto-fill has done a save-excursion with point at the end
144 ;; of the line and wants it to stay at the end of the line.
139 (insert ? )))) 145 (insert ? ))))
146 ;; XEmacs: we don't have this function.
147 ;; (insert-before-markers-and-inherit ? ))))
140 148
141 ;; XEmacs -- added DONT-SKIP-FIRST. Port of older code changes by Stig. 149 ;; XEmacs -- added DONT-SKIP-FIRST. Port of older code changes by Stig.
142 ;; #### probably this junk is broken -- do-auto-fill doesn't actually use 150 ;; #### probably this junk is broken -- do-auto-fill doesn't actually use
143 ;; it. If so, it should be removed. 151 ;; it. If so, it should be removed.
144 (defun fill-context-prefix (from to &optional first-line-regexp 152 (defun fill-context-prefix (from to &optional first-line-regexp
145 dont-skip-first) 153 dont-skip-first)
146 "Compute a fill prefix from the text between FROM and TO. 154 "Compute a fill prefix from the text between FROM and TO.
147 This uses the variables `adapive-fill-prefix' and `adaptive-fill-function'. 155 This uses the variables `adaptive-fill-prefix' and `adaptive-fill-function'.
148 If FIRST-LINE-REGEXP is non-nil, then when taking a prefix from the 156 If FIRST-LINE-REGEXP is non-nil, then when taking a prefix from the
149 first line, insist it must match FIRST-LINE-REGEXP." 157 first line, insist it must match FIRST-LINE-REGEXP."
150 (save-excursion 158 (save-excursion
151 (goto-char from) 159 (goto-char from)
152 (if (eolp) (forward-line 1)) 160 (if (eolp) (forward-line 1))
153 ;; Move to the second line unless there is just one. 161 ;; Move to the second line unless there is just one.
154 (let ((firstline (point)) 162 (let ((firstline (point))
155 ;; Non-nil if we are on the second line. 163 ;; Non-nil if we are on the second line.
156 at-second 164 at-second
157 result) 165 result)
166 ;; XEmacs change
158 (if (not dont-skip-first) 167 (if (not dont-skip-first)
159 (forward-line 1)) 168 (forward-line 1))
160 (if (>= (point) to) 169 (if (>= (point) to)
161 (goto-char firstline) 170 (goto-char firstline)
162 (setq at-second t)) 171 (setq at-second t))
163 (move-to-left-margin) 172 (move-to-left-margin)
173 ;; XEmacs change
164 (let ((start (point)) 174 (let ((start (point))
165 (eol (save-excursion (end-of-line) (point)))) 175 (eol (save-excursion (end-of-line) (point))))
166 (setq result 176 (setq result
167 (if (not (looking-at paragraph-start)) 177 (if (not (looking-at paragraph-start))
168 (cond ((and adaptive-fill-regexp (looking-at adaptive-fill-regexp)) 178 (cond ((and adaptive-fill-regexp (looking-at adaptive-fill-regexp))
180 (defun maybe-adapt-fill-prefix (&optional from to dont-skip-first) 190 (defun maybe-adapt-fill-prefix (&optional from to dont-skip-first)
181 (if (and adaptive-fill-mode 191 (if (and adaptive-fill-mode
182 (or (null fill-prefix) (string= fill-prefix ""))) 192 (or (null fill-prefix) (string= fill-prefix "")))
183 (setq fill-prefix (fill-context-prefix from to nil dont-skip-first)))) 193 (setq fill-prefix (fill-context-prefix from to nil dont-skip-first))))
184 194
185 (defun fill-region-as-paragraph (from to &optional justify nosqueeze) 195 (defun fill-region-as-paragraph (from to &optional justify
196 nosqueeze squeeze-after)
186 "Fill the region as one paragraph. 197 "Fill the region as one paragraph.
187 It removes any paragraph breaks in the region and extra newlines at the end, 198 It removes any paragraph breaks in the region and extra newlines at the end,
188 indents and fills lines between the margins given by the 199 indents and fills lines between the margins given by the
189 `current-left-margin' and `current-fill-column' functions. 200 `current-left-margin' and `current-fill-column' functions.
190 It leaves point at the beginning of the line following the paragraph. 201 It leaves point at the beginning of the line following the paragraph.
191 202
192 Normally performs justification according to the `current-justification' 203 Normally performs justification according to the `current-justification'
193 function, but with a prefix arg, does full justification instead. 204 function, but with a prefix arg, does full justification instead.
194 205
195 From a program, optional third arg JUSTIFY can specify any type of 206 From a program, optional third arg JUSTIFY can specify any type of
196 justification, and fourth arg NOSQUEEZE non-nil means not to make spaces 207 ustification. Fourth arg NOSQUEEZE non-nil means not to make spaces
197 between words canonical before filling. 208 between words canonical before filling. Fifth arg SQUEEZE-AFTER, if non-nil,
209 means don't canonicalize spaces before that position.
198 210
199 If `sentence-end-double-space' is non-nil, then period followed by one 211 If `sentence-end-double-space' is non-nil, then period followed by one
200 space does not end a sentence, so don't break a line there." 212 space does not end a sentence, so don't break a line there."
201 (interactive 213 (interactive
202 (progn 214 (progn
219 231
220 (beginning-of-line) 232 (beginning-of-line)
221 (setq from (point)) 233 (setq from (point))
222 234
223 ;; Delete all but one soft newline at end of region. 235 ;; Delete all but one soft newline at end of region.
236 ;; And leave TO before that one.
224 (goto-char to) 237 (goto-char to)
225 (while (and (> (point) from) (eq ?\n (char-after (1- (point))))) 238 (while (and (> (point) from) (eq ?\n (char-after (1- (point)))))
226 (if (and oneleft 239 (if (and oneleft
227 (not (and use-hard-newlines 240 (not (and use-hard-newlines
228 (get-text-property (1- (point)) 'hard)))) 241 (get-text-property (1- (point)) 'hard))))
285 (while (not (eobp)) 298 (while (not (eobp))
286 (if (looking-at fpre) 299 (if (looking-at fpre)
287 (delete-region (point) (match-end 0))) 300 (delete-region (point) (match-end 0)))
288 (forward-line 1)) 301 (forward-line 1))
289 (goto-char from) 302 (goto-char from)
290 (and (looking-at fpre) (goto-char (match-end 0))) 303 (if (looking-at fpre)
304 (goto-char (match-end 0)))
291 (setq from (point))))) 305 (setq from (point)))))
292 ;; Remove indentation from lines other than the first. 306 ;; Remove indentation from lines other than the first.
293 (beginning-of-line 2) 307 (beginning-of-line 2)
294 (indent-region (point) (point-max) 0) 308 (indent-region (point) (point-max) 0)
295 (goto-char from) 309 (goto-char from)
298 ;; but after any fill prefix on the first line. 312 ;; but after any fill prefix on the first line.
299 313
300 ;; Make sure sentences ending at end of line get an extra space. 314 ;; Make sure sentences ending at end of line get an extra space.
301 ;; loses on split abbrevs ("Mr.\nSmith") 315 ;; loses on split abbrevs ("Mr.\nSmith")
302 (while (re-search-forward "[.?!][])}\"']*$" nil t) 316 (while (re-search-forward "[.?!][])}\"']*$" nil t)
317 ;; XEmacs change (no insert-and-inherit)
303 (or (eobp) (insert ?\ ))) 318 (or (eobp) (insert ?\ )))
304 (goto-char from) 319 (goto-char from)
305 (skip-chars-forward " \t") 320 (skip-chars-forward " \t")
306 ;; Then change all newlines to spaces. 321 ;; Then change all newlines to spaces.
307 (subst-char-in-region from (point-max) ?\n ?\ ) 322 (subst-char-in-region from (point-max) ?\n ?\ )
308 (if (and nosqueeze (not (eq justify 'full))) 323 (if (and nosqueeze (not (eq justify 'full)))
309 nil 324 nil
310 (canonically-space-region (point) (point-max)) 325 (canonically-space-region (or squeeze-after (point)) (point-max))
311 (goto-char (point-max)) 326 (goto-char (point-max))
312 (delete-horizontal-space) 327 (delete-horizontal-space)
328 ;; XEmacs change (no insert-and-inherit)
313 (insert " ")) 329 (insert " "))
314 (goto-char (point-min)) 330 (goto-char (point-min))
315 331
316 ;; This is the actual filling loop. 332 ;; This is the actual filling loop.
317 (let ((prefixcol 0) linebeg) 333 (let ((prefixcol 0) linebeg)
334 (not (eq (following-char) ?\ )) 350 (not (eq (following-char) ?\ ))
335 (eq (char-after (- (point) 2)) ?\.)) 351 (eq (char-after (- (point) 2)) ?\.))
336 (forward-char -2) 352 (forward-char -2)
337 (skip-chars-backward "^ \n" linebeg))) 353 (skip-chars-backward "^ \n" linebeg)))
338 ;; If the left margin and fill prefix by themselves 354 ;; If the left margin and fill prefix by themselves
339 ;; pass the fill-column, keep at least one word. 355 ;; pass the fill-column. or if they are zero
356 ;; but we have no room for even one word,
357 ;; keep at least one word anyway.
340 ;; This handles ALL BUT the first line of the paragraph. 358 ;; This handles ALL BUT the first line of the paragraph.
341 (if (if (zerop prefixcol) 359 (if (if (zerop prefixcol)
342 (save-excursion 360 (save-excursion
343 (skip-chars-backward " \t" linebeg) 361 (skip-chars-backward " \t" linebeg)
344 (bolp)) 362 (bolp))
383 (and (looking-at "\\. ") 401 (and (looking-at "\\. ")
384 (not (looking-at "\\. "))))))) 402 (not (looking-at "\\. ")))))))
385 (skip-chars-forward " \t") 403 (skip-chars-forward " \t")
386 (skip-chars-forward "^ \t\n") 404 (skip-chars-forward "^ \t\n")
387 (setq first nil)))) 405 (setq first nil))))
388 ;; Replace whitespace here with one newline, then indent to left 406 ;; Check again to see if we got to the end of the paragraph.
389 ;; margin. 407 (if (save-excursion (skip-chars-forward " \t") (eobp))
390 (skip-chars-backward " \t") 408 (or nosqueeze (delete-horizontal-space))
391 (insert ?\n) 409 ;; Replace whitespace here with one newline, then indent to left
392 ;; Give newline the properties of the space(s) it replaces 410 ;; margin.
393 (set-text-properties (1- (point)) (point) 411 (skip-chars-backward " \t")
394 (text-properties-at (point))) 412 (insert ?\n)
395 (indent-to-left-margin) 413 ;; Give newline the properties of the space(s) it replaces
396 ;; Insert the fill prefix after indentation. 414 (set-text-properties (1- (point)) (point)
397 ;; Set prefixcol so whitespace in the prefix won't get lost. 415 (text-properties-at (point)))
398 (and fill-prefix (not (equal fill-prefix "")) 416 (indent-to-left-margin)
399 (progn 417 ;; Insert the fill prefix after indentation.
400 (insert fill-prefix) 418 ;; Set prefixcol so whitespace in the prefix won't get lost.
401 (setq prefixcol (current-column))))) 419 (and fill-prefix (not (equal fill-prefix ""))
420 (progn
421 (insert fill-prefix)
422 (setq prefixcol (current-column))))))
402 ;; Justify the line just ended, if desired. 423 ;; Justify the line just ended, if desired.
403 (if justify 424 (if justify
404 (if (eobp) 425 (if (eobp)
405 (justify-current-line justify t t) 426 (justify-current-line justify t t)
406 (forward-line -1) 427 (forward-line -1)
530 breaks. 551 breaks.
531 552
532 When calling from a program, operates just on region between BEGIN and END, 553 When calling from a program, operates just on region between BEGIN and END,
533 unless optional fourth arg WHOLE-PAR is non-nil. In that case bounds are 554 unless optional fourth arg WHOLE-PAR is non-nil. In that case bounds are
534 extended to include entire paragraphs as in the interactive command." 555 extended to include entire paragraphs as in the interactive command."
556 ;; XEmacs change (was mark-active)
535 (interactive (list (if (region-active-p) (region-beginning) (point)) 557 (interactive (list (if (region-active-p) (region-beginning) (point))
536 (if (region-active-p) (region-end) (point)) 558 (if (region-active-p) (region-end) (point))
537 (let ((s (completing-read 559 (let ((s (completing-read
538 "Set justification to: " 560 "Set justification to: "
539 '(("left") ("right") ("full") 561 '(("left") ("right") ("full")
563 (fill-region begin (point-max) nil t)))) 585 (fill-region begin (point-max) nil t))))
564 586
565 (defun set-justification-none (b e) 587 (defun set-justification-none (b e)
566 "Disable automatic filling for paragraphs in the region. 588 "Disable automatic filling for paragraphs in the region.
567 If the mark is not active, this applies to the current paragraph." 589 If the mark is not active, this applies to the current paragraph."
590 ;; XEmacs change (was mark-active)
568 (interactive (list (if (region-active-p) (region-beginning) (point)) 591 (interactive (list (if (region-active-p) (region-beginning) (point))
569 (if (region-active-p) (region-end) (point)))) 592 (if (region-active-p) (region-end) (point))))
570 (set-justification b e 'none t)) 593 (set-justification b e 'none t))
571 594
572 (defun set-justification-left (b e) 595 (defun set-justification-left (b e)
573 "Make paragraphs in the region left-justified. 596 "Make paragraphs in the region left-justified.
574 This is usually the default, but see the variable `default-justification'. 597 This is usually the default, but see the variable `default-justification'.
575 If the mark is not active, this applies to the current paragraph." 598 If the mark is not active, this applies to the current paragraph."
599 ;; XEmacs change (was mark-active)
576 (interactive (list (if (region-active-p) (region-beginning) (point)) 600 (interactive (list (if (region-active-p) (region-beginning) (point))
577 (if (region-active-p) (region-end) (point)))) 601 (if (region-active-p) (region-end) (point))))
578 (set-justification b e 'left t)) 602 (set-justification b e 'left t))
579 603
580 (defun set-justification-right (b e) 604 (defun set-justification-right (b e)
581 "Make paragraphs in the region right-justified: 605 "Make paragraphs in the region right-justified:
582 Flush at the right margin and ragged on the left. 606 Flush at the right margin and ragged on the left.
583 If the mark is not active, this applies to the current paragraph." 607 If the mark is not active, this applies to the current paragraph."
608 ;; XEmacs change (was mark-active)
584 (interactive (list (if (region-active-p) (region-beginning) (point)) 609 (interactive (list (if (region-active-p) (region-beginning) (point))
585 (if (region-active-p) (region-end) (point)))) 610 (if (region-active-p) (region-end) (point))))
586 (set-justification b e 'right t)) 611 (set-justification b e 'right t))
587 612
588 (defun set-justification-full (b e) 613 (defun set-justification-full (b e)
589 "Make paragraphs in the region fully justified: 614 "Make paragraphs in the region fully justified:
590 This makes lines flush on both margins by inserting spaces between words. 615 This makes lines flush on both margins by inserting spaces between words.
591 If the mark is not active, this applies to the current paragraph." 616 If the mark is not active, this applies to the current paragraph."
617 ;; XEmacs change (was mark-active)
592 (interactive (list (if (region-active-p) (region-beginning) (point)) 618 (interactive (list (if (region-active-p) (region-beginning) (point))
593 (if (region-active-p) (region-end) (point)))) 619 (if (region-active-p) (region-end) (point))))
594 (set-justification b e 'full t)) 620 (set-justification b e 'full t))
595 621
596 (defun set-justification-center (b e) 622 (defun set-justification-center (b e)
597 "Make paragraphs in the region centered. 623 "Make paragraphs in the region centered.
598 If the mark is not active, this applies to the current paragraph." 624 If the mark is not active, this applies to the current paragraph."
625 ;; XEmacs change (was mark-active)
599 (interactive (list (if (region-active-p) (region-beginning) (point)) 626 (interactive (list (if (region-active-p) (region-beginning) (point))
600 (if (region-active-p) (region-end) (point)))) 627 (if (region-active-p) (region-end) (point))))
601 (set-justification b e 'center t)) 628 (set-justification b e 'center t))
602 629
603 ;; A line has up to six parts: 630 ;; A line has up to six parts:
735 (progn 762 (progn
736 (goto-char (point-max)) 763 (goto-char (point-max))
737 (search-backward " "))) 764 (search-backward " ")))
738 (skip-chars-backward " ") 765 (skip-chars-backward " ")
739 (setq nmove (1- nmove)))) 766 (setq nmove (1- nmove))))
767 ;; XEmacs change
740 (insert " ") 768 (insert " ")
741 (skip-chars-backward " ") 769 (skip-chars-backward " ")
742 (setq ncols (1- ncols))))))) 770 (setq ncols (1- ncols)))))))
743 (t (error "Unknown justification value")))) 771 (t (error "Unknown justification value"))))
744 (goto-char pos) 772 (goto-char pos)
746 nil) 774 nil)
747 775
748 (defun unjustify-current-line () 776 (defun unjustify-current-line ()
749 "Remove justification whitespace from current line. 777 "Remove justification whitespace from current line.
750 If the line is centered or right-justified, this function removes any 778 If the line is centered or right-justified, this function removes any
751 indentation past the left margin. If the line is full-jusitified, it removes 779 indentation past the left margin. If the line is full-justified, it removes
752 extra spaces between words. It does nothing in other justification modes." 780 extra spaces between words. It does nothing in other justification modes."
753 (let ((justify (current-justification))) 781 (let ((justify (current-justification)))
754 (cond ((eq 'left justify) nil) 782 (cond ((eq 'left justify) nil)
755 ((eq nil justify) nil) 783 ((eq nil justify) nil)
756 ((eq 'full justify) ; full justify: remove extra spaces 784 ((eq 'full justify) ; full justify: remove extra spaces
772 (point)))))))) 800 (point))))))))
773 801
774 (defun unjustify-region (&optional begin end) 802 (defun unjustify-region (&optional begin end)
775 "Remove justification whitespace from region. 803 "Remove justification whitespace from region.
776 For centered or right-justified regions, this function removes any indentation 804 For centered or right-justified regions, this function removes any indentation
777 past the left margin from each line. For full-jusitified lines, it removes 805 past the left margin from each line. For full-justified lines, it removes
778 extra spaces between words. It does nothing in other justification modes. 806 extra spaces between words. It does nothing in other justification modes.
779 Arguments BEGIN and END are optional; default is the whole buffer." 807 Arguments BEGIN and END are optional; default is the whole buffer."
780 (save-excursion 808 (save-excursion
781 (save-restriction 809 (save-restriction
782 (if end (narrow-to-region (point-min) end)) 810 (if end (narrow-to-region (point-min) end))
849 (point) 877 (point)
850 (save-excursion (skip-chars-forward " \t") 878 (save-excursion (skip-chars-forward " \t")
851 (point)))) 879 (point))))
852 fill-prefix-regexp (regexp-quote fill-prefix))) 880 fill-prefix-regexp (regexp-quote fill-prefix)))
853 (forward-line 1) 881 (forward-line 1)
854 (move-to-left-margin) 882 (if (bolp)
883 ;; If forward-line went past a newline
884 ;; move further to the left margin.
885 (move-to-left-margin))
855 ;; Now stop the loop if end of paragraph. 886 ;; Now stop the loop if end of paragraph.
856 (and (not (eobp)) 887 (and (not (eobp))
857 (if fill-individual-varying-indent 888 (if fill-individual-varying-indent
858 ;; If this line is a separator line, with or 889 ;; If this line is a separator line, with or
859 ;; without prefix, end the paragraph. 890 ;; without prefix, end the paragraph.
860 (and 891 (and
861 (not (looking-at paragraph-separate)) 892 (not (looking-at paragraph-separate))
862 (save-excursion 893 (save-excursion
863 (not (and (looking-at fill-prefix-regexp) 894 (not (and (looking-at fill-prefix-regexp)
895 ;; XEmacs change
864 (progn 896 (progn
865 (forward-char (length fill-prefix)) 897 (forward-char (length fill-prefix))
866 (looking-at paragraph-separate)))))) 898 (looking-at paragraph-separate))))))
867 ;; If this line has more or less indent 899 ;; If this line has more or less indent
868 ;; than the fill prefix wants, end the paragraph. 900 ;; than the fill prefix wants, end the paragraph.