From 63bae3a997e2fee896ea93459f481ee28a4b48f5 Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Thu, 27 Feb 2014 16:45:48 +1100 Subject: [PATCH 1/5] Highlight the `mod` in `extern mod x;` as Error. Just like the bare keyword `crate` is highlighted as Error (a little dubious, actually, given macros), `mod` is invalid after `extern`: it's obsolete syntax. --- src/etc/vim/syntax/rust.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/etc/vim/syntax/rust.vim b/src/etc/vim/syntax/rust.vim index 837a87879b026..34d9b534c5c80 100644 --- a/src/etc/vim/syntax/rust.vim +++ b/src/etc/vim/syntax/rust.vim @@ -19,7 +19,7 @@ syn keyword rustOperator as syn match rustAssert "\ Date: Thu, 27 Feb 2014 16:50:35 +1100 Subject: [PATCH 2/5] Downgrade `do` to a reserved keyword in Vim. This means it gets highlighted as Error by default. --- 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 34d9b534c5c80..673b4d3d1b219 100644 --- a/src/etc/vim/syntax/rust.vim +++ b/src/etc/vim/syntax/rust.vim @@ -18,7 +18,7 @@ syn keyword rustOperator as syn match rustAssert "\ Date: Thu, 27 Feb 2014 16:51:20 +1100 Subject: [PATCH 3/5] Update prelude items in Vim syntax. --- src/etc/vim/syntax/rust.vim | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/etc/vim/syntax/rust.vim b/src/etc/vim/syntax/rust.vim index 673b4d3d1b219..7e0b6d99d2474 100644 --- a/src/etc/vim/syntax/rust.vim +++ b/src/etc/vim/syntax/rust.vim @@ -52,8 +52,7 @@ syn keyword rustType f64 i8 i16 i32 i64 str Self " to make it easy to update. " Core operators {{{3 -syn keyword rustTrait Sized -syn keyword rustTrait Freeze Send +syn keyword rustTrait Freeze Pod Send Sized syn keyword rustTrait Add Sub Mul Div Rem Neg Not syn keyword rustTrait BitAnd BitOr BitXor syn keyword rustTrait Drop @@ -64,32 +63,25 @@ syn keyword rustEnum Result syn keyword rustEnumVariant Ok Err " Functions {{{3 -"syn keyword rustFunction print println -"syn keyword rustFunction range "syn keyword rustFunction from_str +"syn keyword rustFunction range +"syn keyword rustFunction drop " Types and traits {{{3 syn keyword rustTrait Any AnyOwnExt AnyRefExt AnyMutRefExt syn keyword rustTrait Ascii AsciiCast OwnedAsciiCast AsciiStr IntoBytes -syn keyword rustTrait Bool syn keyword rustTrait ToCStr syn keyword rustTrait Char syn keyword rustTrait Clone DeepClone syn keyword rustTrait Eq Ord TotalEq TotalOrd Ordering Equiv syn keyword rustEnumVariant Less Equal Greater syn keyword rustTrait Container Mutable Map MutableMap Set MutableSet -syn keyword rustTrait Default -syn keyword rustTrait Hash -syn keyword rustTrait FromStr syn keyword rustTrait FromIterator Extendable syn keyword rustTrait Iterator DoubleEndedIterator RandomAccessIterator CloneableIterator syn keyword rustTrait OrdIterator MutableDoubleEndedIterator ExactSize - -syn keyword rustTrait Algebraic Trigonometric Exponential Hyperbolic -syn keyword rustTrait Bitwise Bounded Fractional -syn keyword rustTrait Num NumCast CheckedAdd CheckedSub CheckedMul CheckedDiv -syn keyword rustTrait Orderable Signed Unsigned Round -syn keyword rustTrait Primitive Int Float ToStrRadix ToPrimitive FromPrimitive +syn keyword rustTrait Num NumCast CheckedAdd CheckedSub CheckedMul +syn keyword rustTrait Signed Unsigned Round +syn keyword rustTrait Primitive Int Float ToPrimitive FromPrimitive syn keyword rustTrait GenericPath Path PosixPath WindowsPath syn keyword rustTrait RawPtr syn keyword rustTrait Buffer Writer Reader Seek @@ -99,20 +91,17 @@ syn keyword rustTrait Tuple1 Tuple2 Tuple3 Tuple4 syn keyword rustTrait Tuple5 Tuple6 Tuple7 Tuple8 syn keyword rustTrait Tuple9 Tuple10 Tuple11 Tuple12 syn keyword rustTrait ImmutableEqVector ImmutableTotalOrdVector ImmutableCloneableVector -syn keyword rustTrait OwnedVector OwnedCloneableVector OwnedEqVector MutableVector +syn keyword rustTrait OwnedVector OwnedCloneableVector OwnedEqVector +syn keyword rustTrait MutableVector MutableTotalOrdVector syn keyword rustTrait Vector VectorVector CloneableVector ImmutableVector "syn keyword rustFunction stream -syn keyword rustTrait Port Chan GenericChan GenericSmartChan GenericPort Peekable +syn keyword rustTrait Port Chan "syn keyword rustFunction spawn syn keyword rustSelf self syn keyword rustBoolean true false -syn keyword rustConstant Some None " option -syn keyword rustConstant Ok Err " result -syn keyword rustConstant Less Equal Greater " Ordering - " Other syntax {{{2 " If foo::bar changes to foo.bar, change this ("::" to "\."). From a94a559cf15822a67d42e4469eb5ffff272e08b6 Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Thu, 27 Feb 2014 16:54:54 +1100 Subject: [PATCH 4/5] Fix Vim section movements for standard Rust style. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (Expressed another way: make `[[` et al. work with the curly brace at the end of a line as is standard Rust style, not just at the start is it is by default in Vim, from K&R style.) This came out of #11492, where a simpler but less effective technique was initially proposed; some discussion of the techniques, ways and means can be found there. There are still a few caveats: - Operator-pending mode behaves differently to the standard behaviour: if inside curly braces, it should delete up to and including the closing of the outermost curly brace (that doesn't seem to me consistent with documented behaviour, but it's what it does). Actual behaviour (the more logical and consistent, in my opinion): up to the start of the next outermost curly brace. - With folding enabled (`set fdm=syntax`), `[[` and `]]` do not behave as they should: the default behaviour treats an entire closed fold as one line for these purposes while this code does not (I explicitly `set nofoldenable` in the function—the side-effects are worse with folds enabled), leading to unexpected behaviour, the worst of which is `[[` and/or `]]` not working in visual mode on a closed fold (visual mode keeps it at the extreme end of the region line of the folded region, so it's always going back to the opening line of that fold and immediately being shoved back to the end by visual mode). - `[[` and `]]` are operating inside comments, whereas the standard behaviour skips comments. - The viewport position is sometimes changed when it should not be necessary. --- src/etc/vim/ftplugin/rust.vim | 55 +++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/src/etc/vim/ftplugin/rust.vim b/src/etc/vim/ftplugin/rust.vim index 281a63ef40ae4..b70cda9b998c4 100644 --- a/src/etc/vim/ftplugin/rust.vim +++ b/src/etc/vim/ftplugin/rust.vim @@ -1,7 +1,7 @@ " Vim syntax file " Language: Rust " Maintainer: Chris Morgan -" Last Change: 2013 Jul 10 +" Last Change: 2014 Feb 27 if exists("b:did_ftplugin") finish @@ -42,4 +42,55 @@ if exists("g:loaded_delimitMate") let b:delimitMate_excluded_regions = delimitMate#Get("excluded_regions") . ',rustLifetimeCandidate,rustGenericLifetimeCandidate' endif -let b:undo_ftplugin = "setlocal formatoptions< comments< commentstring< includeexpr< suffixesadd< | if exists('b:rust_original_delimitMate_excluded_regions') | let b:delimitMate_excluded_regions = b:rust_original_delimitMate_excluded_regions | unlet b:rust_original_delimitMate_excluded_regions | elseif exists('b:delimitMate_excluded_regions') | unlet b:delimitMate_excluded_regions | endif" +" Bind motion commands to support hanging indents +nnoremap [[ :call Rust_Jump('n', 'Back') +nnoremap ]] :call Rust_Jump('n', 'Forward') +xnoremap [[ :call Rust_Jump('v', 'Back') +xnoremap ]] :call Rust_Jump('v', 'Forward') +onoremap [[ :call Rust_Jump('o', 'Back') +onoremap ]] :call Rust_Jump('o', 'Forward') + +let b:undo_ftplugin = " + \setlocal formatoptions< comments< commentstring< includeexpr< suffixesadd< + \|if exists('b:rust_original_delimitMate_excluded_regions') + \|let b:delimitMate_excluded_regions = b:rust_original_delimitMate_excluded_regions + \|unlet b:rust_original_delimitMate_excluded_regions + \|elseif exists('b:delimitMate_excluded_regions') + \|unlet b:delimitMate_excluded_regions + \|endif + \|nunmap [[ + \|nunmap ]] + \|xunmap [[ + \|xunmap ]] + \|ounmap [[ + \|ounmap ]] + \" + +if exists('*Rust_Jump') | finish | endif + +function! Rust_Jump(mode, function) range + let cnt = v:count1 + normal! m' + if a:mode ==# 'v' + norm! gv + endif + let foldenable = &foldenable + set nofoldenable + while cnt > 0 + execute "call Rust_Jump_" . a:function . "()" + let cnt = cnt - 1 + endwhile + let &foldenable = foldenable +endfunction + +function! Rust_Jump_Back() + call search('{', 'b') + keepjumps normal! w99[{ +endfunction + +function! Rust_Jump_Forward() + normal! j0 + call search('{', 'b') + keepjumps normal! w99[{% + call search('{') +endfunction From b1525de2aa7ae0584f9bff4ad67d37c526ae2956 Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Thu, 27 Feb 2014 17:02:51 +1100 Subject: [PATCH 5/5] Update Vim syntax file last change date. --- src/etc/vim/syntax/rust.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/etc/vim/syntax/rust.vim b/src/etc/vim/syntax/rust.vim index 7e0b6d99d2474..cc158bb44af37 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: 2014 Feb 14 +" Last Change: 2014 Feb 27 if version < 600 syntax clear