Mercurial > emacs
comparison lisp/textmodes/fill.el @ 14621:f989cff391f1
(canonically-space-region): Use insert-before-markers
when inserting spaces at end of line.
(fill-region-as-paragraph): New arg SQUEEZE-AFTER.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Wed, 21 Feb 1996 21:20:28 +0000 |
parents | 83f275dcd93a |
children | 875c14f0d0db |
comparison
equal
deleted
inserted
replaced
14620:794c6fdfa87d | 14621:f989cff391f1 |
---|---|
99 here-col col)) | 99 here-col col)) |
100 (max here-col fill-col))))) | 100 (max here-col fill-col))))) |
101 | 101 |
102 (defun canonically-space-region (beg end) | 102 (defun canonically-space-region (beg end) |
103 "Remove extra spaces between words in region. | 103 "Remove extra spaces between words in region. |
104 Puts one space between words in region; two between sentences. | 104 Leave one space between words, two at end of sentences or after colons |
105 (depending on values of `sentence-end-double-space' and `colon-double-space'). | |
105 Remove indentation from each line." | 106 Remove indentation from each line." |
106 (interactive "r") | 107 (interactive "r") |
107 (save-excursion | 108 (save-excursion |
108 (goto-char beg) | 109 (goto-char beg) |
109 ;; Nuke tabs; they get screwed up in a fill. | 110 ;; Nuke tabs; they get screwed up in a fill. |
128 ;; Make sure sentences ending at end of line get an extra space. | 129 ;; Make sure sentences ending at end of line get an extra space. |
129 ;; loses on split abbrevs ("Mr.\nSmith") | 130 ;; loses on split abbrevs ("Mr.\nSmith") |
130 (goto-char beg) | 131 (goto-char beg) |
131 (while (and (< (point) end) | 132 (while (and (< (point) end) |
132 (re-search-forward "[.?!][])}\"']*$" end t)) | 133 (re-search-forward "[.?!][])}\"']*$" end t)) |
133 (insert-and-inherit ? )))) | 134 ;; We insert before markers in case a caller such as |
135 ;; do-auto-fill has done a save-excursion with point at the end | |
136 ;; of the line and wants it to stay at the end of the line. | |
137 (insert-before-markers-and-inherit ? )))) | |
134 | 138 |
135 (defun fill-context-prefix (from to &optional first-line-regexp) | 139 (defun fill-context-prefix (from to &optional first-line-regexp) |
136 "Compute a fill prefix from the text between FROM and TO. | 140 "Compute a fill prefix from the text between FROM and TO. |
137 This uses the variables `adaptive-fill-prefix' and `adaptive-fill-function'. | 141 This uses the variables `adaptive-fill-prefix' and `adaptive-fill-function'. |
138 If FIRST-LINE-REGEXP is non-nil, then when taking a prefix from the | 142 If FIRST-LINE-REGEXP is non-nil, then when taking a prefix from the |
161 (or at-second | 165 (or at-second |
162 (null first-line-regexp) | 166 (null first-line-regexp) |
163 (string-match first-line-regexp result)) | 167 (string-match first-line-regexp result)) |
164 result))))) | 168 result))))) |
165 | 169 |
166 (defun fill-region-as-paragraph (from to &optional justify nosqueeze) | 170 (defun fill-region-as-paragraph (from to &optional justify |
171 nosqueeze squeeze-after) | |
167 "Fill the region as one paragraph. | 172 "Fill the region as one paragraph. |
168 It removes any paragraph breaks in the region and extra newlines at the end, | 173 It removes any paragraph breaks in the region and extra newlines at the end, |
169 indents and fills lines between the margins given by the | 174 indents and fills lines between the margins given by the |
170 `current-left-margin' and `current-fill-column' functions. | 175 `current-left-margin' and `current-fill-column' functions. |
171 It leaves point at the beginning of the line following the paragraph. | 176 It leaves point at the beginning of the line following the paragraph. |
172 | 177 |
173 Normally performs justification according to the `current-justification' | 178 Normally performs justification according to the `current-justification' |
174 function, but with a prefix arg, does full justification instead. | 179 function, but with a prefix arg, does full justification instead. |
175 | 180 |
176 From a program, optional third arg JUSTIFY can specify any type of | 181 From a program, optional third arg JUSTIFY can specify any type of |
177 justification, and fourth arg NOSQUEEZE non-nil means not to make spaces | 182 justification. Fourth arg NOSQUEEZE non-nil means not to make spaces |
178 between words canonical before filling. | 183 between words canonical before filling. Firth arg SQUEEZE-AFTER, if non-nil, |
184 means don't canonicalize spaces before that position. | |
179 | 185 |
180 If `sentence-end-double-space' is non-nil, then period followed by one | 186 If `sentence-end-double-space' is non-nil, then period followed by one |
181 space does not end a sentence, so don't break a line there." | 187 space does not end a sentence, so don't break a line there." |
182 (interactive (list (region-beginning) (region-end) | 188 (interactive (list (region-beginning) (region-end) |
183 (if current-prefix-arg 'full))) | 189 (if current-prefix-arg 'full))) |
264 (while (not (eobp)) | 270 (while (not (eobp)) |
265 (if (looking-at fpre) | 271 (if (looking-at fpre) |
266 (delete-region (point) (match-end 0))) | 272 (delete-region (point) (match-end 0))) |
267 (forward-line 1)) | 273 (forward-line 1)) |
268 (goto-char from) | 274 (goto-char from) |
269 (and (looking-at fpre) (goto-char (match-end 0))) | 275 (if (looking-at fpre) |
276 (goto-char (match-end 0))) | |
270 (setq from (point))))) | 277 (setq from (point))))) |
271 ;; Remove indentation from lines other than the first. | 278 ;; Remove indentation from lines other than the first. |
272 (beginning-of-line 2) | 279 (beginning-of-line 2) |
273 (indent-region (point) (point-max) 0) | 280 (indent-region (point) (point-max) 0) |
274 (goto-char from) | 281 (goto-char from) |
284 (skip-chars-forward " \t") | 291 (skip-chars-forward " \t") |
285 ;; Then change all newlines to spaces. | 292 ;; Then change all newlines to spaces. |
286 (subst-char-in-region from (point-max) ?\n ?\ ) | 293 (subst-char-in-region from (point-max) ?\n ?\ ) |
287 (if (and nosqueeze (not (eq justify 'full))) | 294 (if (and nosqueeze (not (eq justify 'full))) |
288 nil | 295 nil |
289 (canonically-space-region (point) (point-max)) | 296 (canonically-space-region (or squeeze-after (point)) (point-max)) |
290 (goto-char (point-max)) | 297 (goto-char (point-max)) |
291 (delete-horizontal-space) | 298 (delete-horizontal-space) |
292 (insert-and-inherit " ")) | 299 (insert-and-inherit " ")) |
293 (goto-char (point-min)) | 300 (goto-char (point-min)) |
294 | 301 |