diff options
| author | Richard M. Stallman | 1993-08-02 07:44:36 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1993-08-02 07:44:36 +0000 |
| commit | eccf8697a79e0aa5dd98425e5cc5b2750ce5e308 (patch) | |
| tree | 459483bf92faea1991827a18f94b2ac973a9e69d | |
| parent | fa24a82290e79b24e3121bf1250d27a2a5526d7a (diff) | |
| download | emacs-eccf8697a79e0aa5dd98425e5cc5b2750ce5e308.tar.gz emacs-eccf8697a79e0aa5dd98425e5cc5b2750ce5e308.zip | |
(indent-c-exp): Don't document ENDPOS.
(c-indent-region): Rewrite to use indent-c-exp on one sexp at a time,
then use c-indent-line on the next line, etc.
| -rw-r--r-- | lisp/progmodes/c-mode.el | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/lisp/progmodes/c-mode.el b/lisp/progmodes/c-mode.el index bd4186aa90a..fa3e656fb24 100644 --- a/lisp/progmodes/c-mode.el +++ b/lisp/progmodes/c-mode.el | |||
| @@ -957,10 +957,10 @@ If within a string or comment, move by sentences instead of statements." | |||
| 957 | (beginning-of-defun) | 957 | (beginning-of-defun) |
| 958 | (backward-paragraph)) | 958 | (backward-paragraph)) |
| 959 | 959 | ||
| 960 | ;; Idea of ENDPOS is, indent each line, stopping when | ||
| 961 | ;; ENDPOS is encountered. But it's too much of a pain to make that work. | ||
| 960 | (defun indent-c-exp (&optional endpos) | 962 | (defun indent-c-exp (&optional endpos) |
| 961 | "Indent each line of the C grouping following point. | 963 | "Indent each line of the C grouping following point." |
| 962 | If optional arg ENDPOS is given, indent each line, stopping when | ||
| 963 | ENDPOS is encountered." | ||
| 964 | (interactive) | 964 | (interactive) |
| 965 | (let* ((indent-stack (list nil)) | 965 | (let* ((indent-stack (list nil)) |
| 966 | (opoint (point)) ;; May be altered below. | 966 | (opoint (point)) ;; May be altered below. |
| @@ -1184,10 +1184,35 @@ ENDPOS is encountered." | |||
| 1184 | (defun c-indent-region (start end) | 1184 | (defun c-indent-region (start end) |
| 1185 | (save-excursion | 1185 | (save-excursion |
| 1186 | (goto-char start) | 1186 | (goto-char start) |
| 1187 | (let ((endmark (copy-marker end))) | 1187 | (let ((endmark (copy-marker end)) |
| 1188 | (and (bolp) (not (eolp)) | 1188 | (c-tab-always-indent t)) |
| 1189 | (c-indent-line)) | 1189 | (while (and (bolp) (not (eolp))) |
| 1190 | (indent-c-exp endmark) | 1190 | ;; Indent one line as with TAB. |
| 1191 | (let ((shift-amt (c-indent-line)) | ||
| 1192 | nextline sexpend) | ||
| 1193 | (save-excursion | ||
| 1194 | ;; Find beginning of following line. | ||
| 1195 | (save-excursion | ||
| 1196 | (forward-line 1) (setq nextline (point))) | ||
| 1197 | ;; Find first beginning-of-sexp for sexp extending past this line. | ||
| 1198 | (beginning-of-line) | ||
| 1199 | (while (< (point) nextline) | ||
| 1200 | (condition-case nil | ||
| 1201 | (progn | ||
| 1202 | (forward-sexp 1) | ||
| 1203 | (setq sexpend (point-marker))) | ||
| 1204 | (error (setq sexpend nil) | ||
| 1205 | (goto-char nextline))) | ||
| 1206 | (skip-chars-forward " \t\n"))) | ||
| 1207 | ;; If that sexp ends within the region, | ||
| 1208 | ;; indent it all at once, fast. | ||
| 1209 | (if (and sexpend (> sexpend nextline) (<= sexpend endmark)) | ||
| 1210 | (progn | ||
| 1211 | (indent-c-exp) | ||
| 1212 | (goto-char sexpend))) | ||
| 1213 | ;; Move to following line and try again. | ||
| 1214 | (and sexpend (set-marker sexpend nil)) | ||
| 1215 | (forward-line 1))) | ||
| 1191 | (set-marker endmark nil)))) | 1216 | (set-marker endmark nil)))) |
| 1192 | 1217 | ||
| 1193 | (defun set-c-style (style &optional global) | 1218 | (defun set-c-style (style &optional global) |