Fix c-family closing brace indent behaviour on some corner cases

This commit is contained in:
Maxime Coste 2023-06-15 17:41:46 +10:00
parent 5b1ad0bd0c
commit 18d4c40f08
9 changed files with 48 additions and 15 deletions

View File

@ -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 <a-h><a-:><a-k>^\h+\}$<ret>hm <a-F>)M <a-k> \A\(.*\)\h\{.*\}\z <ret> <a-S>1<a-&>
] catch %[
# otherwise align with open curly brace
execute-keys -itersel -draft <a-h><a-:><a-k>^\h+\}$<ret>hm<a-S>1<a-&>
] catch %[]
evaluate-commands -draft -itersel -verbatim try %[
# check if alone on the line and select to opening curly brace
execute-keys <a-h><a-:><a-k>^\h+\}$<ret>hm
try %[
# in case open curly brace follows a closing paren, extend to opening paren
execute-keys -draft <a-f>) <a-k> \A\)\h+\{\z <ret>
execute-keys <a-F>)M
]
# align to selection start
execute-keys <a-S>1<a-&>
]
]
define-command -hidden c-family-insert-on-closing-curly-brace %[

View File

@ -0,0 +1,12 @@
struct A
{
int i%(;)
if (true) {
if (true) {
foo%(;)
bar%(;)
foo(bar) {}
{
baz%(;)

View File

@ -0,0 +1,16 @@
struct A
{
int i;
};
if (true) {
if (true) {
foo;
}
bar;
}
foo(bar) {}
{
baz;
}

View File

@ -1,3 +0,0 @@
struct A
{
int i%(;)

View File

@ -1,4 +0,0 @@
struct A
{
int i;
};

View File

@ -13,3 +13,7 @@ if (1) {
if (1) {
bar()%( )}
foo(bar) {}
{
baz%( )}

View File

@ -19,3 +19,8 @@ if (1) {
if (1) {
bar()
}
foo(bar) {}
{
baz
}