Smarter align to opening parenthesis/brace supporting multiline
This commit is contained in:
parent
ad9ad7e603
commit
2f9b77b748
|
@ -45,11 +45,17 @@ def -hidden c-family-indent-on-newline %< eval -draft -itersel %<
|
|||
try %< exec -draft k <a-x> s[a-zA-Z0-9_-]+:\h*$<ret> j <a-gt> >
|
||||
# indent after a statement not followed by an opening brace
|
||||
try %< exec -draft k <a-x> <a-k>\b(if|else|for|while)\h*\(.+?\)\h*$<ret> j <a-gt> >
|
||||
# align to the opening parenthesis or opening bracket (whichever is first)
|
||||
# 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 %< eval -draft %<
|
||||
# Go to opening parenthesis and opening brace, then select the most nested one
|
||||
try %< exec [bZ<a-\;>[B<a-z><gt> > catch %< exec [B >
|
||||
exec <a-k>\`[{(][^\n]+\n[^\n]*\n?\'<ret> L s\`|.\'<ret> &
|
||||
# Validate selection and get first and last char
|
||||
exec <a-k>\`[{(](\h*\S+)+\n<ret> L s\`|.\'<ret>
|
||||
# Remove eventual indent from new line
|
||||
try %< exec -draft <space> <a-h> s\h+<ret> d >
|
||||
# Now align that new line with the opening parenthesis/brace
|
||||
exec &
|
||||
> >
|
||||
> >
|
||||
|
||||
|
|
1
test/indent/c-family/multiline-nested-align/cmd
Normal file
1
test/indent/c-family/multiline-nested-align/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
c<ret>qiz<esc>
|
5
test/indent/c-family/multiline-nested-align/in
Normal file
5
test/indent/c-family/multiline-nested-align/in
Normal file
|
@ -0,0 +1,5 @@
|
|||
foo{bar(baz,
|
||||
qux),%( )
|
||||
|
||||
foo(bar{baz,
|
||||
qux},%( )
|
7
test/indent/c-family/multiline-nested-align/out
Normal file
7
test/indent/c-family/multiline-nested-align/out
Normal file
|
@ -0,0 +1,7 @@
|
|||
foo{bar(baz,
|
||||
qux),
|
||||
qiz
|
||||
|
||||
foo(bar{baz,
|
||||
qux},
|
||||
qiz
|
3
test/indent/c-family/multiline-nested-align/rc
Normal file
3
test/indent/c-family/multiline-nested-align/rc
Normal file
|
@ -0,0 +1,3 @@
|
|||
source "%val{runtime}/colors/default.kak"
|
||||
source "%val{runtime}/rc/core/c-family.kak"
|
||||
set buffer filetype cpp
|
Loading…
Reference in New Issue
Block a user