diff options
| author | Richard M. Stallman | 1995-11-17 23:32:15 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1995-11-17 23:32:15 +0000 |
| commit | 2b6eb8c6cea3b5267696d479ab1fabee44bd6b32 (patch) | |
| tree | b8b0a53cf89310673acdd515973a9bfab94a6b5a /lisp | |
| parent | 54505d728cf748f1bb19d2f8c9e33f47184a414a (diff) | |
| download | emacs-2b6eb8c6cea3b5267696d479ab1fabee44bd6b32.tar.gz emacs-2b6eb8c6cea3b5267696d479ab1fabee44bd6b32.zip | |
(fill-region-as-paragraph): Remove redundant "setq from".
Don't add extra newline at end if there is no text in paragraph --
doing so can make fill-region loop.
When testing for indentation exceeding fill-column, skip back over tabs too.
(fill-context-prefix): Use adaptive-fill-regexp only if non-nil.
(fill-context-prefix): Check adaptive-fill-function non-nil.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/textmodes/fill.el | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el index 71942e8616a..85223d14f1d 100644 --- a/lisp/textmodes/fill.el +++ b/lisp/textmodes/fill.el | |||
| @@ -145,15 +145,16 @@ This uses the variables `adapive-fill-prefix' and `adaptive-fill-function'." | |||
| 145 | (let ((start (point)) | 145 | (let ((start (point)) |
| 146 | (eol (save-excursion (end-of-line) (point)))) | 146 | (eol (save-excursion (end-of-line) (point)))) |
| 147 | (if (not (looking-at paragraph-start)) | 147 | (if (not (looking-at paragraph-start)) |
| 148 | (cond ((looking-at adaptive-fill-regexp) | 148 | (cond ((and adaptive-fill-regexp (looking-at adaptive-fill-regexp)) |
| 149 | (buffer-substring-no-properties start (match-end 0))) | 149 | (buffer-substring-no-properties start (match-end 0))) |
| 150 | (t (funcall adaptive-fill-function))))))) | 150 | (adaptive-fill-function (funcall adaptive-fill-function))))))) |
| 151 | 151 | ||
| 152 | (defun fill-region-as-paragraph (from to &optional justify nosqueeze) | 152 | (defun fill-region-as-paragraph (from to &optional justify nosqueeze) |
| 153 | "Fill the region as one paragraph. | 153 | "Fill the region as one paragraph. |
| 154 | Removes any paragraph breaks in the region and extra newlines at the end, | 154 | It removes any paragraph breaks in the region and extra newlines at the end, |
| 155 | indents and fills lines between the margins given by the | 155 | indents and fills lines between the margins given by the |
| 156 | `current-left-margin' and `current-fill-column' functions. | 156 | `current-left-margin' and `current-fill-column' functions. |
| 157 | It leaves point at the beginning of the line following the paragraph. | ||
| 157 | 158 | ||
| 158 | Normally performs justification according to the `current-justification' | 159 | Normally performs justification according to the `current-justification' |
| 159 | function, but with a prefix arg, does full justification instead. | 160 | function, but with a prefix arg, does full justification instead. |
| @@ -170,14 +171,20 @@ space does not end a sentence, so don't break a line there." | |||
| 170 | (if (and buffer-undo-list (not (eq buffer-undo-list t))) | 171 | (if (and buffer-undo-list (not (eq buffer-undo-list t))) |
| 171 | (setq buffer-undo-list (cons (point) buffer-undo-list))) | 172 | (setq buffer-undo-list (cons (point) buffer-undo-list))) |
| 172 | 173 | ||
| 173 | ;; Make sure "to" is the endpoint. Make sure that we end up there. | 174 | ;; Make sure "to" is the endpoint. |
| 174 | (goto-char (min from to)) | 175 | (goto-char (min from to)) |
| 175 | (setq to (max from to)) | 176 | (setq to (max from to)) |
| 176 | (setq from (point)) | 177 | ;; Ignore blank lines at beginning of region. |
| 178 | (skip-chars-forward " \t\n") | ||
| 177 | 179 | ||
| 178 | ;; Delete all but one soft newline at end of region. | 180 | (let ((from-plus-indent (point)) |
| 179 | (goto-char to) | 181 | (oneleft nil)) |
| 180 | (let ((oneleft nil)) | 182 | |
| 183 | (beginning-of-line) | ||
| 184 | (setq from (point)) | ||
| 185 | |||
| 186 | ;; Delete all but one soft newline at end of region. | ||
| 187 | (goto-char to) | ||
| 181 | (while (and (> (point) from) (eq ?\n (char-after (1- (point))))) | 188 | (while (and (> (point) from) (eq ?\n (char-after (1- (point))))) |
| 182 | (if (and oneleft | 189 | (if (and oneleft |
| 183 | (not (and use-hard-newlines | 190 | (not (and use-hard-newlines |
| @@ -185,19 +192,16 @@ space does not end a sentence, so don't break a line there." | |||
| 185 | (delete-backward-char 1) | 192 | (delete-backward-char 1) |
| 186 | (backward-char 1) | 193 | (backward-char 1) |
| 187 | (setq oneleft t))) | 194 | (setq oneleft t))) |
| 188 | ;; If there was no newline, create one. | 195 | (setq to (point)) |
| 189 | (if (and (not oneleft) (> (point) from)) | ||
| 190 | (save-excursion (newline)))) | ||
| 191 | (setq to (point)) | ||
| 192 | 196 | ||
| 193 | ;; Ignore blank lines at beginning of region. | 197 | ;; If there was no newline, and there is text in the paragraph, then |
| 194 | (goto-char from) | 198 | ;; create a newline. |
| 195 | (skip-chars-forward " \t\n") | 199 | (if (and (not oneleft) (> to from-plus-indent)) |
| 196 | (beginning-of-line) | 200 | (newline)) |
| 197 | (setq from (point)) | 201 | (goto-char from-plus-indent)) |
| 198 | 202 | ||
| 199 | (if (>= from to) | 203 | (if (not (> to (point))) |
| 200 | nil ; There is no paragraph at all. | 204 | nil ; There is no paragraph, only whitespace: exit now. |
| 201 | 205 | ||
| 202 | (or justify (setq justify (current-justification))) | 206 | (or justify (setq justify (current-justification))) |
| 203 | 207 | ||
| @@ -300,7 +304,7 @@ space does not end a sentence, so don't break a line there." | |||
| 300 | ;; This handles ALL BUT the first line of the paragraph. | 304 | ;; This handles ALL BUT the first line of the paragraph. |
| 301 | (if (if (zerop prefixcol) | 305 | (if (if (zerop prefixcol) |
| 302 | (save-excursion | 306 | (save-excursion |
| 303 | (skip-chars-backward " " linebeg) | 307 | (skip-chars-backward " \t" linebeg) |
| 304 | (bolp)) | 308 | (bolp)) |
| 305 | (>= prefixcol (current-column))) | 309 | (>= prefixcol (current-column))) |
| 306 | ;; Ok, skip at least one word. | 310 | ;; Ok, skip at least one word. |
| @@ -314,8 +318,8 @@ space does not end a sentence, so don't break a line there." | |||
| 314 | (save-excursion (forward-char -1) | 318 | (save-excursion (forward-char -1) |
| 315 | (and (looking-at "\\. ") | 319 | (and (looking-at "\\. ") |
| 316 | (not (looking-at "\\. "))))))) | 320 | (not (looking-at "\\. "))))))) |
| 317 | (skip-chars-forward " ") | 321 | (skip-chars-forward " \t") |
| 318 | (skip-chars-forward "^ \n") | 322 | (skip-chars-forward "^ \n\t") |
| 319 | (setq first nil))) | 323 | (setq first nil))) |
| 320 | ;; Normally, move back over the single space between the words. | 324 | ;; Normally, move back over the single space between the words. |
| 321 | (forward-char -1)) | 325 | (forward-char -1)) |
| @@ -342,12 +346,12 @@ space does not end a sentence, so don't break a line there." | |||
| 342 | (save-excursion (forward-char -1) | 346 | (save-excursion (forward-char -1) |
| 343 | (and (looking-at "\\. ") | 347 | (and (looking-at "\\. ") |
| 344 | (not (looking-at "\\. "))))))) | 348 | (not (looking-at "\\. "))))))) |
| 345 | (skip-chars-forward " ") | 349 | (skip-chars-forward " \t") |
| 346 | (skip-chars-forward "^ \n") | 350 | (skip-chars-forward "^ \t\n") |
| 347 | (setq first nil)))) | 351 | (setq first nil)))) |
| 348 | ;; Replace whitespace here with one newline, then indent to left | 352 | ;; Replace whitespace here with one newline, then indent to left |
| 349 | ;; margin. | 353 | ;; margin. |
| 350 | (skip-chars-backward " ") | 354 | (skip-chars-backward " \t") |
| 351 | (insert ?\n) | 355 | (insert ?\n) |
| 352 | ;; Give newline the properties of the space(s) it replaces | 356 | ;; Give newline the properties of the space(s) it replaces |
| 353 | (set-text-properties (1- (point)) (point) | 357 | (set-text-properties (1- (point)) (point) |