about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKevin Ballard <kevin@sb.org>2014-07-06 01:09:03 -0700
committerKevin Ballard <kevin@sb.org>2014-07-07 22:18:27 -0700
commit94cfd1b4adb16b059e1b596c7f3f96af4fc7726b (patch)
tree2e924c18086c66065704db73429bb41569e43220
parentc6492040b260b09e92526e10807dfa7e71f8c901 (diff)
downloadrust-94cfd1b4adb16b059e1b596c7f3f96af4fc7726b.tar.gz
rust-94cfd1b4adb16b059e1b596c7f3f96af4fc7726b.zip
Set softtabstop, textwidth, and optionally colorcolumn
Setting softtabstop makes <Del> 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.
-rw-r--r--src/etc/vim/doc/rust.txt8
-rw-r--r--src/etc/vim/ftplugin/rust.vim28
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 <me@chrismorgan.info>
 " Maintainer:   Kevin Ballard <kevin@sb.org>
-" 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