Smarter align to opening parenthesis/brace supporting multiline

This commit is contained in:
Maxime Coste 2017-05-21 22:31:05 +01:00
parent ad9ad7e603
commit 2f9b77b748
5 changed files with 24 additions and 2 deletions

View File

@ -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> > 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 # 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> > 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 # on a previous line if its followed by text on the same line
try %< eval -draft %< 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 > 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 &
> > > >
> > > >

View File

@ -0,0 +1 @@
c<ret>qiz<esc>

View File

@ -0,0 +1,5 @@
foo{bar(baz,
qux),%( )
foo(bar{baz,
qux},%( )

View File

@ -0,0 +1,7 @@
foo{bar(baz,
qux),
qiz
foo(bar{baz,
qux},
qiz

View File

@ -0,0 +1,3 @@
source "%val{runtime}/colors/default.kak"
source "%val{runtime}/rc/core/c-family.kak"
set buffer filetype cpp