diff --git a/rc/core/c-family.kak b/rc/core/c-family.kak index cc101984..1aee07a9 100644 --- a/rc/core/c-family.kak +++ b/rc/core/c-family.kak @@ -49,11 +49,16 @@ define-command -hidden c-family-indent-on-newline %< evaluate-commands -draft -i try %< execute-keys -draft k s[a-zA-Z0-9_-]+:\h*$ j > # indent after a statement not followed by an opening brace try %< execute-keys -draft k s\)\h*(?://[^\n]+)?\n\z \ - mB \A\b(if|else|for|while)\b j > + mB \A\b(if|for|while)\b j > + try %< execute-keys -draft k s \belse\b\h*(?://[^\n]+)?\n\z \ + j > # deindent after a single line statement end try %< execute-keys -draft K \;\h*(//[^\n]+)?$ \ K s\)(\h+\w+)*\h*(//[^\n]+)?\n([^\n]*\n){2}\z \ - MB \A\b(if|else|for|while)\b 1 > + MB \A\b(if|for|while)\b 1 > + try %< execute-keys -draft K \;\h*(//[^\n]+)?$ \ + K s \belse\b\h*(?://[^\n]+)?\n([^\n]*\n){2}\z \ + 1 > # align to the opening parenthesis or opening brace (whichever is first) # on a previous line if its followed by text on the same line try %< evaluate-commands -draft %< diff --git a/test/indent/c-family/deindent-if-body/in b/test/indent/c-family/deindent-if-body/in index 5b2cc138..71c9ed0d 100644 --- a/test/indent/c-family/deindent-if-body/in +++ b/test/indent/c-family/deindent-if-body/in @@ -8,3 +8,9 @@ if (bar(a, b, if (bar(a, b, c, d)) // comment foo();%( ) + +else + bar();%( ) + +else // comment + bar();%( ) diff --git a/test/indent/c-family/deindent-if-body/out b/test/indent/c-family/deindent-if-body/out index 543b5aa1..f8d662a1 100644 --- a/test/indent/c-family/deindent-if-body/out +++ b/test/indent/c-family/deindent-if-body/out @@ -11,3 +11,11 @@ if (bar(a, b, c, d)) // comment foo(); baz + +else + bar(); +baz + +else // comment + bar(); +baz diff --git a/test/indent/c-family/indent-if-body/in b/test/indent/c-family/indent-if-body/in index 0ac6763a..7ce06395 100644 --- a/test/indent/c-family/indent-if-body/in +++ b/test/indent/c-family/indent-if-body/in @@ -5,3 +5,7 @@ if (bar(a, b, if (bar(a, b, c, d)) // comment%( ) + +else%( ) + +else // comment%( ) diff --git a/test/indent/c-family/indent-if-body/out b/test/indent/c-family/indent-if-body/out index 3b4b466f..c638be41 100644 --- a/test/indent/c-family/indent-if-body/out +++ b/test/indent/c-family/indent-if-body/out @@ -8,3 +8,9 @@ if (bar(a, b, if (bar(a, b, c, d)) // comment foo + +else + foo + +else // comment + foo