Fix c-family closing brace indent behaviour on some corner cases
This commit is contained in:
parent
5b1ad0bd0c
commit
18d4c40f08
|
@ -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 %[
|
||||
|
|
12
test/indent/c-family/close-block/in
Normal file
12
test/indent/c-family/close-block/in
Normal file
|
@ -0,0 +1,12 @@
|
|||
struct A
|
||||
{
|
||||
int i%(;)
|
||||
|
||||
if (true) {
|
||||
if (true) {
|
||||
foo%(;)
|
||||
bar%(;)
|
||||
|
||||
foo(bar) {}
|
||||
{
|
||||
baz%(;)
|
16
test/indent/c-family/close-block/out
Normal file
16
test/indent/c-family/close-block/out
Normal file
|
@ -0,0 +1,16 @@
|
|||
struct A
|
||||
{
|
||||
int i;
|
||||
};
|
||||
|
||||
if (true) {
|
||||
if (true) {
|
||||
foo;
|
||||
}
|
||||
bar;
|
||||
}
|
||||
|
||||
foo(bar) {}
|
||||
{
|
||||
baz;
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
struct A
|
||||
{
|
||||
int i%(;)
|
|
@ -1,4 +0,0 @@
|
|||
struct A
|
||||
{
|
||||
int i;
|
||||
};
|
|
@ -13,3 +13,7 @@ if (1) {
|
|||
|
||||
if (1) {
|
||||
bar()%( )}
|
||||
|
||||
foo(bar) {}
|
||||
{
|
||||
baz%( )}
|
||||
|
|
|
@ -19,3 +19,8 @@ if (1) {
|
|||
if (1) {
|
||||
bar()
|
||||
}
|
||||
|
||||
foo(bar) {}
|
||||
{
|
||||
baz
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user