Merge remote-tracking branch 'pickfire/rust-dedent'

This commit is contained in:
Maxime Coste 2020-06-02 18:40:09 +10:00
commit d43b6799cf
17 changed files with 179 additions and 3 deletions

View File

@ -75,15 +75,24 @@ define-command -hidden rust-indent-on-new-line %~
evaluate-commands -draft -itersel %< evaluate-commands -draft -itersel %<
# 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*//[!/]{0,2}\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-&> >
| # 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 # filter previous line
try %{ execute-keys -draft k : rust-trim-indent <ret> } 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 %_ evaluate-commands -draft -itersel %_
# align indent with opening paren when { is entered on a new line after the closing paren # 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-&> ] 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> >
_ _
] ]

View File

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

View File

@ -0,0 +1,5 @@
impl X for T where%( )
impl X for T
where%( )

View File

@ -0,0 +1,7 @@
impl X for T where
bar
impl X for T
where
bar

View File

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

View File

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

View File

@ -0,0 +1,12 @@
// foo%( )
//! foo%( )
//!! foo%( )
/// foo%( )
//// foo%( )
println!("hello world"); // foo%( )

View File

@ -0,0 +1,18 @@
// foo
// bar
//! foo
//! bar
//!! foo
//!! bar
/// foo
/// bar
//// foo
//// bar
println!("hello world"); // foo
bar

View File

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

View File

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

View File

@ -0,0 +1,16 @@
foo();%( )
foo(
bar().baz(),%( )
foo(
bar()
.baz(),%( )
foo()
.bar()
.baz();%( )
let t = "a
wah";%( )

View File

@ -0,0 +1,21 @@
foo();
bar
foo(
bar().baz(),
bar
foo(
bar()
.baz(),
bar
foo()
.bar()
.baz();
bar
let t = "a
wah";
bar

View File

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

View File

@ -0,0 +1 @@
c{<esc>

View 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 %( )

View 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 {

View File

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