From 15f05dc581f4978c91113a0bce6ea2fdfc164ca0 Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Thu, 29 Aug 2013 15:22:34 +1000 Subject: [PATCH 1/5] Modernise some Vim syntax highlighting. - Remove highlighting of ``L"..."`` (obsolete syntax) - Remove backslash at end of line being a line continuation always (obsolete syntax; this only affects comments, actually) - Add highlighting for backslash at end of line and leading whitespace on the following line inside a string (a genuine line continuation) --- src/etc/vim/syntax/rust.vim | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/etc/vim/syntax/rust.vim b/src/etc/vim/syntax/rust.vim index b5e52939635..6bf6946c797 100644 --- a/src/etc/vim/syntax/rust.vim +++ b/src/etc/vim/syntax/rust.vim @@ -102,7 +102,8 @@ syn match rustMacro '#\w\(\w\)*' contains=rustAssert,rustFail syn match rustFormat display "%\(\d\+\$\)\=[-+' #0*]*\(\d*\|\*\|\*\d\+\$\)\(\.\(\d*\|\*\|\*\d\+\$\)\)\=\([hlLjzt]\|ll\|hh\)\=\([aAbdiuoxXDOUfFeEgGcCsSpn?]\|\[\^\=.[^]]*\]\)" contained syn match rustFormat display "%%" contained syn match rustSpecial display contained /\\\([nrt\\'"]\|x\x\{2}\|u\x\{4}\|U\x\{8}\)/ -syn region rustString start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=rustTodo,rustFormat,rustSpecial +syn match rustStringContinuation display contained /\\\n\s*/ +syn region rustString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=rustTodo,rustFormat,rustSpecial,rustStringContinuation syn region rustAttribute start="#\[" end="\]" contains=rustString,rustDeriving syn region rustDeriving start="deriving(" end=")" contained contains=rustTrait @@ -137,9 +138,9 @@ syn match rustLifetime display "\'\%([^[:cntrl:][:space:][:punct:][:digit syn match rustCharacter /'\([^'\\]\|\\\([nrt\\'"]\|x\x\{2}\|u\x\{4}\|U\x\{8}\)\)'/ contains=rustSpecial syn region rustCommentML start="/\*" end="\*/" contains=rustTodo -syn region rustComment start="//" skip="\\$" end="$" contains=rustTodo keepend +syn region rustComment start="//" end="$" contains=rustTodo keepend syn region rustCommentMLDoc start="/\*\%(!\|\*/\@!\)" end="\*/" contains=rustTodo -syn region rustCommentDoc start="//[/!]" skip="\\$" end="$" contains=rustTodo keepend +syn region rustCommentDoc start="//[/!]" end="$" contains=rustTodo keepend syn keyword rustTodo contained TODO FIXME XXX NB NOTE @@ -157,6 +158,7 @@ hi def link rustTrait rustType hi def link rustSigil StorageClass hi def link rustFormat Special hi def link rustSpecial Special +hi def link rustStringContinuation Special hi def link rustString String hi def link rustCharacter Character hi def link rustNumber Number From afbf908ff472f6557c01632bf531e2a21bd812c8 Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Thu, 29 Aug 2013 15:52:01 +1000 Subject: [PATCH 2/5] Update a handful of keywords highlighted in Vim. I added a few and removed a few and corrected a couple, all with reference to the prelude. It ends up a slightly arbitrary decision precisely what ends up in and what doesn't, unfortunately. --- src/etc/vim/syntax/rust.vim | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/etc/vim/syntax/rust.vim b/src/etc/vim/syntax/rust.vim index 6bf6946c797..dce633cd0cd 100644 --- a/src/etc/vim/syntax/rust.vim +++ b/src/etc/vim/syntax/rust.vim @@ -37,7 +37,7 @@ syn keyword rustKeyword be yield typeof syn keyword rustType int uint float char bool u8 u16 u32 u64 f32 syn keyword rustType f64 i8 i16 i32 i64 str Self -syn keyword rustType Option Either +syn keyword rustType Option Either Result Ordering " Types from libc syn keyword rustType c_float c_double c_void FILE fpos_t @@ -48,10 +48,10 @@ syn keyword rustType size_t ptrdiff_t clock_t time_t syn keyword rustType c_longlong c_ulonglong intptr_t uintptr_t syn keyword rustType off_t dev_t ino_t pid_t mode_t ssize_t -syn keyword rustTrait Const Copy Send Owned Sized " inherent traits -syn keyword rustTrait Clone Decodable Encodable IterBytes Rand ToStr -syn keyword rustTrait Eq Ord TotalEq TotalOrd Num Ptr -syn keyword rustTrait Drop Add Sub Mul Quot Rem Neg BitAnd BitOr +syn keyword rustTrait Const Copy Freeze Send Owned Sized " inherent traits +syn keyword rustTrait Clone DeepClone Decodable Encodable IterBytes Rand ToCStr ToStr ToStrConsume FromStr +syn keyword rustTrait ApproxEq Eq Ord TotalEq TotalOrd Num Ptr Equiv +syn keyword rustTrait Drop Add Sub Mul Div Rem Not Neg BitAnd BitOr syn keyword rustTrait BitXor Shl Shr Index syn keyword rustSelf self @@ -60,9 +60,7 @@ syn keyword rustBoolean true false syn keyword rustConstant Some None " option syn keyword rustConstant Left Right " either syn keyword rustConstant Ok Err " result -syn keyword rustConstant Success Failure " task -syn keyword rustConstant Cons Nil " list -" syn keyword rustConstant empty node " tree +syn keyword rustConstant Less Equal Greater " Ordering " Constants from libc syn keyword rustConstant EXIT_FAILURE EXIT_SUCCESS RAND_MAX From c4b180aa9ce0dc33143de75dfe9aade191689beb Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Fri, 30 Aug 2013 02:15:01 +1000 Subject: [PATCH 3/5] Highlight everything in the prelude in Vim. This is a rather more extensive change than the last, but *ever* so much easier to maintain reasonably, as there's then something to track directly. --- src/etc/vim/syntax/rust.vim | 100 +++++++++++++++++++++++++++--------- 1 file changed, 76 insertions(+), 24 deletions(-) diff --git a/src/etc/vim/syntax/rust.vim b/src/etc/vim/syntax/rust.vim index dce633cd0cd..a2229d4a5ae 100644 --- a/src/etc/vim/syntax/rust.vim +++ b/src/etc/vim/syntax/rust.vim @@ -11,6 +11,8 @@ elseif exists("b:current_syntax") finish endif +" Syntax definitions {{{1 +" Basic keywords {{{2 syn keyword rustConditional match if else syn keyword rustOperator as @@ -32,27 +34,80 @@ syn keyword rustStorage const mut ref static syn match rustIdentifier contains=rustIdentifierPrime "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained syn match rustFuncName "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained -" reserved +" Reserved (but not yet used) keywords {{{2 syn keyword rustKeyword be yield typeof +" Built-in types {{{2 syn keyword rustType int uint float char bool u8 u16 u32 u64 f32 syn keyword rustType f64 i8 i16 i32 i64 str Self -syn keyword rustType Option Either Result Ordering -" Types from libc -syn keyword rustType c_float c_double c_void FILE fpos_t -syn keyword rustType DIR dirent -syn keyword rustType c_char c_schar c_uchar -syn keyword rustType c_short c_ushort c_int c_uint c_long c_ulong -syn keyword rustType size_t ptrdiff_t clock_t time_t -syn keyword rustType c_longlong c_ulonglong intptr_t uintptr_t -syn keyword rustType off_t dev_t ino_t pid_t mode_t ssize_t +" Things from the prelude (src/libstd/prelude.rs) {{{2 +" This section is just straight transformation of the contents of the prelude, +" to make it easy to update. -syn keyword rustTrait Const Copy Freeze Send Owned Sized " inherent traits -syn keyword rustTrait Clone DeepClone Decodable Encodable IterBytes Rand ToCStr ToStr ToStrConsume FromStr -syn keyword rustTrait ApproxEq Eq Ord TotalEq TotalOrd Num Ptr Equiv -syn keyword rustTrait Drop Add Sub Mul Div Rem Not Neg BitAnd BitOr -syn keyword rustTrait BitXor Shl Shr Index +" Core operators {{{3 +syn keyword rustEnum Either +syn keyword rustEnumVariant Left Right +syn keyword rustTrait Sized +syn keyword rustTrait Freeze Send +syn keyword rustTrait Add Sub Mul Div Rem Neg Not +syn keyword rustTrait BitAnd BitOr BitXor +syn keyword rustTrait Drop +syn keyword rustTrait Shl Shr Index +syn keyword rustEnum Option +syn keyword rustEnumVariant Some None +syn keyword rustEnum Result +syn keyword rustEnumVariant Ok Err + +" Functions {{{3 +"syn keyword rustFunction print println +"syn keyword rustFunction range + +" Types and traits {{{3 +syn keyword rustTrait ToCStr +syn keyword rustTrait Clone DeepClone +syn keyword rustTrait Eq ApproxEq Ord TotalEq TotalOrd Ordering Equiv +syn keyword rustEnumVariant Less Equal Greater +syn keyword rustTrait Char +syn keyword rustTrait Container Mutable Map MutableMap Set MutableSet +syn keyword rustTrait Hash +syn keyword rustTrait Times +syn keyword rustTrait FromIterator Extendable +syn keyword rustTrait Iterator DoubleEndedIterator RandomAccessIterator ClonableIterator +syn keyword rustTrait OrdIterator MutableDoubleEndedIterator +syn keyword rustTrait Num NumCast CheckedAdd CheckedSub CheckedMul +syn keyword rustTrait Orderable Signed Unsigned Round +syn keyword rustTrait Algebraic Trigonometric Exponential Hyperbolic +syn keyword rustTrait Integer Fractional Real RealExt +syn keyword rustTrait Bitwise BitCount Bounded +syn keyword rustTrait Primitive Int Float ToStrRadix +syn keyword rustTrait GenericPath +syn keyword rustTrait Path +syn keyword rustTrait PosixPath +syn keyword rustTrait WindowsPath +syn keyword rustTrait RawPtr +syn keyword rustTrait Ascii AsciiCast OwnedAsciiCast AsciiStr ToBytesConsume +syn keyword rustTrait Str StrVector StrSlice OwnedStr +syn keyword rustTrait FromStr +syn keyword rustTrait IterBytes +syn keyword rustTrait ToStr ToStrConsume +syn keyword rustTrait CopyableTuple ImmutableTuple +syn keyword rustTrait CloneableTuple1 ImmutableTuple1 +syn keyword rustTrait CloneableTuple2 CloneableTuple3 CloneableTuple4 CloneableTuple5 +syn keyword rustTrait CloneableTuple6 CloneableTuple7 CloneableTuple8 CloneableTuple9 +syn keyword rustTrait CloneableTuple10 CloneableTuple11 CloneableTuple12 +syn keyword rustTrait ImmutableTuple2 ImmutableTuple3 ImmutableTuple4 ImmutableTuple5 +syn keyword rustTrait ImmutableTuple6 ImmutableTuple7 ImmutableTuple8 ImmutableTuple9 +syn keyword rustTrait ImmutableTuple10 ImmutableTuple11 ImmutableTuple12 +syn keyword rustTrait Vector VectorVector CopyableVector ImmutableVector +syn keyword rustTrait ImmutableEqVector ImmutableTotalOrdVector ImmutableCopyableVector +syn keyword rustTrait OwnedVector OwnedCopyableVector OwnedEqVector MutableVector +syn keyword rustTrait Reader ReaderUtil Writer WriterUtil +syn keyword rustTrait Default + +"syn keyword rustFunction stream +syn keyword rustTrait Port Chan GenericChan GenericSmartChan GenericPort Peekable +"syn keyword rustFunction spawn syn keyword rustSelf self syn keyword rustBoolean true false @@ -62,15 +117,7 @@ syn keyword rustConstant Left Right " either syn keyword rustConstant Ok Err " result syn keyword rustConstant Less Equal Greater " Ordering -" Constants from libc -syn keyword rustConstant EXIT_FAILURE EXIT_SUCCESS RAND_MAX -syn keyword rustConstant EOF SEEK_SET SEEK_CUR SEEK_END _IOFBF _IONBF -syn keyword rustConstant _IOLBF BUFSIZ FOPEN_MAX FILENAME_MAX L_tmpnam -syn keyword rustConstant TMP_MAX O_RDONLY O_WRONLY O_RDWR O_APPEND O_CREAT -syn keyword rustConstant O_EXCL O_TRUNC S_IFIFO S_IFCHR S_IFBLK S_IFDIR -syn keyword rustConstant S_IFREG S_IFMT S_IEXEC S_IWRITE S_IREAD S_IRWXU -syn keyword rustConstant S_IXUSR S_IWUSR S_IRUSR F_OK R_OK W_OK X_OK -syn keyword rustConstant STDIN_FILENO STDOUT_FILENO STDERR_FILENO +" Other syntax {{{2 " If foo::bar changes to foo.bar, change this ("::" to "\."). " If foo::bar changes to Foo::bar, change this (first "\w" to "\u"). @@ -142,12 +189,14 @@ syn region rustCommentDoc start="//[/!]" end="$" contains=rustTodo keepend syn keyword rustTodo contained TODO FIXME XXX NB NOTE +" Folding rules {{{2 " Trivial folding rules to begin with. " TODO: use the AST to make really good folding syn region rustFoldBraces start="{" end="}" transparent fold " If you wish to enable this, setlocal foldmethod=syntax " It's not enabled by default as it would drive some people mad. +" Default highlighting {{{1 hi def link rustHexNumber rustNumber hi def link rustBinNumber rustNumber hi def link rustIdentifierPrime rustIdentifier @@ -161,6 +210,8 @@ hi def link rustString String hi def link rustCharacter Character hi def link rustNumber Number hi def link rustBoolean Boolean +hi def link rustEnum rustType +hi def link rustEnumVariant rustConstant hi def link rustConstant Constant hi def link rustSelf Constant hi def link rustFloat Float @@ -171,6 +222,7 @@ hi def link rustIdentifier Identifier hi def link rustCapsIdent rustIdentifier hi def link rustModPath Include hi def link rustModPathSep Delimiter +hi def link rustFunction Function hi def link rustFuncName Function hi def link rustFuncCall Function hi def link rustCommentMLDoc rustCommentDoc From 2bc408f3e377bdbdd03b934c56cddf8bc93b1f69 Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Wed, 4 Sep 2013 02:38:41 +1000 Subject: [PATCH 4/5] Update highlighting for prelude changes. --- src/etc/vim/syntax/rust.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/etc/vim/syntax/rust.vim b/src/etc/vim/syntax/rust.vim index a2229d4a5ae..0a95f31b067 100644 --- a/src/etc/vim/syntax/rust.vim +++ b/src/etc/vim/syntax/rust.vim @@ -3,7 +3,7 @@ " Maintainer: Patrick Walton " Maintainer: Ben Blum " Maintainer: Chris Morgan -" Last Change: 2013 Aug 1 +" Last Change: 2013 Sep 4 if version < 600 syntax clear @@ -74,7 +74,7 @@ syn keyword rustTrait Hash syn keyword rustTrait Times syn keyword rustTrait FromIterator Extendable syn keyword rustTrait Iterator DoubleEndedIterator RandomAccessIterator ClonableIterator -syn keyword rustTrait OrdIterator MutableDoubleEndedIterator +syn keyword rustTrait OrdIterator MutableDoubleEndedIterator ExactSize syn keyword rustTrait Num NumCast CheckedAdd CheckedSub CheckedMul syn keyword rustTrait Orderable Signed Unsigned Round syn keyword rustTrait Algebraic Trigonometric Exponential Hyperbolic From 9f6180413dd08a77397353269f77024168a71429 Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Wed, 4 Sep 2013 13:33:40 +1000 Subject: [PATCH 5/5] Silence fo+=j error for users of Vim < 7.3.541. --- src/etc/vim/ftplugin/rust.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/etc/vim/ftplugin/rust.vim b/src/etc/vim/ftplugin/rust.vim index bf02d7b1723..281a63ef40a 100644 --- a/src/etc/vim/ftplugin/rust.vim +++ b/src/etc/vim/ftplugin/rust.vim @@ -21,7 +21,9 @@ else setlocal comments=s0:/*!,m:\ ,ex:*/,s1:/*,mb:*,ex:*/,:///,://!,:// endif setlocal commentstring=//%s -setlocal formatoptions-=t formatoptions+=croqnlj +setlocal formatoptions-=t formatoptions+=croqnl +" j was only added in 7.3.541, so stop complaints about its nonexistence +silent! setlocal formatoptions+=j " This includeexpr isn't perfect, but it's a good start setlocal includeexpr=substitute(v:fname,'::','/','g')