diff --git a/rc/core/c-family.kak b/rc/core/c-family.kak index def12daa0..19d9750b6 100644 --- a/rc/core/c-family.kak +++ b/rc/core/c-family.kak @@ -48,6 +48,8 @@ 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 \b(if|else|for|while)\h*\(.+?\)\h*$ j > + # deindent after a single line statement end + try %< execute-keys -draft K \;\h*$ K s\b(if|else|for|while)\h*\(.*\)\h*$|.\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/cmd b/test/indent/c-family/deindent-if-body/cmd new file mode 100644 index 000000000..b11ad9949 --- /dev/null +++ b/test/indent/c-family/deindent-if-body/cmd @@ -0,0 +1 @@ +cbaz diff --git a/test/indent/c-family/deindent-if-body/in b/test/indent/c-family/deindent-if-body/in new file mode 100644 index 000000000..3a64ea8b8 --- /dev/null +++ b/test/indent/c-family/deindent-if-body/in @@ -0,0 +1,2 @@ +if (int i = bar()) + foo();%( ) diff --git a/test/indent/c-family/deindent-if-body/out b/test/indent/c-family/deindent-if-body/out new file mode 100644 index 000000000..62a0612fe --- /dev/null +++ b/test/indent/c-family/deindent-if-body/out @@ -0,0 +1,3 @@ +if (int i = bar()) + foo(); +baz diff --git a/test/indent/c-family/deindent-if-body/rc b/test/indent/c-family/deindent-if-body/rc new file mode 100644 index 000000000..53c40654e --- /dev/null +++ b/test/indent/c-family/deindent-if-body/rc @@ -0,0 +1,3 @@ +source "%val{runtime}/colors/default.kak" +source "%val{runtime}/rc/core/c-family.kak" +set buffer filetype cpp diff --git a/test/indent/c-family/deindent-if-body/state b/test/indent/c-family/deindent-if-body/state new file mode 100644 index 000000000..88f47c8ab --- /dev/null +++ b/test/indent/c-family/deindent-if-body/state @@ -0,0 +1 @@ +3.4,3.4