From c6492040b260b09e92526e10807dfa7e71f8c901 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Sat, 5 Jul 2014 20:21:34 -0700 Subject: [PATCH 1/3] Define a new setting g:rust_fold g:rust_fold allows folding to be enabled. This lets the user turn on folding without having to define autocommands. --- src/etc/vim/doc/rust.txt | 12 ++++++++++++ src/etc/vim/syntax/rust.vim | 15 ++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/etc/vim/doc/rust.txt b/src/etc/vim/doc/rust.txt index 96ed69db635..15b231df8fe 100644 --- a/src/etc/vim/doc/rust.txt +++ b/src/etc/vim/doc/rust.txt @@ -53,6 +53,18 @@ g:rust_conceal_pub~ let g:rust_conceal_pub = 1 < + *g:rust_fold* +g:rust_fold~ + Set this option to turn on |folding|: > + let g:rust_fold = 1 +< + Value Effect ~ + 0 No folding + 1 Braced blocks are folded. All folds are open by + default. + 2 Braced blocks are folded. 'foldlevel' is left at the + global value (all folds are closed by default). + *g:rust_bang_comment_leader* g:rust_bang_comment_leader~ Set this option to 1 to preserve the leader on multi-line doc comments diff --git a/src/etc/vim/syntax/rust.vim b/src/etc/vim/syntax/rust.vim index 6285eb6895d..b29c2ce2462 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 27 +" Last Change: July 06, 2014 if version < 600 syntax clear @@ -11,6 +11,17 @@ elseif exists("b:current_syntax") finish endif +" Fold settings {{{1 + +if has("folding") && exists('g:rust_fold') && g:rust_fold != 0 + setlocal foldmethod=syntax + if g:rust_fold == 2 + setlocal foldlevel< + else + setlocal foldlevel=99 + endif +endif + " Syntax definitions {{{1 " Basic keywords {{{2 syn keyword rustConditional match if else @@ -213,8 +224,6 @@ syn keyword rustTodo contained TODO FIXME XXX NB NOTE " 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 rustDecNumber rustNumber From 94cfd1b4adb16b059e1b596c7f3f96af4fc7726b Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Sun, 6 Jul 2014 01:09:03 -0700 Subject: [PATCH 2/3] Set softtabstop, textwidth, and optionally colorcolumn Setting softtabstop makes delete 4 spaces as if it were a tab. Setting textwidth allows comments to be wrapped automatically. It's set at 80, which is the recommended line length for Rust programs. There are suggestions that it should be 79, but our current style guide says 80 so that's what we're matching. A new setting g:rust_colorcolumn sets colorcolumn as well, to +1,101. This indicates both the textwidth and the second stricter line length of 100 that our style guide lists. --- src/etc/vim/doc/rust.txt | 8 +++++++- src/etc/vim/ftplugin/rust.vim | 28 +++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/etc/vim/doc/rust.txt b/src/etc/vim/doc/rust.txt index 15b231df8fe..fdf3a052b2c 100644 --- a/src/etc/vim/doc/rust.txt +++ b/src/etc/vim/doc/rust.txt @@ -1,7 +1,7 @@ *rust.txt* Filetype plugin for Rust ============================================================================== -CONTENTS *rust* +CONTENTS *rust* *ft-rust* 1. Introduction |rust-intro| 2. Settings |rust-settings| @@ -34,6 +34,12 @@ g:rustc_makeprg_no_percent~ let g:rustc_makeprg_no_percent = 1 < + *g:rust_colorcolumn* +g:rust_colorcolumn~ + Set this option to use 'colorcolumn' to highlight the text width + indicate the 100 column recommended hard limit on line lengths: > + let g:rust_colorcolumn = 1 +< *g:rust_conceal* g:rust_conceal~ Set this option to turn on the basic |conceal| support: > diff --git a/src/etc/vim/ftplugin/rust.vim b/src/etc/vim/ftplugin/rust.vim index 16ed43415c3..2b1261c35b5 100644 --- a/src/etc/vim/ftplugin/rust.vim +++ b/src/etc/vim/ftplugin/rust.vim @@ -2,7 +2,7 @@ " Description: Vim syntax file for Rust " Maintainer: Chris Morgan " Maintainer: Kevin Ballard -" Last Change: May 27, 2014 +" Last Change: July 06, 2014 if exists("b:did_ftplugin") finish @@ -35,7 +35,24 @@ silent! setlocal formatoptions+=j " otherwise it's better than nothing. setlocal smartindent nocindent -setlocal tabstop=4 shiftwidth=4 expandtab +setlocal tabstop=4 shiftwidth=4 softtabstop=4 expandtab + +" Line lengths {{{2 + +" Rust style conventions for line lengths say you SHOULD not go over 80 +" columns and MUST not go over 100. +" Without a good 'formatexpr' we can't automatically wrap code, but we can +" still wrap comments just fine with 'textwidth'. +setlocal textwidth=80 + +" We can also use 'colorcolumn' to highlight both the 80 and 100 limits. Not +" everyone likes this so it's gated. +if exists('g:rust_colorcolumn') + setlocal colorcolumn=+1,101 + let b:rust_colorcolumn=1 +endif + +" }}}2 " This includeexpr isn't perfect, but it's a good start setlocal includeexpr=substitute(v:fname,'::','/','g') @@ -93,7 +110,12 @@ endif " Cleanup {{{1 let b:undo_ftplugin = " - \setlocal formatoptions< comments< commentstring< includeexpr< suffixesadd< + \ setlocal formatoptions< comments< commentstring< includeexpr< suffixesadd< + \|setlocal tabstop< shiftwidth< softtabstop< expandtab< textwidth< + \|if exists('b:rust_colorcolumn') + \|setlocal colorcolumn< + \|unlet b:rust_colorcolumn + \|endif \|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 From 9dc667d472630c52a792f47e8ea67337ec23b224 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Mon, 7 Jul 2014 22:19:59 -0700 Subject: [PATCH 3/3] Remove rust_colorcolumn, set textwidth to 99 The latest change to aturon/rust-guidelines states that lines must not exceed 99 characters. This gets rid of the 80/100 split, so we don't need to customize colorcolumn amymore. --- src/etc/vim/doc/rust.txt | 6 ------ src/etc/vim/ftplugin/rust.vim | 23 ++--------------------- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/src/etc/vim/doc/rust.txt b/src/etc/vim/doc/rust.txt index fdf3a052b2c..80f8c3ca5e1 100644 --- a/src/etc/vim/doc/rust.txt +++ b/src/etc/vim/doc/rust.txt @@ -34,12 +34,6 @@ g:rustc_makeprg_no_percent~ let g:rustc_makeprg_no_percent = 1 < - *g:rust_colorcolumn* -g:rust_colorcolumn~ - Set this option to use 'colorcolumn' to highlight the text width - indicate the 100 column recommended hard limit on line lengths: > - let g:rust_colorcolumn = 1 -< *g:rust_conceal* g:rust_conceal~ Set this option to turn on the basic |conceal| support: > diff --git a/src/etc/vim/ftplugin/rust.vim b/src/etc/vim/ftplugin/rust.vim index 2b1261c35b5..39edc1f9a20 100644 --- a/src/etc/vim/ftplugin/rust.vim +++ b/src/etc/vim/ftplugin/rust.vim @@ -2,7 +2,7 @@ " Description: Vim syntax file for Rust " Maintainer: Chris Morgan " Maintainer: Kevin Ballard -" Last Change: July 06, 2014 +" Last Change: Jul 07, 2014 if exists("b:did_ftplugin") finish @@ -37,22 +37,7 @@ setlocal smartindent nocindent setlocal tabstop=4 shiftwidth=4 softtabstop=4 expandtab -" Line lengths {{{2 - -" Rust style conventions for line lengths say you SHOULD not go over 80 -" columns and MUST not go over 100. -" Without a good 'formatexpr' we can't automatically wrap code, but we can -" still wrap comments just fine with 'textwidth'. -setlocal textwidth=80 - -" We can also use 'colorcolumn' to highlight both the 80 and 100 limits. Not -" everyone likes this so it's gated. -if exists('g:rust_colorcolumn') - setlocal colorcolumn=+1,101 - let b:rust_colorcolumn=1 -endif - -" }}}2 +setlocal textwidth=99 " This includeexpr isn't perfect, but it's a good start setlocal includeexpr=substitute(v:fname,'::','/','g') @@ -112,10 +97,6 @@ endif let b:undo_ftplugin = " \ setlocal formatoptions< comments< commentstring< includeexpr< suffixesadd< \|setlocal tabstop< shiftwidth< softtabstop< expandtab< textwidth< - \|if exists('b:rust_colorcolumn') - \|setlocal colorcolumn< - \|unlet b:rust_colorcolumn - \|endif \|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