aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1992-06-22 01:29:50 +0000
committerRichard M. Stallman1992-06-22 01:29:50 +0000
commit406a57c16e41db74f71a5dfa6152cdb0aeb3e62e (patch)
tree25564bdb3ae47ccf9d37230464530ced2f0f84de
parent9cfd2eeb81ecf56abdf6d3fdb5c2b89a8d5086b1 (diff)
downloademacs-406a57c16e41db74f71a5dfa6152cdb0aeb3e62e.tar.gz
emacs-406a57c16e41db74f71a5dfa6152cdb0aeb3e62e.zip
*** empty log message ***
-rw-r--r--lisp/textmodes/fill.el41
1 files changed, 37 insertions, 4 deletions
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el
index bc6ae99bae8..ed46490174d 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -133,23 +133,56 @@ From program, pass args FROM, TO and JUSTIFY-FLAG."
133 (insert " ") 133 (insert " ")
134 (goto-char (point-min)) 134 (goto-char (point-min))
135 135
136 (let ((prefixcol 0)) 136 ;; This is the actual filling loop.
137 (let ((prefixcol 0) linebeg)
137 (while (not (eobp)) 138 (while (not (eobp))
139 (setq linebeg (point))
138 (move-to-column (1+ fill-column)) 140 (move-to-column (1+ fill-column))
139 (if (eobp) 141 (if (eobp)
140 nil 142 nil
141 (skip-chars-backward "^ \n") 143 ;; Move back to start of word.
144 (skip-chars-backward "^ \n" linebeg)
145 ;; Don't break after a period followed by just one space.
146 ;; Move back to the previous place to break.
147 ;; The reason is that if a period ends up at the end of a line,
148 ;; further fills will assume it ends a sentence.
149 ;; If we now know it does not end a sentence,
150 ;; avoid putting it at the end of the line.
151 (while (and (> (point) (+ linebeg 2))
152 (eq (preceding-char) ?\ )
153 (eq (char-after (- (point) 2)) ?\.))
154 (forward-char -2)
155 (skip-chars-backward "^ \n" linebeg))
142 (if (if (zerop prefixcol) (bolp) (>= prefixcol (current-column))) 156 (if (if (zerop prefixcol) (bolp) (>= prefixcol (current-column)))
143 (skip-chars-forward "^ \n") 157 ;; Keep at least one word even if fill prefix exceeds margin.
158 ;; This handles all but the first line of the paragraph.
159 (progn
160 (skip-chars-forward " ")
161 (skip-chars-forward "^ \n"))
162 ;; Normally, move back over the single space between the words.
144 (forward-char -1))) 163 (forward-char -1)))
145 ;; Inserting the newline first prevents losing track of point. 164 (if (and fill-prefix (zerop prefixcol)
165 (< (- (point) (point-min)) (length fill-prefix))
166 (string= (buffer-substring (point-min) (point))
167 (substring fill-prefix 0 (- (point) (point-min)))))
168 ;; Keep at least one word even if fill prefix exceeds margin.
169 ;; This handles the first line of the paragraph.
170 (progn
171 (skip-chars-forward " ")
172 (skip-chars-forward "^ \n")))
173 ;; Replace all whitespace here with one newline.
174 ;; Insert before deleting, so we don't forget which side of
175 ;; the whitespace point or markers used to be on.
146 (skip-chars-backward " ") 176 (skip-chars-backward " ")
147 (insert ?\n) 177 (insert ?\n)
148 (delete-horizontal-space) 178 (delete-horizontal-space)
179 ;; Insert the fill prefix at start of each line.
180 ;; Set prefixcol so whitespace in the prefix won't get lost.
149 (and (not (eobp)) fill-prefix (not (equal fill-prefix "")) 181 (and (not (eobp)) fill-prefix (not (equal fill-prefix ""))
150 (progn 182 (progn
151 (insert fill-prefix) 183 (insert fill-prefix)
152 (setq prefixcol (current-column)))) 184 (setq prefixcol (current-column))))
185 ;; Justify the line just ended, if desired.
153 (and justify-flag (not (eobp)) 186 (and justify-flag (not (eobp))
154 (progn 187 (progn
155 (forward-line -1) 188 (forward-line -1)