Skip to content

Commit 3fa4cef

Browse files
committed
A few slight tweaks to the Vim syntax file.
- Add fold support (NOT turned on by default) - Highlight `::` by default - Support the common `NOTE` as an important note - Highlight `assert!` and `fail!` differently - Don't highlight `deriving(...)` except in `#[...]`
1 parent 62bb843 commit 3fa4cef

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/etc/vim/syntax/rust.vim

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
" Language: Rust
33
" Maintainer: Patrick Walton <[email protected]>
44
" Maintainer: Ben Blum <[email protected]>
5-
" Last Change: 2013 Jun 14
5+
" Maintainer: Chris Morgan <[email protected]>
6+
" Last Change: 2013 Jul 10
67

78
if version < 600
89
syntax clear
@@ -13,8 +14,8 @@ endif
1314
syn keyword rustConditional match if else
1415
syn keyword rustOperator as
1516

16-
syn match rustAssert "\<assert\(\w\)*!"
17-
syn match rustFail "\<fail\(\w\)*!"
17+
syn match rustAssert "\<assert\(\w\)*!" contained
18+
syn match rustFail "\<fail\(\w\)*!" contained
1819
syn keyword rustKeyword break copy do extern
1920
syn keyword rustKeyword for if impl let log
2021
syn keyword rustKeyword copy do extern
@@ -90,7 +91,7 @@ syn match rustFormat display "%%" contained
9091
syn region rustString start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=rustTodo,rustFormat
9192

9293
syn region rustAttribute start="#\[" end="\]" contains=rustString,rustDeriving
93-
syn region rustDeriving start="deriving(" end=")" contains=rustTrait
94+
syn region rustDeriving start="deriving(" end=")" contained contains=rustTrait
9495

9596
" Number literals
9697
syn match rustNumber display "\<[0-9][0-9_]*\>"
@@ -116,13 +117,18 @@ syn match rustFloat display "\<[0-9][0-9_]*\.[0-9_]\+\%([eE][+-]\=[0-9
116117
syn match rustLifetime display "\'\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*"
117118
syn match rustCharacter "'\([^'\\]\|\\\(['nrt\\\"]\|x\x\{2}\|u\x\{4}\|U\x\{8}\)\)'"
118119

119-
syn region rustCommentDoc start="/\*[\*!]" end="\*/"
120-
syn region rustCommentDoc start="//[/!]" skip="\\$" end="$" keepend
121-
syn match rustComment "/\*\*/"
122-
syn region rustComment start="/\*\([^\*!]\|$\)" end="\*/" contains=rustTodo
123-
syn region rustComment start="//\([^/!]\|$\)" skip="\\$" end="$" contains=rustTodo keepend
120+
syn region rustComment start="/\*" end="\*/" contains=rustTodo
121+
syn region rustComment start="//" skip="\\$" end="$" contains=rustTodo keepend
122+
syn region rustCommentDoc start="/\*\%(!\|\*/\@!\)" end="\*/" contains=rustTodo
123+
syn region rustCommentDoc start="//[/!]" skip="\\$" end="$" contains=rustTodo keepend
124124

125-
syn keyword rustTodo contained TODO FIXME XXX NB
125+
syn keyword rustTodo contained TODO FIXME XXX NB NOTE
126+
127+
" Trivial folding rules to begin with.
128+
" TODO: use the AST to make really good folding
129+
syn region rustFoldBraces start="{" end="}" transparent fold
130+
" If you wish to enable this, setlocal foldmethod=syntax
131+
" It's not enabled by default as it would drive some people mad.
126132

127133
hi def link rustHexNumber rustNumber
128134
hi def link rustBinNumber rustNumber
@@ -142,10 +148,13 @@ hi def link rustKeyword Keyword
142148
hi def link rustConditional Conditional
143149
hi def link rustIdentifier Identifier
144150
hi def link rustModPath Include
151+
hi def link rustModPathSep Delimiter
145152
hi def link rustFuncName Function
146153
hi def link rustFuncCall Function
147154
hi def link rustCommentDoc SpecialComment
148155
hi def link rustComment Comment
156+
hi def link rustAssert PreCondit
157+
hi def link rustFail PreCondit
149158
hi def link rustMacro Macro
150159
hi def link rustType Type
151160
hi def link rustTodo Todo
@@ -160,7 +169,6 @@ hi def link rustLifetime Special
160169
" hi rustAssert ctermfg=yellow
161170
" hi rustFail ctermfg=red
162171
" hi rustMacro ctermfg=magenta
163-
" hi rustModPathSep ctermfg=grey
164172

165173
syn sync minlines=200
166174
syn sync maxlines=500

0 commit comments

Comments
 (0)