mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-25 12:36:11 +03:00
Merge remote-tracking branch 'pickfire/rust-dedent'
This commit is contained in:
commit
d43b6799cf
@ -75,15 +75,24 @@ define-command -hidden rust-indent-on-new-line %~
|
||||
evaluate-commands -draft -itersel %<
|
||||
# copy // comments prefix and following white spaces
|
||||
try %{
|
||||
execute-keys -draft k <a-x> s ^\h*\K//[!/]?\h* <ret> y gh j P
|
||||
} catch %|
|
||||
execute-keys -draft k <a-x> s ^\h*//[!/]{0,2}\h* <ret> y gh j P
|
||||
} 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-&> >
|
||||
|
|
||||
# indent lines with a standalone where
|
||||
try %+ execute-keys -draft k <a-x> <a-k> ^\h*where\h*$ <ret> j <a-gt> +
|
||||
# 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> }
|
||||
>
|
||||
@ -93,6 +102,8 @@ define-command -hidden rust-indent-on-opening-curly-brace %[
|
||||
evaluate-commands -draft -itersel %_
|
||||
# align indent with opening paren when { is entered on a new line after the closing paren
|
||||
try %[ execute-keys -draft h <a-F> ) M <a-k> \A\(.*\)\h*\n\h*\{\z <ret> s \A|.\z <ret> 1<a-&> ]
|
||||
# dedent standalone { after impl or fn block without any { in between
|
||||
try %< execute-keys -draft hh <a-?> impl|fn|struct|enum|union <ret> <a-K> \{ <ret> <a-semicolon> <semicolon> ll <a-x> <a-k> ^\h*\{$ <ret> <a-lt> >
|
||||
_
|
||||
]
|
||||
|
||||
|
1
test/indent/rust/after-where/cmd
Normal file
1
test/indent/rust/after-where/cmd
Normal file
@ -0,0 +1 @@
|
||||
c<ret>bar<esc>
|
5
test/indent/rust/after-where/in
Normal file
5
test/indent/rust/after-where/in
Normal file
@ -0,0 +1,5 @@
|
||||
impl X for T where%( )
|
||||
|
||||
impl X for T
|
||||
where%( )
|
||||
|
7
test/indent/rust/after-where/out
Normal file
7
test/indent/rust/after-where/out
Normal file
@ -0,0 +1,7 @@
|
||||
impl X for T where
|
||||
bar
|
||||
|
||||
impl X for T
|
||||
where
|
||||
bar
|
||||
|
3
test/indent/rust/after-where/rc
Normal file
3
test/indent/rust/after-where/rc
Normal file
@ -0,0 +1,3 @@
|
||||
source "%val{runtime}/colors/default.kak"
|
||||
source "%val{runtime}/rc/filetype/rust.kak"
|
||||
set buffer filetype rust
|
1
test/indent/rust/comment/cmd
Normal file
1
test/indent/rust/comment/cmd
Normal file
@ -0,0 +1 @@
|
||||
c<ret>bar<esc>
|
12
test/indent/rust/comment/in
Normal file
12
test/indent/rust/comment/in
Normal file
@ -0,0 +1,12 @@
|
||||
// foo%( )
|
||||
|
||||
//! foo%( )
|
||||
|
||||
//!! foo%( )
|
||||
|
||||
/// foo%( )
|
||||
|
||||
//// foo%( )
|
||||
|
||||
println!("hello world"); // foo%( )
|
||||
|
18
test/indent/rust/comment/out
Normal file
18
test/indent/rust/comment/out
Normal file
@ -0,0 +1,18 @@
|
||||
// foo
|
||||
// bar
|
||||
|
||||
//! foo
|
||||
//! bar
|
||||
|
||||
//!! foo
|
||||
//!! bar
|
||||
|
||||
/// foo
|
||||
/// bar
|
||||
|
||||
//// foo
|
||||
//// bar
|
||||
|
||||
println!("hello world"); // foo
|
||||
bar
|
||||
|
3
test/indent/rust/comment/rc
Normal file
3
test/indent/rust/comment/rc
Normal file
@ -0,0 +1,3 @@
|
||||
source "%val{runtime}/colors/default.kak"
|
||||
source "%val{runtime}/rc/filetype/rust.kak"
|
||||
set buffer filetype rust
|
1
test/indent/rust/dedent/cmd
Normal file
1
test/indent/rust/dedent/cmd
Normal file
@ -0,0 +1 @@
|
||||
c<ret>bar<esc>
|
16
test/indent/rust/dedent/in
Normal file
16
test/indent/rust/dedent/in
Normal file
@ -0,0 +1,16 @@
|
||||
foo();%( )
|
||||
|
||||
foo(
|
||||
bar().baz(),%( )
|
||||
|
||||
foo(
|
||||
bar()
|
||||
.baz(),%( )
|
||||
|
||||
foo()
|
||||
.bar()
|
||||
.baz();%( )
|
||||
|
||||
let t = "a
|
||||
wah";%( )
|
||||
|
21
test/indent/rust/dedent/out
Normal file
21
test/indent/rust/dedent/out
Normal file
@ -0,0 +1,21 @@
|
||||
foo();
|
||||
bar
|
||||
|
||||
foo(
|
||||
bar().baz(),
|
||||
bar
|
||||
|
||||
foo(
|
||||
bar()
|
||||
.baz(),
|
||||
bar
|
||||
|
||||
foo()
|
||||
.bar()
|
||||
.baz();
|
||||
bar
|
||||
|
||||
let t = "a
|
||||
wah";
|
||||
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
|
1
test/indent/rust/on-open-paren/cmd
Normal file
1
test/indent/rust/on-open-paren/cmd
Normal file
@ -0,0 +1 @@
|
||||
c{<esc>
|
35
test/indent/rust/on-open-paren/in
Normal file
35
test/indent/rust/on-open-paren/in
Normal file
@ -0,0 +1,35 @@
|
||||
fn foo<T>(x: T)
|
||||
where
|
||||
T: Debug
|
||||
%( )
|
||||
|
||||
fn foo<T>(x: T) where T: Debug %( )
|
||||
|
||||
impl<T> X for T
|
||||
where
|
||||
T: Debug
|
||||
%( )
|
||||
|
||||
impl<T> X for T where T: Debug %( )
|
||||
|
||||
struct X<T>
|
||||
where
|
||||
T: Debug
|
||||
%( )
|
||||
|
||||
struct X<T> where T: Debug %( )
|
||||
|
||||
enum X<T>
|
||||
where
|
||||
T: Debug
|
||||
%( )
|
||||
|
||||
enum X<T> where T: Debug %( )
|
||||
|
||||
union X<T>
|
||||
where
|
||||
T: Debug
|
||||
%( )
|
||||
|
||||
union X<T> where T: Debug %( )
|
||||
|
35
test/indent/rust/on-open-paren/out
Normal file
35
test/indent/rust/on-open-paren/out
Normal file
@ -0,0 +1,35 @@
|
||||
fn foo<T>(x: T)
|
||||
where
|
||||
T: Debug
|
||||
{
|
||||
|
||||
fn foo<T>(x: T) where T: Debug {
|
||||
|
||||
impl<T> X for T
|
||||
where
|
||||
T: Debug
|
||||
{
|
||||
|
||||
impl<T> X for T where T: Debug {
|
||||
|
||||
struct X<T>
|
||||
where
|
||||
T: Debug
|
||||
{
|
||||
|
||||
struct X<T> where T: Debug {
|
||||
|
||||
enum X<T>
|
||||
where
|
||||
T: Debug
|
||||
{
|
||||
|
||||
enum X<T> where T: Debug {
|
||||
|
||||
union X<T>
|
||||
where
|
||||
T: Debug
|
||||
{
|
||||
|
||||
union X<T> where T: Debug {
|
||||
|
3
test/indent/rust/on-open-paren/rc
Normal file
3
test/indent/rust/on-open-paren/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