diff --git a/rc/filetype/c-family.kak b/rc/filetype/c-family.kak index 3682d323..e7c440ba 100644 --- a/rc/filetype/c-family.kak +++ b/rc/filetype/c-family.kak @@ -122,14 +122,17 @@ define-command -hidden c-family-indent-on-opening-curly-brace %[ ] define-command -hidden c-family-indent-on-closing-curly-brace %[ - # align to opening curly brace when alone on a line - try %[ - # in case open curly brace follows a closing paren, align indent with opening paren - execute-keys -itersel -draft ^\h+\}$hm )M \A\(.*\)\h\{.*\}\z 1 - ] catch %[ - # otherwise align with open curly brace - execute-keys -itersel -draft ^\h+\}$hm1 - ] catch %[] + evaluate-commands -draft -itersel -verbatim try %[ + # check if alone on the line and select to opening curly brace + execute-keys ^\h+\}$hm + try %[ + # in case open curly brace follows a closing paren, extend to opening paren + execute-keys -draft ) \A\)\h+\{\z + execute-keys )M + ] + # align to selection start + execute-keys 1 + ] ] define-command -hidden c-family-insert-on-closing-curly-brace %[ diff --git a/test/indent/c-family/close-struct/cmd b/test/indent/c-family/close-block/cmd similarity index 100% rename from test/indent/c-family/close-struct/cmd rename to test/indent/c-family/close-block/cmd diff --git a/test/indent/c-family/close-block/in b/test/indent/c-family/close-block/in new file mode 100644 index 00000000..bc0901e8 --- /dev/null +++ b/test/indent/c-family/close-block/in @@ -0,0 +1,12 @@ +struct A +{ + int i%(;) + +if (true) { + if (true) { + foo%(;) + bar%(;) + + foo(bar) {} +{ + baz%(;) diff --git a/test/indent/c-family/close-block/out b/test/indent/c-family/close-block/out new file mode 100644 index 00000000..b207dfd6 --- /dev/null +++ b/test/indent/c-family/close-block/out @@ -0,0 +1,16 @@ +struct A +{ + int i; +}; + +if (true) { + if (true) { + foo; + } + bar; +} + + foo(bar) {} +{ + baz; +} diff --git a/test/indent/c-family/close-struct/rc b/test/indent/c-family/close-block/rc similarity index 100% rename from test/indent/c-family/close-struct/rc rename to test/indent/c-family/close-block/rc diff --git a/test/indent/c-family/close-struct/in b/test/indent/c-family/close-struct/in deleted file mode 100644 index 149f2a22..00000000 --- a/test/indent/c-family/close-struct/in +++ /dev/null @@ -1,3 +0,0 @@ -struct A -{ - int i%(;) diff --git a/test/indent/c-family/close-struct/out b/test/indent/c-family/close-struct/out deleted file mode 100644 index 67c4f51a..00000000 --- a/test/indent/c-family/close-struct/out +++ /dev/null @@ -1,4 +0,0 @@ -struct A -{ - int i; -}; diff --git a/test/indent/c-family/deindent-if-closing-brace/in b/test/indent/c-family/deindent-if-closing-brace/in index 5ac38a34..f200dda6 100644 --- a/test/indent/c-family/deindent-if-closing-brace/in +++ b/test/indent/c-family/deindent-if-closing-brace/in @@ -13,3 +13,7 @@ if (1) { if (1) { bar()%( )} + + foo(bar) {} + { + baz%( )} diff --git a/test/indent/c-family/deindent-if-closing-brace/out b/test/indent/c-family/deindent-if-closing-brace/out index d46b84cf..edd7dfa3 100644 --- a/test/indent/c-family/deindent-if-closing-brace/out +++ b/test/indent/c-family/deindent-if-closing-brace/out @@ -19,3 +19,8 @@ if (1) { if (1) { bar() } + + foo(bar) {} + { + baz + }