diff options
| author | Richard M. Stallman | 1995-01-19 04:21:56 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1995-01-19 04:21:56 +0000 |
| commit | eed5698bea36b5a87672c4e6bb64d3d0eefa3212 (patch) | |
| tree | d124c08fa202bafbd4dce514bf8f6be9231368e7 | |
| parent | 0cb08f98380da55714e253028eaf57c5b6afa217 (diff) | |
| download | emacs-eed5698bea36b5a87672c4e6bb64d3d0eefa3212.tar.gz emacs-eed5698bea36b5a87672c4e6bb64d3d0eefa3212.zip | |
(do-auto-fill): Fill, don't fill, or fill-and-justify
depending on setting of justification text-property. Respect
left-margin and right-margin text properties.
(open-line, indent-new-comment-line): Inherit when inserting.
(newline-and-indent, reindent-then-newline-and-indent): Doc fix.
| -rw-r--r-- | lisp/simple.el | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/lisp/simple.el b/lisp/simple.el index 6beae8b9464..40845d0c10c 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -34,7 +34,7 @@ With arg N, insert N newlines." | |||
| 34 | (let* ((do-fill-prefix (and fill-prefix (bolp))) | 34 | (let* ((do-fill-prefix (and fill-prefix (bolp))) |
| 35 | (loc (point))) | 35 | (loc (point))) |
| 36 | (while (> arg 0) | 36 | (while (> arg 0) |
| 37 | (if do-fill-prefix (insert fill-prefix)) | 37 | (if do-fill-prefix (insert-and-inherit fill-prefix)) |
| 38 | (newline 1) | 38 | (newline 1) |
| 39 | (setq arg (1- arg))) | 39 | (setq arg (1- arg))) |
| 40 | (goto-char loc)) | 40 | (goto-char loc)) |
| @@ -170,7 +170,7 @@ On nonblank line, delete any immediately following blank lines." | |||
| 170 | Indentation is done using the value of `indent-line-function'. | 170 | Indentation is done using the value of `indent-line-function'. |
| 171 | In programming language modes, this is the same as TAB. | 171 | In programming language modes, this is the same as TAB. |
| 172 | In some text modes, where TAB inserts a tab, this command indents to the | 172 | In some text modes, where TAB inserts a tab, this command indents to the |
| 173 | column specified by the variable `left-margin'." | 173 | column specified by the function `current-left-margin'." |
| 174 | (interactive "*") | 174 | (interactive "*") |
| 175 | (delete-region (point) (progn (skip-chars-backward " \t") (point))) | 175 | (delete-region (point) (progn (skip-chars-backward " \t") (point))) |
| 176 | (newline) | 176 | (newline) |
| @@ -182,7 +182,7 @@ Indentation of both lines is done according to the current major mode, | |||
| 182 | which means calling the current value of `indent-line-function'. | 182 | which means calling the current value of `indent-line-function'. |
| 183 | In programming language modes, this is the same as TAB. | 183 | In programming language modes, this is the same as TAB. |
| 184 | In some text modes, where TAB inserts a tab, this indents to the | 184 | In some text modes, where TAB inserts a tab, this indents to the |
| 185 | column specified by the variable `left-margin'." | 185 | column specified by the function `current-left-margin'." |
| 186 | (interactive "*") | 186 | (interactive "*") |
| 187 | (save-excursion | 187 | (save-excursion |
| 188 | (delete-region (point) (progn (skip-chars-backward " \t") (point))) | 188 | (delete-region (point) (progn (skip-chars-backward " \t") (point))) |
| @@ -2162,18 +2162,31 @@ Setting this variable automatically makes it local to the current buffer.") | |||
| 2162 | "*Regexp to match lines which should not be auto-filled.") | 2162 | "*Regexp to match lines which should not be auto-filled.") |
| 2163 | 2163 | ||
| 2164 | (defun do-auto-fill () | 2164 | (defun do-auto-fill () |
| 2165 | (let (give-up) | 2165 | (let (fc justify bol give-up) |
| 2166 | (or (and auto-fill-inhibit-regexp | 2166 | (if (or (not (setq justify (justification))) |
| 2167 | (save-excursion (beginning-of-line) | 2167 | (and (setq fc (current-fill-column)) ; make sure this gets set |
| 2168 | (looking-at auto-fill-inhibit-regexp))) | 2168 | (eq justify 'left) |
| 2169 | (while (and (not give-up) (> (current-column) fill-column)) | 2169 | (<= (current-column) (setq fc (current-fill-column)))) |
| 2170 | (save-excursion (beginning-of-line) | ||
| 2171 | (setq bol (point)) | ||
| 2172 | (and auto-fill-inhibit-regexp | ||
| 2173 | (looking-at auto-fill-inhibit-regexp)))) | ||
| 2174 | nil ;; Auto-filling not required | ||
| 2175 | ;; Remove justification-introduced whitespace before filling | ||
| 2176 | (cond ((eq 'left justify) nil) | ||
| 2177 | ((eq 'full justify) ; full justify: remove extra spaces | ||
| 2178 | (canonically-space-region | ||
| 2179 | (point) (save-excursion (end-of-line) (point)))) | ||
| 2180 | ;; right or center justify: remove extra indentation. | ||
| 2181 | (t (save-excursion (indent-according-to-mode)))) | ||
| 2182 | (while (and (not give-up) (> (current-column) fc)) | ||
| 2170 | ;; Determine where to split the line. | 2183 | ;; Determine where to split the line. |
| 2171 | (let ((fill-point | 2184 | (let ((fill-point |
| 2172 | (let ((opoint (point)) | 2185 | (let ((opoint (point)) |
| 2173 | bounce | 2186 | bounce |
| 2174 | (first t)) | 2187 | (first t)) |
| 2175 | (save-excursion | 2188 | (save-excursion |
| 2176 | (move-to-column (1+ fill-column)) | 2189 | (move-to-column (1+ fc)) |
| 2177 | ;; Move back to a word boundary. | 2190 | ;; Move back to a word boundary. |
| 2178 | (while (or first | 2191 | (while (or first |
| 2179 | ;; If this is after period and a single space, | 2192 | ;; If this is after period and a single space, |
| @@ -2214,18 +2227,25 @@ Setting this variable automatically makes it local to the current buffer.") | |||
| 2214 | (save-excursion | 2227 | (save-excursion |
| 2215 | (goto-char fill-point) | 2228 | (goto-char fill-point) |
| 2216 | (indent-new-comment-line t))) | 2229 | (indent-new-comment-line t))) |
| 2230 | ;; Now do justification, if required | ||
| 2231 | (if (not (eq justify 'left)) | ||
| 2232 | (save-excursion | ||
| 2233 | (end-of-line 0) | ||
| 2234 | (justify-current-line justify nil t))) | ||
| 2217 | ;; If making the new line didn't reduce the hpos of | 2235 | ;; If making the new line didn't reduce the hpos of |
| 2218 | ;; the end of the line, then give up now; | 2236 | ;; the end of the line, then give up now; |
| 2219 | ;; trying again will not help. | 2237 | ;; trying again will not help. |
| 2220 | (if (>= (current-column) prev-column) | 2238 | (if (>= (current-column) prev-column) |
| 2221 | (setq give-up t))) | 2239 | (setq give-up t))) |
| 2222 | ;; No place to break => stop trying. | 2240 | ;; No place to break => stop trying. |
| 2223 | (setq give-up t))))))) | 2241 | (setq give-up t)))) |
| 2242 | ;; justify last line | ||
| 2243 | (justify-current-line justify t t)))) | ||
| 2224 | 2244 | ||
| 2225 | (defun auto-fill-mode (&optional arg) | 2245 | (defun auto-fill-mode (&optional arg) |
| 2226 | "Toggle auto-fill mode. | 2246 | "Toggle auto-fill mode. |
| 2227 | With arg, turn Auto-Fill mode on if and only if arg is positive. | 2247 | With arg, turn Auto-Fill mode on if and only if arg is positive. |
| 2228 | In Auto-Fill mode, inserting a space at a column beyond `fill-column' | 2248 | In Auto-Fill mode, inserting a space at a column beyond `current-fill-column' |
| 2229 | automatically breaks the line at a previous space." | 2249 | automatically breaks the line at a previous space." |
| 2230 | (interactive "P") | 2250 | (interactive "P") |
| 2231 | (prog1 (setq auto-fill-function | 2251 | (prog1 (setq auto-fill-function |
| @@ -2275,7 +2295,7 @@ unless optional argument SOFT is non-nil." | |||
| 2275 | (delete-region (point) | 2295 | (delete-region (point) |
| 2276 | (progn (skip-chars-forward " \t") | 2296 | (progn (skip-chars-forward " \t") |
| 2277 | (point))) | 2297 | (point))) |
| 2278 | (if soft (insert ?\n) (newline 1)) | 2298 | (if soft (insert-and-inherit ?\n) (newline 1)) |
| 2279 | (if (not comment-multi-line) | 2299 | (if (not comment-multi-line) |
| 2280 | (save-excursion | 2300 | (save-excursion |
| 2281 | (if (and comment-start-skip | 2301 | (if (and comment-start-skip |
| @@ -2314,7 +2334,7 @@ unless optional argument SOFT is non-nil." | |||
| 2314 | ) | 2334 | ) |
| 2315 | (if (not (eolp)) | 2335 | (if (not (eolp)) |
| 2316 | (setq comment-end "")) | 2336 | (setq comment-end "")) |
| 2317 | (insert ?\n) | 2337 | (insert-and-inherit ?\n) |
| 2318 | (forward-char -1) | 2338 | (forward-char -1) |
| 2319 | (indent-for-comment) | 2339 | (indent-for-comment) |
| 2320 | (save-excursion | 2340 | (save-excursion |
| @@ -2322,7 +2342,7 @@ unless optional argument SOFT is non-nil." | |||
| 2322 | (end-of-line) | 2342 | (end-of-line) |
| 2323 | (delete-char 1))) | 2343 | (delete-char 1))) |
| 2324 | (if fill-prefix | 2344 | (if fill-prefix |
| 2325 | (insert fill-prefix) | 2345 | (insert-and-inherit fill-prefix) |
| 2326 | (indent-according-to-mode))))) | 2346 | (indent-according-to-mode))))) |
| 2327 | 2347 | ||
| 2328 | (defun set-selective-display (arg) | 2348 | (defun set-selective-display (arg) |