diff --git a/rc/core/c-family.kak b/rc/core/c-family.kak index def12daa..19d9750b 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 00000000..b11ad994 --- /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 00000000..3a64ea8b --- /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 00000000..62a0612f --- /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 00000000..53c40654 --- /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 00000000..88f47c8a --- /dev/null +++ b/test/indent/c-family/deindent-if-body/state @@ -0,0 +1 @@ +3.4,3.4