Support dedent with rust fn qualifiers
This commit is contained in:
parent
4e594e034a
commit
8df5621334
|
@ -147,7 +147,8 @@ define-command -hidden rust-indent-on-new-line %~
|
||||||
]
|
]
|
||||||
} catch %`
|
} catch %`
|
||||||
# re-indent previous line if it starts with where to match previous block
|
# re-indent previous line if it starts with where to match previous block
|
||||||
try %+ execute-keys -draft k <a-x> <a-k> ^\h*where\b <ret> hh <a-?> ^\h*\b(impl|fn|struct|enum|union)\b <ret> <a-S> 1<a-&> +
|
# string literal parsing within extern does not handle escape
|
||||||
|
try %% execute-keys -draft k <a-x> <a-k> ^\h*where\b <ret> hh <a-?> ^\h*\b(impl|(|pub\ |pub\((crate|self|super|in\ (::)?([a-zA-Z][a-zA-Z0-9_]*|_[a-zA-Z0-9_]+)(::[a-zA-Z][a-zA-Z0-9_]*|_[a-zA-Z0-9_]+)*)\)\ )(async\ |const\ )?(unsafe\ )?(extern\ ("[^"]*"\ )?)?fn|struct|enum|union)\b <ret> <a-S> 1<a-&> %
|
||||||
# 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 [{([].+ and move first parameter to own line
|
# indent after lines ending with [{([].+ and move first parameter to own line
|
||||||
|
@ -156,7 +157,7 @@ define-command -hidden rust-indent-on-new-line %~
|
||||||
# XXX simplify this into a single <a-k> without s
|
# XXX simplify this into a single <a-k> without s
|
||||||
try %< execute-keys -draft k <a-x> s [^\h].+ <ret> <a-K> \A[-+*/&|^})<gt><lt>#] <ret> <a-K> [,<semicolon>{](\h*/[/*].*|)$ <ret> j <a-gt> >
|
try %< execute-keys -draft k <a-x> s [^\h].+ <ret> <a-K> \A[-+*/&|^})<gt><lt>#] <ret> <a-K> [,<semicolon>{](\h*/[/*].*|)$ <ret> j <a-gt> >
|
||||||
# indent after lines ending with {
|
# indent after lines ending with {
|
||||||
try %< execute-keys -draft k <a-x> <a-k> \{$ <ret> j <a-gt> >
|
try %+ execute-keys -draft k <a-x> <a-k> \{$ <ret> j <a-gt> +
|
||||||
# dedent after lines starting with . and ending with } or ) or , or ; or .await (} or ) or .await maybe with ?)
|
# dedent after lines starting with . and ending with } or ) or , or ; or .await (} or ) or .await maybe with ?)
|
||||||
try %_ execute-keys -draft k <a-x> <a-k> ^\h*\. <ret> <a-k> ([,<semicolon>]|(([})]|\.await)\?*))\h*$ <ret> j <a-lt> _
|
try %_ execute-keys -draft k <a-x> <a-k> ^\h*\. <ret> <a-k> ([,<semicolon>]|(([})]|\.await)\?*))\h*$ <ret> j <a-lt> _
|
||||||
# dedent after lines ending with " => {}" - part of empty match
|
# dedent after lines ending with " => {}" - part of empty match
|
||||||
|
@ -175,12 +176,12 @@ define-command -hidden rust-indent-on-new-line %~
|
||||||
~
|
~
|
||||||
|
|
||||||
define-command -hidden rust-indent-on-opening-curly-brace %[
|
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 and related block without any { in between
|
# dedent standalone { after impl and related block without any { in between
|
||||||
try %< execute-keys -draft hh <a-?> ^\h*\b(impl|fn|struct|enum|union|if|for)\b <ret> <a-K> \{ <ret> <a-semicolon> <semicolon> ll <a-x> <a-k> ^\h*\{$ <ret> <a-lt> >
|
try %@ execute-keys -draft hh <a-?> ^\h*\b(impl|(|pub\ |pub\((crate|self|super|in\ (::)?([a-zA-Z][a-zA-Z0-9_]*|_[a-zA-Z0-9_]+)(::[a-zA-Z][a-zA-Z0-9_]*|_[a-zA-Z0-9_]+)*)\)\ )(async\ |const\ )?(unsafe\ )?(extern\ ("[^"]*"\ )?)?fn|struct|enum|union|if|for)\b <ret> <a-K> \{ <ret> <a-semicolon> <semicolon> ll <a-x> <a-k> ^\h*\{$ <ret> <a-lt> @
|
||||||
_
|
~
|
||||||
]
|
]
|
||||||
|
|
||||||
define-command -hidden rust-indent-on-closing %~
|
define-command -hidden rust-indent-on-closing %~
|
||||||
|
|
|
@ -3,6 +3,16 @@
|
||||||
T: Debug
|
T: Debug
|
||||||
%( )
|
%( )
|
||||||
|
|
||||||
|
pub async fn foo<T>(x: T)
|
||||||
|
where
|
||||||
|
T: Debug
|
||||||
|
%( )
|
||||||
|
|
||||||
|
pub(in std::fmt) const unsafe extern "C" fn foo<T>(x: T)
|
||||||
|
where
|
||||||
|
T: Debug
|
||||||
|
%( )
|
||||||
|
|
||||||
fn foo<T>(x: T) where T: Debug %( )
|
fn foo<T>(x: T) where T: Debug %( )
|
||||||
|
|
||||||
impl<T> X for T
|
impl<T> X for T
|
||||||
|
|
|
@ -3,6 +3,16 @@
|
||||||
T: Debug
|
T: Debug
|
||||||
{
|
{
|
||||||
|
|
||||||
|
pub async fn foo<T>(x: T)
|
||||||
|
where
|
||||||
|
T: Debug
|
||||||
|
{
|
||||||
|
|
||||||
|
pub(in std::fmt) const unsafe extern "C" fn foo<T>(x: T)
|
||||||
|
where
|
||||||
|
T: Debug
|
||||||
|
{
|
||||||
|
|
||||||
fn foo<T>(x: T) where T: Debug {
|
fn foo<T>(x: T) where T: Debug {
|
||||||
|
|
||||||
impl<T> X for T
|
impl<T> X for T
|
||||||
|
|
Loading…
Reference in New Issue
Block a user