Commit 3bbf6363 authored by Richard M. Stallman's avatar Richard M. Stallman
Browse files

(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.
parent 83e37cb6
...@@ -989,7 +989,7 @@ ENDPOS is encountered." ...@@ -989,7 +989,7 @@ ENDPOS is encountered."
restart outer-loop-done inner-loop-done state ostate restart outer-loop-done inner-loop-done state ostate
this-indent last-sexp this-indent last-sexp
at-else at-brace at-while at-else at-brace at-while
last-depth last-depth this-point
(next-depth 0)) (next-depth 0))
;; If the braces don't match, get an error right away. ;; If the braces don't match, get an error right away.
(save-excursion (save-excursion
...@@ -1033,9 +1033,12 @@ ENDPOS is encountered." ...@@ -1033,9 +1033,12 @@ ENDPOS is encountered."
(if (and (car (cdr (cdr state))) (if (and (car (cdr (cdr state)))
(>= (car (cdr (cdr state))) 0)) (>= (car (cdr (cdr state))) 0))
(setq last-sexp (car (cdr (cdr state))))) (setq last-sexp (car (cdr (cdr state)))))
(if (or (nth 4 ostate)) ;; If this line started within a comment, indent it as such.
(if (or (nth 4 ostate) (nth 7 ostate))
(c-indent-line)) (c-indent-line))
(if (or (nth 3 state)) ;; If it ends outside of comments or strings, exit the inner loop.
;; Otherwise move on to next line.
(if (or (nth 3 state) (nth 4 state) (nth 7 state))
(forward-line 1) (forward-line 1)
(setq inner-loop-done t))) (setq inner-loop-done t)))
(and endpos (and endpos
...@@ -1085,6 +1088,7 @@ ENDPOS is encountered." ...@@ -1085,6 +1088,7 @@ ENDPOS is encountered."
;; Is it a new statement? Is it an else? ;; Is it a new statement? Is it an else?
;; Find last non-comment character before this line ;; Find last non-comment character before this line
(save-excursion (save-excursion
(setq this-point (point))
(setq at-else (looking-at "else\\W")) (setq at-else (looking-at "else\\W"))
(setq at-brace (= (following-char) ?{)) (setq at-brace (= (following-char) ?{))
(setq at-while (looking-at "while\\b")) (setq at-while (looking-at "while\\b"))
...@@ -1105,6 +1109,9 @@ ENDPOS is encountered." ...@@ -1105,6 +1109,9 @@ ENDPOS is encountered."
(current-indentation)))) (current-indentation))))
((and at-while (c-backward-to-start-of-do opoint)) ((and at-while (c-backward-to-start-of-do opoint))
(setq this-indent (current-indentation))) (setq this-indent (current-indentation)))
((eq (preceding-char) ?\,)
(goto-char this-point)
(setq this-indent (calculate-c-indent)))
(t (setq this-indent (car indent-stack))))))) (t (setq this-indent (car indent-stack)))))))
;; Just started a new nesting level. ;; Just started a new nesting level.
;; Compute the standard indent for this level. ;; Compute the standard indent for this level.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment