diff options
| author | Jim Blandy | 1991-12-21 09:14:03 +0000 |
|---|---|---|
| committer | Jim Blandy | 1991-12-21 09:14:03 +0000 |
| commit | aa228418e97d3b6aada0da50ee0419c5c23f726c (patch) | |
| tree | 54f5de32b8b44b028fc96ebda21b9d11f96916fe /lisp/textmodes | |
| parent | 0231f2dce81e3f5118c5c2eecec6081ba888e03a (diff) | |
| download | emacs-aa228418e97d3b6aada0da50ee0419c5c23f726c.tar.gz emacs-aa228418e97d3b6aada0da50ee0419c5c23f726c.zip | |
*** empty log message ***
Diffstat (limited to 'lisp/textmodes')
| -rw-r--r-- | lisp/textmodes/fill.el | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el index d7526a192b5..ad15fed9ee0 100644 --- a/lisp/textmodes/fill.el +++ b/lisp/textmodes/fill.el | |||
| @@ -224,23 +224,40 @@ Optional third and fourth arguments JUSTIFY-FLAG and MAIL-FLAG: | |||
| 224 | JUSTIFY-FLAG to justify paragraphs (prefix arg), | 224 | JUSTIFY-FLAG to justify paragraphs (prefix arg), |
| 225 | MAIL-FLAG for a mail message, i. e. don't fill header lines." | 225 | MAIL-FLAG for a mail message, i. e. don't fill header lines." |
| 226 | (interactive "r\nP") | 226 | (interactive "r\nP") |
| 227 | (let (fill-prefix) | 227 | (save-restriction |
| 228 | (save-restriction | 228 | (save-excursion |
| 229 | (save-excursion | 229 | (goto-char min) |
| 230 | (goto-char min) | 230 | (beginning-of-line) |
| 231 | (if mailp | 231 | (if mailp |
| 232 | (while (looking-at "[^ \t\n]*:") | 232 | (while (looking-at "[^ \t\n]*:") |
| 233 | (forward-line 1))) | 233 | (forward-line 1))) |
| 234 | (narrow-to-region (point) max) | 234 | (narrow-to-region (point) max) |
| 235 | (while (progn | 235 | ;; Loop over paragraphs. |
| 236 | (skip-chars-forward " \t\n") | 236 | (while (progn (skip-chars-forward " \t\n") (not (eobp))) |
| 237 | (not (eobp))) | 237 | (beginning-of-line) |
| 238 | (setq fill-prefix | 238 | (let ((start (point)) |
| 239 | (buffer-substring (point) (progn (beginning-of-line) (point)))) | 239 | fill-prefix fill-prefix-regexp) |
| 240 | (let ((fin (save-excursion (forward-paragraph) (point))) | 240 | ;; Find end of paragraph, and compute the smallest fill-prefix |
| 241 | (start (point))) | 241 | ;; that fits all the lines in this paragraph. |
| 242 | (fill-region-as-paragraph (point) fin justifyp) | 242 | (while (progn |
| 243 | (goto-char start) | 243 | ;; Update the fill-prefix on the first line |
| 244 | (forward-paragraph))))))) | 244 | ;; and whenever the prefix good so far is too long. |
| 245 | 245 | (if (not (and fill-prefix | |
| 246 | 246 | (looking-at fill-prefix-regexp))) | |
| 247 | (setq fill-prefix | ||
| 248 | (buffer-substring (point) | ||
| 249 | (save-excursion (skip-chars-forward " \t") (point))) | ||
| 250 | fill-prefix-regexp | ||
| 251 | (regexp-quote fill-prefix))) | ||
| 252 | (forward-line 1) | ||
| 253 | ;; Now stop the loop if end of paragraph. | ||
| 254 | (and (not (eobp)) | ||
| 255 | (not (looking-at paragraph-separate)) | ||
| 256 | (save-excursion | ||
| 257 | (not (and (looking-at fill-prefix-regexp) | ||
| 258 | (progn (forward-char (length fill-prefix)) | ||
| 259 | (looking-at paragraph-separate)))))))) | ||
| 260 | ;; Fill this paragraph, but don't add a newline at the end. | ||
| 261 | (let ((had-newline (bolp))) | ||
| 262 | (fill-region-as-paragraph start (point) justifyp) | ||
| 263 | (or had-newline (delete-char -1)))))))) \ No newline at end of file | ||