From 7c791f130c168e2b4eab699ec04983d3f7aab438 Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Sat, 16 May 2020 21:08:11 +0800 Subject: Handle dedent in rust syntax Naively handle dedent after , and ; which works most of the cases but does not work with multi level dedent. --- rc/filetype/rust.kak | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'rc') diff --git a/rc/filetype/rust.kak b/rc/filetype/rust.kak index be440f75..bb998216 100644 --- a/rc/filetype/rust.kak +++ b/rc/filetype/rust.kak @@ -76,14 +76,21 @@ define-command -hidden rust-indent-on-new-line %~ # copy // comments prefix and following white spaces try %{ execute-keys -draft k s ^\h*\K//[!/]?\h* y gh j P - } catch %| + } catch %` # preserve previous line indent try %{ execute-keys -draft K } # indent after lines ending with { or ( try %[ execute-keys -draft k [{(]\h*$ j ] # indent after lines ending with [{(].+ and move first parameter to own line try %< execute-keys -draft [c[({],[)}] \A[({][^\n]+\n[^\n]*\n?\z L i > - | + # dedent after lines starting with . and ending with , or ; + try %_ execute-keys -draft k ^\h*\..*[,]\h*$ j _ + # todo dedent additional unmatched parenthesis + # try %& execute-keys -draft k s \((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*\) l Gl s\) %sh{ + # count previous selections length + # printf "j $(echo $kak_selections_length | wc -w) " + # } & + ` # filter previous line try %{ execute-keys -draft k : rust-trim-indent } > -- cgit v1.2.3 From dd3257e3f2d2a2dec759b2d2b530ff4dc5444a64 Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Sun, 24 May 2020 11:20:24 +0800 Subject: Rust take indentation before comment to next line --- rc/filetype/rust.kak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rc') diff --git a/rc/filetype/rust.kak b/rc/filetype/rust.kak index bb998216..35788fd8 100644 --- a/rc/filetype/rust.kak +++ b/rc/filetype/rust.kak @@ -75,7 +75,7 @@ define-command -hidden rust-indent-on-new-line %~ evaluate-commands -draft -itersel %< # copy // comments prefix and following white spaces try %{ - execute-keys -draft k s ^\h*\K//[!/]?\h* y gh j P + execute-keys -draft k s ^\h*//[!/]?\h* y gh j P } catch %` # preserve previous line indent try %{ execute-keys -draft K } -- cgit v1.2.3 From de4b7f3864844aad133b3170cc01780a8aefd9a4 Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Sun, 31 May 2020 11:10:11 +0800 Subject: Rust indent block comment --- rc/filetype/rust.kak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rc') diff --git a/rc/filetype/rust.kak b/rc/filetype/rust.kak index 35788fd8..5dca28a2 100644 --- a/rc/filetype/rust.kak +++ b/rc/filetype/rust.kak @@ -75,7 +75,7 @@ define-command -hidden rust-indent-on-new-line %~ evaluate-commands -draft -itersel %< # copy // comments prefix and following white spaces try %{ - execute-keys -draft k s ^\h*//[!/]?\h* y gh j P + execute-keys -draft k s ^\h*//[!/]{0,2}\h* y gh j P } catch %` # preserve previous line indent try %{ execute-keys -draft K } -- cgit v1.2.3 From b1beea86381ae61a2e286a28901b0b563c15ee15 Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Sun, 31 May 2020 18:13:04 +0800 Subject: Rust indent after standalone where --- rc/filetype/rust.kak | 2 ++ 1 file changed, 2 insertions(+) (limited to 'rc') diff --git a/rc/filetype/rust.kak b/rc/filetype/rust.kak index 5dca28a2..9d870959 100644 --- a/rc/filetype/rust.kak +++ b/rc/filetype/rust.kak @@ -83,6 +83,8 @@ define-command -hidden rust-indent-on-new-line %~ try %[ execute-keys -draft k [{(]\h*$ j ] # indent after lines ending with [{(].+ and move first parameter to own line try %< execute-keys -draft [c[({],[)}] \A[({][^\n]+\n[^\n]*\n?\z L i > + # indent lines with a standalone where + try %+ execute-keys -draft k ^\h*where\h*$ j + # dedent after lines starting with . and ending with , or ; try %_ execute-keys -draft k ^\h*\..*[,]\h*$ j _ # todo dedent additional unmatched parenthesis -- cgit v1.2.3 From 12cafe3ed4dbc6d16fb7e54d07d6941985631942 Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Sun, 31 May 2020 19:19:09 +0800 Subject: Rust dedent { after where clause --- rc/filetype/rust.kak | 2 ++ 1 file changed, 2 insertions(+) (limited to 'rc') diff --git a/rc/filetype/rust.kak b/rc/filetype/rust.kak index 9d870959..14071511 100644 --- a/rc/filetype/rust.kak +++ b/rc/filetype/rust.kak @@ -102,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 ) M \A\(.*\)\h*\n\h*\{\z s \A|.\z 1 ] + # dedent standalone { after impl or fn block without any { in between + try %< execute-keys -draft hh impl|fn|struct|enum|union \{ ll ^\h*\{$ > _ ] -- cgit v1.2.3