Mercurial > emacs
comparison lisp/simple.el @ 10469:2546bad34200
(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.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 19 Jan 1995 04:21:56 +0000 |
parents | 3c447e2caef3 |
children | 3eb77f03f53e |
comparison
equal
deleted
inserted
replaced
10468:d0854b6f3216 | 10469:2546bad34200 |
---|---|
32 With arg N, insert N newlines." | 32 With arg N, insert N newlines." |
33 (interactive "*p") | 33 (interactive "*p") |
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)) |
41 (end-of-line)) | 41 (end-of-line)) |
42 | 42 |
168 (defun newline-and-indent () | 168 (defun newline-and-indent () |
169 "Insert a newline, then indent according to major mode. | 169 "Insert a newline, then indent according to major mode. |
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) |
177 (indent-according-to-mode)) | 177 (indent-according-to-mode)) |
178 | 178 |
180 "Reindent current line, insert newline, then indent the new line. | 180 "Reindent current line, insert newline, then indent the new line. |
181 Indentation of both lines is done according to the current major mode, | 181 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))) |
189 (indent-according-to-mode)) | 189 (indent-according-to-mode)) |
190 (newline) | 190 (newline) |
2160 | 2160 |
2161 (defconst auto-fill-inhibit-regexp nil | 2161 (defconst auto-fill-inhibit-regexp nil |
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, |
2180 ;; move back once more--we don't want to break | 2193 ;; move back once more--we don't want to break |
2181 ;; the line there and make it look like a | 2194 ;; the line there and make it look like a |
2212 (= (point) fill-point)) | 2225 (= (point) fill-point)) |
2213 (indent-new-comment-line t) | 2226 (indent-new-comment-line t) |
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 |
2232 (if (if (null arg) | 2252 (if (if (null arg) |
2233 (not auto-fill-function) | 2253 (not auto-fill-function) |
2273 (let (comcol comstart) | 2293 (let (comcol comstart) |
2274 (skip-chars-backward " \t") | 2294 (skip-chars-backward " \t") |
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 |
2282 (let ((opoint (point))) | 2302 (let ((opoint (point))) |
2283 (forward-line -1) | 2303 (forward-line -1) |
2312 ; comment-start "") | 2332 ; comment-start "") |
2313 ; ) | 2333 ; ) |
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 |
2321 ;; Make sure we delete the newline inserted above. | 2341 ;; Make sure we delete the newline inserted above. |
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) |
2329 "Set `selective-display' to ARG; clear it if no arg. | 2349 "Set `selective-display' to ARG; clear it if no arg. |
2330 When the value of `selective-display' is a number > 0, | 2350 When the value of `selective-display' is a number > 0, |