Support rust visibility for enum and others

This commit is contained in:
Ivan Tham 2021-03-07 14:22:43 +08:00
parent 8df5621334
commit ebe7f82bb2
3 changed files with 12 additions and 2 deletions

View File

@ -148,7 +148,7 @@ define-command -hidden rust-indent-on-new-line %~
} catch %`
# re-indent previous line if it starts with where to match previous block
# 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-&> %
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
try %{ execute-keys -draft <semicolon> K <a-&> }
# indent after lines ending with [{([].+ and move first parameter to own line
@ -180,7 +180,7 @@ define-command -hidden rust-indent-on-opening-curly-brace %[
# 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 and related block without any { in between
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> @
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> @
~
]

View File

@ -27,6 +27,11 @@
T: Debug
%( )
pub(crate) struct X<T>
where
T: Debug
%( )
struct X<T> where T: Debug %( )
enum X<T>

View File

@ -27,6 +27,11 @@
T: Debug
{
pub(crate) struct X<T>
where
T: Debug
{
struct X<T> where T: Debug {
enum X<T>