Skip to content

Commit 2094dd7

Browse files
committed
Merge pull request rust-lang#1 from chris-morgan/master
Assorted minor improvements.
2 parents 04deac5 + d5c7d08 commit 2094dd7

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

ftplugin/rust.vim

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
" Description: Vim syntax file for Rust
33
" Maintainer: Chris Morgan <[email protected]>
44
" Maintainer: Kevin Ballard <[email protected]>
5-
" Last Change: Jul 07, 2014
5+
" Last Change: January 29, 2015
66

77
if exists("b:did_ftplugin")
88
finish
@@ -82,6 +82,16 @@ xnoremap <silent> <buffer> ]] :call rust#Jump('v', 'Forward')<CR>
8282
onoremap <silent> <buffer> [[ :call rust#Jump('o', 'Back')<CR>
8383
onoremap <silent> <buffer> ]] :call rust#Jump('o', 'Forward')<CR>
8484
85+
" %-matching. <:> is handy for generics.
86+
set matchpairs+=<:>
87+
" There are two minor issues with it; (a) comparison operators in expressions,
88+
" where a less-than may match a greater-than later on—this is deemed a trivial
89+
" issue—and (b) `Fn() -> X` syntax. This latter issue is irremediable from the
90+
" highlighting perspective (built into Vim), but the actual % functionality
91+
" can be fixed by this use of matchit.vim.
92+
let b:match_skip = 's:comment\|string\|rustArrow'
93+
source $VIMRUNTIME/macros/matchit.vim
94+
8595
" Commands {{{1
8696

8797
" See |:RustRun| for docs
@@ -140,6 +150,8 @@ let b:undo_ftplugin = "
140150
\|xunmap <buffer> ]]
141151
\|ounmap <buffer> [[
142152
\|ounmap <buffer> ]]
153+
\|set matchpairs-=<:>
154+
\|unlet b:match_skip
143155
\"
144156

145157
" }}}1

syntax/rust.vim

+13-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
" Maintainer: Patrick Walton <[email protected]>
44
" Maintainer: Ben Blum <[email protected]>
55
" Maintainer: Chris Morgan <[email protected]>
6-
" Last Change: January 5, 2015
6+
" Last Change: January 29, 2015
77

88
if version < 600
99
syntax clear
@@ -62,7 +62,7 @@ syn keyword rustReservedKeyword alignof be do offsetof priv pure sizeof typeof
6262
syn keyword rustType isize usize float char bool u8 u16 u32 u64 f32
6363
syn keyword rustType f64 i8 i16 i32 i64 str Self
6464

65-
" Things from the prelude (src/libstd/prelude.rs) {{{2
65+
" Things from the libstd v1 prelude (src/libstd/prelude/v1.rs) {{{2
6666
" This section is just straight transformation of the contents of the prelude,
6767
" to make it easy to update.
6868

@@ -71,7 +71,10 @@ syn keyword rustTrait Copy Send Sized Sync
7171
syn keyword rustTrait Drop Fn FnMut FnOnce
7272

7373
" Reexported functions {{{3
74-
syn keyword rustFunction drop
74+
" There’s no point in highlighting these; when one writes drop( or drop::< it
75+
" gets the same highlighting anyway, and if someone writes `let drop = …;` we
76+
" don’t really want *that* drop to be highlighted.
77+
"syn keyword rustFunction drop
7578

7679
" Reexported types and traits {{{3
7780
syn keyword rustTrait Box
@@ -120,6 +123,7 @@ syn match rustSigil display /[&~@*][^)= \t\r\n]/he=e-1,me=e-1
120123
" This isn't actually correct; a closure with no arguments can be `|| { }`.
121124
" Last, because the & in && isn't a sigil
122125
syn match rustOperator display "&&\|||"
126+
syn match rustArrow display "->"
123127

124128
syn match rustMacro '\w\(\w\)*!' contains=rustAssert,rustPanic
125129
syn match rustMacro '#\w\(\w\)*' contains=rustAssert,rustPanic
@@ -134,7 +138,10 @@ syn region rustString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=rustEs
134138
syn region rustString start='b\?r\z(#*\)"' end='"\z1' contains=@Spell
135139

136140
syn region rustAttribute start="#!\?\[" end="\]" contains=rustString,rustDerive
137-
syn region rustDerive start="derive(" end=")" contained contains=rustTrait
141+
syn region rustDerive start="derive(" end=")" contained contains=rustDeriveTrait
142+
" This list comes from src/libsyntax/ext/deriving/mod.rs
143+
" Some are deprecated (Encodable, Decodable) or to be removed after a new snapshot (Show).
144+
syn keyword rustDeriveTrait contained Clone Hash RustcEncodable RustcDecodable Encodable Decodable PartialEq Eq PartialOrd Ord Rand Show Debug Default FromPrimitive Send Sync Copy
138145

139146
" Number literals
140147
syn match rustDecNumber display "\<[0-9][0-9_]*\%([iu]\%(s\|8\|16\|32\|64\)\)\="
@@ -198,6 +205,7 @@ hi def link rustOctNumber rustNumber
198205
hi def link rustBinNumber rustNumber
199206
hi def link rustIdentifierPrime rustIdentifier
200207
hi def link rustTrait rustType
208+
hi def link rustDeriveTrait rustTrait
201209

202210
hi def link rustMacroRepeatCount rustMacroRepeatDelimiters
203211
hi def link rustMacroRepeatDelimiters Macro
@@ -218,6 +226,7 @@ hi def link rustEnumVariant rustConstant
218226
hi def link rustConstant Constant
219227
hi def link rustSelf Constant
220228
hi def link rustFloat Float
229+
hi def link rustArrow rustOperator
221230
hi def link rustOperator Operator
222231
hi def link rustKeyword Keyword
223232
hi def link rustReservedKeyword Error

0 commit comments

Comments
 (0)