diff options
| author | Richard M. Stallman | 1993-07-26 07:10:13 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1993-07-26 07:10:13 +0000 |
| commit | 3bbf636395b25f35d1c2e9b7a4bc57bc798a1cfd (patch) | |
| tree | c4fd01d9ce9673a5d2b25ba226a400b535733e5f | |
| parent | 83e37cb6e8a87f9197fb8bdf14ff672b4c3c9f1d (diff) | |
| download | emacs-3bbf636395b25f35d1c2e9b7a4bc57bc798a1cfd.tar.gz emacs-3bbf636395b25f35d1c2e9b7a4bc57bc798a1cfd.zip | |
(indent-c-exp): When previous line ends in comma,
use calculate-c-indent. Fix the "inner loop" to properly detect
a line that ends outside of comments and strings.
| -rw-r--r-- | lisp/progmodes/c-mode.el | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lisp/progmodes/c-mode.el b/lisp/progmodes/c-mode.el index d9c673cd384..9b20d6f72d9 100644 --- a/lisp/progmodes/c-mode.el +++ b/lisp/progmodes/c-mode.el | |||
| @@ -989,7 +989,7 @@ ENDPOS is encountered." | |||
| 989 | restart outer-loop-done inner-loop-done state ostate | 989 | restart outer-loop-done inner-loop-done state ostate |
| 990 | this-indent last-sexp | 990 | this-indent last-sexp |
| 991 | at-else at-brace at-while | 991 | at-else at-brace at-while |
| 992 | last-depth | 992 | last-depth this-point |
| 993 | (next-depth 0)) | 993 | (next-depth 0)) |
| 994 | ;; If the braces don't match, get an error right away. | 994 | ;; If the braces don't match, get an error right away. |
| 995 | (save-excursion | 995 | (save-excursion |
| @@ -1033,9 +1033,12 @@ ENDPOS is encountered." | |||
| 1033 | (if (and (car (cdr (cdr state))) | 1033 | (if (and (car (cdr (cdr state))) |
| 1034 | (>= (car (cdr (cdr state))) 0)) | 1034 | (>= (car (cdr (cdr state))) 0)) |
| 1035 | (setq last-sexp (car (cdr (cdr state))))) | 1035 | (setq last-sexp (car (cdr (cdr state))))) |
| 1036 | (if (or (nth 4 ostate)) | 1036 | ;; If this line started within a comment, indent it as such. |
| 1037 | (if (or (nth 4 ostate) (nth 7 ostate)) | ||
| 1037 | (c-indent-line)) | 1038 | (c-indent-line)) |
| 1038 | (if (or (nth 3 state)) | 1039 | ;; If it ends outside of comments or strings, exit the inner loop. |
| 1040 | ;; Otherwise move on to next line. | ||
| 1041 | (if (or (nth 3 state) (nth 4 state) (nth 7 state)) | ||
| 1039 | (forward-line 1) | 1042 | (forward-line 1) |
| 1040 | (setq inner-loop-done t))) | 1043 | (setq inner-loop-done t))) |
| 1041 | (and endpos | 1044 | (and endpos |
| @@ -1085,6 +1088,7 @@ ENDPOS is encountered." | |||
| 1085 | ;; Is it a new statement? Is it an else? | 1088 | ;; Is it a new statement? Is it an else? |
| 1086 | ;; Find last non-comment character before this line | 1089 | ;; Find last non-comment character before this line |
| 1087 | (save-excursion | 1090 | (save-excursion |
| 1091 | (setq this-point (point)) | ||
| 1088 | (setq at-else (looking-at "else\\W")) | 1092 | (setq at-else (looking-at "else\\W")) |
| 1089 | (setq at-brace (= (following-char) ?{)) | 1093 | (setq at-brace (= (following-char) ?{)) |
| 1090 | (setq at-while (looking-at "while\\b")) | 1094 | (setq at-while (looking-at "while\\b")) |
| @@ -1105,6 +1109,9 @@ ENDPOS is encountered." | |||
| 1105 | (current-indentation)))) | 1109 | (current-indentation)))) |
| 1106 | ((and at-while (c-backward-to-start-of-do opoint)) | 1110 | ((and at-while (c-backward-to-start-of-do opoint)) |
| 1107 | (setq this-indent (current-indentation))) | 1111 | (setq this-indent (current-indentation))) |
| 1112 | ((eq (preceding-char) ?\,) | ||
| 1113 | (goto-char this-point) | ||
| 1114 | (setq this-indent (calculate-c-indent))) | ||
| 1108 | (t (setq this-indent (car indent-stack))))))) | 1115 | (t (setq this-indent (car indent-stack))))))) |
| 1109 | ;; Just started a new nesting level. | 1116 | ;; Just started a new nesting level. |
| 1110 | ;; Compute the standard indent for this level. | 1117 | ;; Compute the standard indent for this level. |