mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-25 04:24:48 +03:00
Support aligning to opening { as well as ( in c-family indent
This commit is contained in:
parent
b440d9f537
commit
cab0adaa53
@ -28,26 +28,27 @@ def -hidden c-family-trim-autoindent %[ eval -draft -itersel %[
|
||||
try %[ exec <a-x> 1s^(\h+)$<ret> d ]
|
||||
] ]
|
||||
|
||||
def -hidden c-family-indent-on-newline %[ eval -draft -itersel %[
|
||||
def -hidden c-family-indent-on-newline %< eval -draft -itersel %<
|
||||
exec \;
|
||||
try %[
|
||||
try %<
|
||||
# if previous line closed a paren, copy indent of the opening paren line
|
||||
exec -draft k<a-x> 1s(\))(\h+\w+)*\h*(\;\h*)?$<ret> m<a-\;>J s\`|.\'<ret> 1<a-&>
|
||||
] catch %[
|
||||
> catch %<
|
||||
# else indent new lines with the same level as the previous one
|
||||
exec -draft K <a-&>
|
||||
]
|
||||
>
|
||||
# remove previous empty lines resulting from the automatic indent
|
||||
try %[ exec -draft k <a-x> <a-k>^\h+$<ret> Hd ]
|
||||
try %< exec -draft k <a-x> <a-k>^\h+$<ret> Hd >
|
||||
# indent after an opening brace
|
||||
try %[ exec -draft k <a-x> s\{\h*$<ret> j <a-gt> ]
|
||||
try %< exec -draft k <a-x> s\{\h*$<ret> j <a-gt> >
|
||||
# indent after a label
|
||||
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
|
||||
try %[ exec -draft k <a-x> <a-k>\b(if|else|for|while)\h*\(.+?\)\h*$<ret> j <a-gt> ]
|
||||
# align to the opening parenthesis on a previous line if its followed by text on the same line
|
||||
try %[ exec -draft {b <a-k>\`\([^\n]+\n[^\n]*\n?\'<ret> L s\`|.\'<ret> & ]
|
||||
] ]
|
||||
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)
|
||||
# on a previous line if its followed by text on the same line
|
||||
try %< exec -draft [b Z<a-\;>[B<a-z><gt> <a-k>\`[{(][^\n]+\n[^\n]*\n?\'<ret> L s\`|.\'<ret> & >
|
||||
> >
|
||||
|
||||
def -hidden c-family-indent-on-opening-curly-brace %[
|
||||
# align indent with opening paren when { is entered on a new line after the closing paren
|
||||
|
1
test/indent/c-family/construct-align/cmd
Normal file
1
test/indent/c-family/construct-align/cmd
Normal file
@ -0,0 +1 @@
|
||||
c<ret><esc>
|
1
test/indent/c-family/construct-align/in
Normal file
1
test/indent/c-family/construct-align/in
Normal file
@ -0,0 +1 @@
|
||||
MyObject obj{param1,%( )param2};
|
2
test/indent/c-family/construct-align/out
Normal file
2
test/indent/c-family/construct-align/out
Normal file
@ -0,0 +1,2 @@
|
||||
MyObject obj{param1,
|
||||
param2};
|
3
test/indent/c-family/construct-align/rc
Normal file
3
test/indent/c-family/construct-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
|
1
test/indent/c-family/nested-align/cmd
Normal file
1
test/indent/c-family/nested-align/cmd
Normal file
@ -0,0 +1 @@
|
||||
c<ret>qux<esc>
|
3
test/indent/c-family/nested-align/in
Normal file
3
test/indent/c-family/nested-align/in
Normal file
@ -0,0 +1,3 @@
|
||||
foo{bar(baz,%( )
|
||||
|
||||
foo(bar{baz,%( )
|
5
test/indent/c-family/nested-align/out
Normal file
5
test/indent/c-family/nested-align/out
Normal file
@ -0,0 +1,5 @@
|
||||
foo{bar(baz,
|
||||
qux
|
||||
|
||||
foo(bar{baz,
|
||||
qux
|
3
test/indent/c-family/nested-align/rc
Normal file
3
test/indent/c-family/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