annotate lisp/textmodes/fill.el @ 2757:a3ee51f30431

(child_setup): Omit duplicates from new env array.
author Richard M. Stallman <rms@gnu.org>
date Thu, 13 May 1993 00:21:47 +0000
parents ef643dbb7d40
children d00889d02f75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 638
diff changeset
1 ;;; fill.el --- fill commands for Emacs
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 638
diff changeset
2
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 821
diff changeset
3 ;; Copyright (C) 1985, 1986, 1992 Free Software Foundation, Inc.
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 821
diff changeset
4
811
e694e0879463 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
5 ;; Keywords: wp
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 732
diff changeset
6
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
8
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 732
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
12 ;; any later version.
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
13
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
17 ;; GNU General Public License for more details.
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
18
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
22
2307
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2109
diff changeset
23 ;;; Commentary:
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2109
diff changeset
24
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2109
diff changeset
25 ;; All the commands for filling text. These are documented in the Emacs
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2109
diff changeset
26 ;; manual.
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2109
diff changeset
27
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 732
diff changeset
28 ;;; Code:
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
29
638
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
30 (defconst fill-individual-varying-indent nil
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
31 "*Controls criterion for a new paragraph in `fill-individual-paragraphs'.
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
32 Non-nil means changing indent doesn't end a paragraph.
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
33 That mode can handle paragraphs with extra indentation on the first line,
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
34 but it requires separator lines between paragraphs.
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
35 Nil means that any change in indentation starts a new paragraph.")
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
36
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
37 (defun set-fill-prefix ()
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
38 "Set the fill-prefix to the current line up to point.
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
39 Filling expects lines to start with the fill prefix and
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
40 reinserts the fill prefix in each resulting line."
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
41 (interactive)
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
42 (setq fill-prefix (buffer-substring
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
43 (save-excursion (beginning-of-line) (point))
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
44 (point)))
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
45 (if (equal fill-prefix "")
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
46 (setq fill-prefix nil))
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
47 (if fill-prefix
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
48 (message "fill-prefix: \"%s\"" fill-prefix)
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
49 (message "fill-prefix cancelled")))
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
50
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
51 (defconst adaptive-fill-mode t
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
52 "*Non-nil means determine a paragraph's fill prefix from its text.")
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
53
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
54 (defconst adaptive-fill-regexp "[ \t]*\\([>*] +\\)?"
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
55 "*Regexp to match text at start of line that constitutes indentation.
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
56 If Adaptive Fill mode is enabled, whatever text matches this pattern
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
57 on the second line of a paragraph is used as the standard indentation
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
58 for the paragraph.")
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
59
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
60 (defun fill-region-as-paragraph (from to &optional justify-flag)
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
61 "Fill region as one paragraph: break lines to fit fill-column.
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
62 Prefix arg means justify too.
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
63 From program, pass args FROM, TO and JUSTIFY-FLAG."
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
64 (interactive "r\nP")
1332
955ebdb98095 (fill-paragraph): Don't actually change point before
Richard M. Stallman <rms@gnu.org>
parents: 1067
diff changeset
65 ;; Arrange for undoing the fill to restore point.
955ebdb98095 (fill-paragraph): Don't actually change point before
Richard M. Stallman <rms@gnu.org>
parents: 1067
diff changeset
66 (if (and buffer-undo-list (not (eq buffer-undo-list t)))
955ebdb98095 (fill-paragraph): Don't actually change point before
Richard M. Stallman <rms@gnu.org>
parents: 1067
diff changeset
67 (setq buffer-undo-list (cons (point) buffer-undo-list)))
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
68 ;; Don't let Adaptive Fill mode alter the fill prefix permanently.
2409
d03c7b8ac284 Cancel previous change; this version should be identical to version 1.17.
Richard M. Stallman <rms@gnu.org>
parents: 2376
diff changeset
69 (let ((fill-prefix fill-prefix))
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
70 ;; Figure out how this paragraph is indented, if desired.
670
bff41708644e *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 662
diff changeset
71 (if (and adaptive-fill-mode
bff41708644e *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 662
diff changeset
72 (or (null fill-prefix) (string= fill-prefix "")))
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
73 (save-excursion
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
74 (goto-char (min from to))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
75 (if (eolp) (forward-line 1))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
76 (forward-line 1)
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
77 (if (< (point) (max from to))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
78 (let ((start (point)))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
79 (re-search-forward adaptive-fill-regexp)
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
80 (setq fill-prefix (buffer-substring start (point))))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
81 (goto-char (min from to))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
82 (if (eolp) (forward-line 1))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
83 ;; If paragraph has only one line, don't assume
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
84 ;; that additional lines would have the same starting
729
5d684b81ac6b *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 719
diff changeset
85 ;; decoration. Assume no indentation.
5d684b81ac6b *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 719
diff changeset
86 ;; (re-search-forward adaptive-fill-regexp)
5d684b81ac6b *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 719
diff changeset
87 ;; (setq fill-prefix (make-string (current-column) ?\ ))
5d684b81ac6b *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 719
diff changeset
88 )))
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
89
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
90 (save-restriction
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
91 (narrow-to-region from to)
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
92 (goto-char (point-min))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
93 (skip-chars-forward "\n")
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
94 (narrow-to-region (point) (point-max))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
95 (setq from (point))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
96 (goto-char (point-max))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
97 (let ((fpre (and fill-prefix (not (equal fill-prefix ""))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
98 (regexp-quote fill-prefix))))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
99 ;; Delete the fill prefix from every line except the first.
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
100 ;; The first line may not even have a fill prefix.
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
101 (and fpre
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
102 (progn
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
103 (if (>= (length fill-prefix) fill-column)
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
104 (error "fill-prefix too long for specified width"))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
105 (goto-char (point-min))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
106 (forward-line 1)
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
107 (while (not (eobp))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
108 (if (looking-at fpre)
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
109 (delete-region (point) (match-end 0)))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
110 (forward-line 1))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
111 (goto-char (point-min))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
112 (and (looking-at fpre) (forward-char (length fill-prefix)))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
113 (setq from (point)))))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
114 ;; from is now before the text to fill,
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
115 ;; but after any fill prefix on the first line.
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
116
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
117 ;; Make sure sentences ending at end of line get an extra space.
2409
d03c7b8ac284 Cancel previous change; this version should be identical to version 1.17.
Richard M. Stallman <rms@gnu.org>
parents: 2376
diff changeset
118 ;; loses on split abbrevs ("Mr.\nSmith")
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
119 (goto-char from)
670
bff41708644e *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 662
diff changeset
120 (while (re-search-forward "[.?!][])}\"']*$" nil t)
2409
d03c7b8ac284 Cancel previous change; this version should be identical to version 1.17.
Richard M. Stallman <rms@gnu.org>
parents: 2376
diff changeset
121 (insert ? ))
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
122
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
123 ;; Then change all newlines to spaces.
2409
d03c7b8ac284 Cancel previous change; this version should be identical to version 1.17.
Richard M. Stallman <rms@gnu.org>
parents: 2376
diff changeset
124 (subst-char-in-region from (point-max) ?\n ?\ )
2376
f7a3795bd1c5 (fill-paragraph, justify-current-line) Now uses the skip-syntax-
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2307
diff changeset
125
2409
d03c7b8ac284 Cancel previous change; this version should be identical to version 1.17.
Richard M. Stallman <rms@gnu.org>
parents: 2376
diff changeset
126 ;; Flush excess spaces, except in the paragraph indentation.
d03c7b8ac284 Cancel previous change; this version should be identical to version 1.17.
Richard M. Stallman <rms@gnu.org>
parents: 2376
diff changeset
127 (goto-char from)
d03c7b8ac284 Cancel previous change; this version should be identical to version 1.17.
Richard M. Stallman <rms@gnu.org>
parents: 2376
diff changeset
128 (skip-chars-forward " \t")
d03c7b8ac284 Cancel previous change; this version should be identical to version 1.17.
Richard M. Stallman <rms@gnu.org>
parents: 2376
diff changeset
129 ;; nuke tabs while we're at it; they get screwed up in a fill
d03c7b8ac284 Cancel previous change; this version should be identical to version 1.17.
Richard M. Stallman <rms@gnu.org>
parents: 2376
diff changeset
130 ;; this is quick, but loses when a sole tab follows the end of a sentence.
d03c7b8ac284 Cancel previous change; this version should be identical to version 1.17.
Richard M. Stallman <rms@gnu.org>
parents: 2376
diff changeset
131 ;; actually, it is difficult to tell that from "Mr.\tSmith".
d03c7b8ac284 Cancel previous change; this version should be identical to version 1.17.
Richard M. Stallman <rms@gnu.org>
parents: 2376
diff changeset
132 ;; blame the typist.
d03c7b8ac284 Cancel previous change; this version should be identical to version 1.17.
Richard M. Stallman <rms@gnu.org>
parents: 2376
diff changeset
133 (subst-char-in-region (point) (point-max) ?\t ?\ )
d03c7b8ac284 Cancel previous change; this version should be identical to version 1.17.
Richard M. Stallman <rms@gnu.org>
parents: 2376
diff changeset
134 (while (re-search-forward " *" nil t)
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
135 (delete-region
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
136 (+ (match-beginning 0)
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
137 (if (save-excursion
2409
d03c7b8ac284 Cancel previous change; this version should be identical to version 1.17.
Richard M. Stallman <rms@gnu.org>
parents: 2376
diff changeset
138 (skip-chars-backward " ]})\"'")
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
139 (memq (preceding-char) '(?. ?? ?!)))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
140 2 1))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
141 (match-end 0)))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
142 (goto-char (point-max))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
143 (delete-horizontal-space)
2409
d03c7b8ac284 Cancel previous change; this version should be identical to version 1.17.
Richard M. Stallman <rms@gnu.org>
parents: 2376
diff changeset
144 (insert " ")
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
145 (goto-char (point-min))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
146
719
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
147 ;; This is the actual filling loop.
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
148 (let ((prefixcol 0) linebeg)
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
149 (while (not (eobp))
719
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
150 (setq linebeg (point))
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
151 (move-to-column (1+ fill-column))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
152 (if (eobp)
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
153 nil
719
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
154 ;; Move back to start of word.
2409
d03c7b8ac284 Cancel previous change; this version should be identical to version 1.17.
Richard M. Stallman <rms@gnu.org>
parents: 2376
diff changeset
155 (skip-chars-backward "^ \n" linebeg)
719
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
156 ;; Don't break after a period followed by just one space.
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
157 ;; Move back to the previous place to break.
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
158 ;; The reason is that if a period ends up at the end of a line,
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
159 ;; further fills will assume it ends a sentence.
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
160 ;; If we now know it does not end a sentence,
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
161 ;; avoid putting it at the end of the line.
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
162 (while (and (> (point) (+ linebeg 2))
2409
d03c7b8ac284 Cancel previous change; this version should be identical to version 1.17.
Richard M. Stallman <rms@gnu.org>
parents: 2376
diff changeset
163 (eq (preceding-char) ?\ )
719
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
164 (eq (char-after (- (point) 2)) ?\.))
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
165 (forward-char -2)
2409
d03c7b8ac284 Cancel previous change; this version should be identical to version 1.17.
Richard M. Stallman <rms@gnu.org>
parents: 2376
diff changeset
166 (skip-chars-backward "^ \n" linebeg))
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
167 (if (if (zerop prefixcol) (bolp) (>= prefixcol (current-column)))
719
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
168 ;; Keep at least one word even if fill prefix exceeds margin.
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
169 ;; This handles all but the first line of the paragraph.
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
170 (progn
2409
d03c7b8ac284 Cancel previous change; this version should be identical to version 1.17.
Richard M. Stallman <rms@gnu.org>
parents: 2376
diff changeset
171 (skip-chars-forward " ")
d03c7b8ac284 Cancel previous change; this version should be identical to version 1.17.
Richard M. Stallman <rms@gnu.org>
parents: 2376
diff changeset
172 (skip-chars-forward "^ \n"))
719
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
173 ;; Normally, move back over the single space between the words.
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
174 (forward-char -1)))
719
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
175 (if (and fill-prefix (zerop prefixcol)
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
176 (< (- (point) (point-min)) (length fill-prefix))
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
177 (string= (buffer-substring (point-min) (point))
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
178 (substring fill-prefix 0 (- (point) (point-min)))))
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
179 ;; Keep at least one word even if fill prefix exceeds margin.
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
180 ;; This handles the first line of the paragraph.
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
181 (progn
2409
d03c7b8ac284 Cancel previous change; this version should be identical to version 1.17.
Richard M. Stallman <rms@gnu.org>
parents: 2376
diff changeset
182 (skip-chars-forward " ")
d03c7b8ac284 Cancel previous change; this version should be identical to version 1.17.
Richard M. Stallman <rms@gnu.org>
parents: 2376
diff changeset
183 (skip-chars-forward "^ \n")))
719
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
184 ;; Replace all whitespace here with one newline.
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
185 ;; Insert before deleting, so we don't forget which side of
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
186 ;; the whitespace point or markers used to be on.
2409
d03c7b8ac284 Cancel previous change; this version should be identical to version 1.17.
Richard M. Stallman <rms@gnu.org>
parents: 2376
diff changeset
187 (skip-chars-backward " ")
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
188 (insert ?\n)
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
189 (delete-horizontal-space)
719
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
190 ;; Insert the fill prefix at start of each line.
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
191 ;; Set prefixcol so whitespace in the prefix won't get lost.
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
192 (and (not (eobp)) fill-prefix (not (equal fill-prefix ""))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
193 (progn
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
194 (insert fill-prefix)
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
195 (setq prefixcol (current-column))))
719
3007551721dc *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 670
diff changeset
196 ;; Justify the line just ended, if desired.
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
197 (and justify-flag (not (eobp))
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
198 (progn
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
199 (forward-line -1)
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
200 (justify-current-line)
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
201 (forward-line 1))))))))
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
202
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
203 (defun fill-paragraph (arg)
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
204 "Fill paragraph at or after point. Prefix arg means justify as well."
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
205 (interactive "P")
1332
955ebdb98095 (fill-paragraph): Don't actually change point before
Richard M. Stallman <rms@gnu.org>
parents: 1067
diff changeset
206 (let ((before (point)))
955ebdb98095 (fill-paragraph): Don't actually change point before
Richard M. Stallman <rms@gnu.org>
parents: 1067
diff changeset
207 (save-excursion
955ebdb98095 (fill-paragraph): Don't actually change point before
Richard M. Stallman <rms@gnu.org>
parents: 1067
diff changeset
208 (forward-paragraph)
955ebdb98095 (fill-paragraph): Don't actually change point before
Richard M. Stallman <rms@gnu.org>
parents: 1067
diff changeset
209 (or (bolp) (newline 1))
955ebdb98095 (fill-paragraph): Don't actually change point before
Richard M. Stallman <rms@gnu.org>
parents: 1067
diff changeset
210 (let ((end (point))
955ebdb98095 (fill-paragraph): Don't actually change point before
Richard M. Stallman <rms@gnu.org>
parents: 1067
diff changeset
211 (beg (progn (backward-paragraph) (point))))
955ebdb98095 (fill-paragraph): Don't actually change point before
Richard M. Stallman <rms@gnu.org>
parents: 1067
diff changeset
212 (goto-char before)
955ebdb98095 (fill-paragraph): Don't actually change point before
Richard M. Stallman <rms@gnu.org>
parents: 1067
diff changeset
213 (fill-region-as-paragraph beg end arg)))))
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
214
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
215 (defun fill-region (from to &optional justify-flag)
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
216 "Fill each of the paragraphs in the region.
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
217 Prefix arg (non-nil third arg, if called from program) means justify as well."
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
218 (interactive "r\nP")
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
219 (save-restriction
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
220 (narrow-to-region from to)
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
221 (goto-char (point-min))
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
222 (while (not (eobp))
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
223 (let ((initial (point))
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
224 (end (progn
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
225 (forward-paragraph 1) (point))))
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
226 (forward-paragraph -1)
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
227 (if (>= (point) initial)
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
228 (fill-region-as-paragraph (point) end justify-flag)
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
229 (goto-char end))))))
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
230
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
231 (defun justify-current-line ()
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
232 "Add spaces to line point is in, so it ends at `fill-column'."
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
233 (interactive)
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
234 (save-excursion
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
235 (save-restriction
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
236 (let (ncols beg indent)
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
237 (beginning-of-line)
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
238 (forward-char (length fill-prefix))
2409
d03c7b8ac284 Cancel previous change; this version should be identical to version 1.17.
Richard M. Stallman <rms@gnu.org>
parents: 2376
diff changeset
239 (skip-chars-forward " \t")
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
240 (setq indent (current-column))
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
241 (setq beg (point))
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
242 (end-of-line)
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
243 (narrow-to-region beg (point))
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
244 (goto-char beg)
2409
d03c7b8ac284 Cancel previous change; this version should be identical to version 1.17.
Richard M. Stallman <rms@gnu.org>
parents: 2376
diff changeset
245 (while (re-search-forward " *" nil t)
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
246 (delete-region
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
247 (+ (match-beginning 0)
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
248 (if (save-excursion
2409
d03c7b8ac284 Cancel previous change; this version should be identical to version 1.17.
Richard M. Stallman <rms@gnu.org>
parents: 2376
diff changeset
249 (skip-chars-backward " ])\"'")
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
250 (memq (preceding-char) '(?. ?? ?!)))
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
251 2 1))
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
252 (match-end 0)))
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
253 (goto-char beg)
1067
eb89a883529c entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
254 (while (re-search-forward "[.?!][])\"']*\n" nil t)
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
255 (forward-char -1)
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
256 (insert ? ))
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
257 (goto-char (point-max))
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
258 ;; Note that the buffer bounds start after the indentation,
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
259 ;; so the columns counted by INDENT don't appear in (current-column).
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
260 (setq ncols (- fill-column (current-column) indent))
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
261 (if (search-backward " " nil t)
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
262 (while (> ncols 0)
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
263 (let ((nmove (+ 3 (random 3))))
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
264 (while (> nmove 0)
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
265 (or (search-backward " " nil t)
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
266 (progn
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
267 (goto-char (point-max))
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
268 (search-backward " ")))
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
269 (skip-chars-backward " ")
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
270 (setq nmove (1- nmove))))
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
271 (insert " ")
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
272 (skip-chars-backward " ")
2109
73485780a8f9 * simple.el (yank, yank-pop): Always return nil; don't rely on
Jim Blandy <jimb@redhat.com>
parents: 1332
diff changeset
273 (setq ncols (1- ncols)))))))
73485780a8f9 * simple.el (yank, yank-pop): Always return nil; don't rely on
Jim Blandy <jimb@redhat.com>
parents: 1332
diff changeset
274 nil)
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
275
2520
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
276 (defun fill-nonuniform-paragraphs (min max &optional justifyp mailp)
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
277 "Fill paragraphs within the region, allowing varying indentation within each.
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
278 This command divides the region into \"paragraphs\",
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
279 only at paragraph-separator lines, then fills each paragraph
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
280 using as the fill prefix the smallest indentation of any line
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
281 in the paragraph.
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
282
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
283 When calling from a program, pass range to fill as first two arguments.
638
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
284
2520
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
285 Optional third and fourth arguments JUSTIFY-FLAG and MAIL-FLAG:
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
286 JUSTIFY-FLAG to justify paragraphs (prefix arg),
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
287 MAIL-FLAG for a mail message, i. e. don't fill header lines."
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
288 (interactive "r\nP")
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
289 (let ((fill-individual-varying-indent t))
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
290 (fill-individual-paragraphs min max justifyp mailp)))
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
291
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
292 (defun fill-individual-paragraphs (min max &optional justifyp mailp)
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
293 "Fill paragraphs of uniform indentation within the region.
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
294 This command divides the region into \"paragraphs\",
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
295 treating every change in indentation level as a paragraph boundary,
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
296 then fills each paragraph using its indentation level as the fill prefix.
638
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
297
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
298 When calling from a program, pass range to fill as first two arguments.
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
299
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
300 Optional third and fourth arguments JUSTIFY-FLAG and MAIL-FLAG:
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
301 JUSTIFY-FLAG to justify paragraphs (prefix arg),
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
302 MAIL-FLAG for a mail message, i. e. don't fill header lines."
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
303 (interactive "r\nP")
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
304 (save-restriction
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
305 (save-excursion
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
306 (goto-char min)
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
307 (beginning-of-line)
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
308 (if mailp
821
cee415e2dae8 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 811
diff changeset
309 (while (or (looking-at "[ \t]*[^ \t\n]*:") (looking-at "[ \t]*$"))
2412
b3ea1323d6d1 (fill-individual-paragraphs): When skipping mail headers, skip to a blank line.
Richard M. Stallman <rms@gnu.org>
parents: 2409
diff changeset
310 (search-forward "\n\n" nil 'move)))
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
311 (narrow-to-region (point) max)
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
312 ;; Loop over paragraphs.
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
313 (while (progn (skip-chars-forward " \t\n") (not (eobp)))
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
314 (beginning-of-line)
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
315 (let ((start (point))
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
316 fill-prefix fill-prefix-regexp)
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
317 ;; Find end of paragraph, and compute the smallest fill-prefix
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
318 ;; that fits all the lines in this paragraph.
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
319 (while (progn
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
320 ;; Update the fill-prefix on the first line
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
321 ;; and whenever the prefix good so far is too long.
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
322 (if (not (and fill-prefix
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
323 (looking-at fill-prefix-regexp)))
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
324 (setq fill-prefix
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
325 (buffer-substring (point)
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
326 (save-excursion (skip-chars-forward " \t") (point)))
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
327 fill-prefix-regexp
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
328 (regexp-quote fill-prefix)))
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
329 (forward-line 1)
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
330 ;; Now stop the loop if end of paragraph.
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
331 (and (not (eobp))
638
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
332 (if fill-individual-varying-indent
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
333 ;; If this line is a separator line, with or
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
334 ;; without prefix, end the paragraph.
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
335 (and
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
336 (not (looking-at paragraph-separate))
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
337 (save-excursion
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
338 (not (and (looking-at fill-prefix-regexp)
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
339 (progn (forward-char (length fill-prefix))
638
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
340 (looking-at paragraph-separate))))))
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
341 ;; If this line has more or less indent
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
342 ;; than the fill prefix wants, end the paragraph.
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
343 (and (looking-at fill-prefix-regexp)
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
344 (save-excursion
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
345 (not (progn (forward-char (length fill-prefix))
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
346 (or (looking-at paragraph-separate)
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
347 (looking-at paragraph-start))))))))))
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
348 ;; Fill this paragraph, but don't add a newline at the end.
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
349 (let ((had-newline (bolp)))
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
350 (fill-region-as-paragraph start (point) justifyp)
638
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
351 (or had-newline (delete-char -1))))))))
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 638
diff changeset
352
732
a8d94735277e *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 729
diff changeset
353 ;;; fill.el ends here