From 9c72da52514428c187742de3e8b796949e72d34f Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Sat, 13 Sep 2014 00:24:40 +0200 Subject: [PATCH 1/2] update vim indent file --- src/etc/vim/indent/rust.vim | 41 +++---------------------------------- 1 file changed, 3 insertions(+), 38 deletions(-) diff --git a/src/etc/vim/indent/rust.vim b/src/etc/vim/indent/rust.vim index b9d6330c8bb..3c733d39da4 100644 --- a/src/etc/vim/indent/rust.vim +++ b/src/etc/vim/indent/rust.vim @@ -1,7 +1,7 @@ " Vim indent file " Language: Rust " Author: Chris Morgan -" Last Change: 2013 Oct 29 +" Last Change: 2014 Sep 13 " Only load this indent file when no other was loaded. if exists("b:did_indent") @@ -10,7 +10,7 @@ endif let b:did_indent = 1 setlocal cindent -setlocal cinoptions=L0,(0,Ws,JN,j1 +setlocal cinoptions=L0,(0,Ws,J1,j1 setlocal cinkeys=0{,0},!^F,o,O,0[,0] " Don't think cinwords will actually do anything at all... never mind setlocal cinwords=for,if,else,while,loop,impl,mod,unsafe,trait,struct,enum,fn,extern @@ -151,42 +151,7 @@ function GetRustIndent(lnum) " " There are probably other cases where we don't want to do this as " well. Add them as needed. - return GetRustIndent(a:lnum - 1) - endif - - " cindent doesn't do the module scope well at all; e.g.:: - " - " static FOO : &'static [bool] = [ - " true, - " false, - " false, - " true, - " ]; - " - " uh oh, next statement is indented further! - - " Note that this does *not* apply the line continuation pattern properly; - " that's too hard to do correctly for my liking at present, so I'll just - " start with these two main cases (square brackets and not returning to - " column zero) - - call cursor(a:lnum, 1) - if searchpair('{\|(', '', '}\|)', 'nbW', - \ 's:is_string_comment(line("."), col("."))') == 0 - if searchpair('\[', '', '\]', 'nbW', - \ 's:is_string_comment(line("."), col("."))') == 0 - " Global scope, should be zero - return 0 - else - " At the module scope, inside square brackets only - "if getline(a:lnum)[0] == ']' || search('\[', '', '\]', 'nW') == a:lnum - if line =~ "^\\s*]" - " It's the closing line, dedent it - return 0 - else - return &shiftwidth - endif - endif + return indent(prevlinenum) endif " Fall back on cindent, which does it mostly right From 39116d01914854882f62b1306e8b96fb0b4f9842 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Thu, 18 Sep 2014 22:16:47 +0200 Subject: [PATCH 2/2] fix for vim < 7.4.355 --- src/etc/vim/indent/rust.vim | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/etc/vim/indent/rust.vim b/src/etc/vim/indent/rust.vim index 3c733d39da4..300d7dacfa9 100644 --- a/src/etc/vim/indent/rust.vim +++ b/src/etc/vim/indent/rust.vim @@ -154,6 +154,43 @@ function GetRustIndent(lnum) return indent(prevlinenum) endif + if !has("patch-7.4.355") + " cindent before 7.4.355 doesn't do the module scope well at all; e.g.:: + " + " static FOO : &'static [bool] = [ + " true, + " false, + " false, + " true, + " ]; + " + " uh oh, next statement is indented further! + + " Note that this does *not* apply the line continuation pattern properly; + " that's too hard to do correctly for my liking at present, so I'll just + " start with these two main cases (square brackets and not returning to + " column zero) + + call cursor(a:lnum, 1) + if searchpair('{\|(', '', '}\|)', 'nbW', + \ 's:is_string_comment(line("."), col("."))') == 0 + if searchpair('\[', '', '\]', 'nbW', + \ 's:is_string_comment(line("."), col("."))') == 0 + " Global scope, should be zero + return 0 + else + " At the module scope, inside square brackets only + "if getline(a:lnum)[0] == ']' || search('\[', '', '\]', 'nW') == a:lnum + if line =~ "^\\s*]" + " It's the closing line, dedent it + return 0 + else + return &shiftwidth + endif + endif + endif + endif + " Fall back on cindent, which does it mostly right return cindent(a:lnum) endfunction