1
1
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:
Ivan Tham 2020-05-16 21:08:11 +08:00
parent 75a575bc02
commit 7c791f130c
5 changed files with 41 additions and 2 deletions

View File

@ -76,14 +76,21 @@ define-command -hidden rust-indent-on-new-line %~
# copy // comments prefix and following white spaces # copy // comments prefix and following white spaces
try %{ try %{
execute-keys -draft k <a-x> s ^\h*\K//[!/]?\h* <ret> y gh j P execute-keys -draft k <a-x> s ^\h*\K//[!/]?\h* <ret> y gh j P
} catch %| } catch %`
# preserve previous line indent # preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> } try %{ execute-keys -draft <semicolon> K <a-&> }
# indent after lines ending with { or ( # indent after lines ending with { or (
try %[ execute-keys -draft k <a-x> <a-k> [{(]\h*$ <ret> j <a-gt> ] 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 # 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-&> > 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 # filter previous line
try %{ execute-keys -draft k : rust-trim-indent <ret> } try %{ execute-keys -draft k : rust-trim-indent <ret> }
> >

View File

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

View File

@ -0,0 +1,12 @@
foo();%( )
foo(
bar().baz(),%( )
foo(
bar()
.baz(),%( )
foo()
.bar()
.baz();%( )

View File

@ -0,0 +1,16 @@
foo();
bar
foo(
bar().baz(),
bar
foo(
bar()
.baz(),
bar
foo()
.bar()
.baz();
bar

View File

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