mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-29 14:44:56 +03:00
Handle dedent in rust syntax
Naively handle dedent after , and ; which works most of the cases but does not work with multi level dedent.
This commit is contained in:
parent
75a575bc02
commit
7c791f130c
@ -76,14 +76,21 @@ define-command -hidden rust-indent-on-new-line %~
|
||||
# copy // comments prefix and following white spaces
|
||||
try %{
|
||||
execute-keys -draft k <a-x> s ^\h*\K//[!/]?\h* <ret> y gh j P
|
||||
} catch %|
|
||||
} catch %`
|
||||
# preserve previous line indent
|
||||
try %{ execute-keys -draft <semicolon> K <a-&> }
|
||||
# indent after lines ending with { or (
|
||||
try %[ execute-keys -draft k <a-x> <a-k> [{(]\h*$ <ret> j <a-gt> ]
|
||||
# indent after lines ending with [{(].+ and move first parameter to own line
|
||||
try %< execute-keys -draft [c[({],[)}] <ret> <a-k> \A[({][^\n]+\n[^\n]*\n?\z <ret> L i<ret><esc> <gt> <a-S> <a-&> >
|
||||
|
|
||||
# dedent after lines starting with . and ending with , or ;
|
||||
try %_ execute-keys -draft k <a-x> <a-k> ^\h*\..*[,<semicolon>]\h*$ <ret> j <a-lt> _
|
||||
# todo dedent additional unmatched parenthesis
|
||||
# try %& execute-keys -draft k <a-x> s \((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*\) l Gl s\) %sh{
|
||||
# count previous selections length
|
||||
# printf "j $(echo $kak_selections_length | wc -w) <a-lt>"
|
||||
# } &
|
||||
`
|
||||
# filter previous line
|
||||
try %{ execute-keys -draft k : rust-trim-indent <ret> }
|
||||
>
|
||||
|
1
test/indent/rust/dedent/cmd
Normal file
1
test/indent/rust/dedent/cmd
Normal file
@ -0,0 +1 @@
|
||||
c<ret>bar<esc>
|
12
test/indent/rust/dedent/in
Normal file
12
test/indent/rust/dedent/in
Normal file
@ -0,0 +1,12 @@
|
||||
foo();%( )
|
||||
|
||||
foo(
|
||||
bar().baz(),%( )
|
||||
|
||||
foo(
|
||||
bar()
|
||||
.baz(),%( )
|
||||
|
||||
foo()
|
||||
.bar()
|
||||
.baz();%( )
|
16
test/indent/rust/dedent/out
Normal file
16
test/indent/rust/dedent/out
Normal file
@ -0,0 +1,16 @@
|
||||
foo();
|
||||
bar
|
||||
|
||||
foo(
|
||||
bar().baz(),
|
||||
bar
|
||||
|
||||
foo(
|
||||
bar()
|
||||
.baz(),
|
||||
bar
|
||||
|
||||
foo()
|
||||
.bar()
|
||||
.baz();
|
||||
bar
|
3
test/indent/rust/dedent/rc
Normal file
3
test/indent/rust/dedent/rc
Normal file
@ -0,0 +1,3 @@
|
||||
source "%val{runtime}/colors/default.kak"
|
||||
source "%val{runtime}/rc/filetype/rust.kak"
|
||||
set buffer filetype rust
|
Loading…
Reference in New Issue
Block a user