diff options
| author | bors <bors@rust-lang.org> | 2014-05-05 21:21:34 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-05-05 21:21:34 -0700 |
| commit | cba66bc9209ea2acbd51cabb9059f26a0416b2ec (patch) | |
| tree | d36fe51dc183042f94465c21057ff9b2eff8da4b | |
| parent | a1ca57237b27f67195b39740de4dc0bbb063e74a (diff) | |
| parent | 91e61ad9670baf6884dd77e93dbe5160fa50fb49 (diff) | |
| download | rust-cba66bc9209ea2acbd51cabb9059f26a0416b2ec.tar.gz rust-cba66bc9209ea2acbd51cabb9059f26a0416b2ec.zip | |
auto merge of #13925 : kballard/rust/vim_indent_bracket_fix, r=thestinger
If an unbalanced [ exists in a string or comment, this should not be
considered when calculating the indent at the top level.
Similarly, when testing for ({/}) to see if we're at the top level to
begin with, strings and comments should be skipped.
| -rw-r--r-- | src/etc/vim/indent/rust.vim | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/etc/vim/indent/rust.vim b/src/etc/vim/indent/rust.vim index 54094a74119..9fdc18582ba 100644 --- a/src/etc/vim/indent/rust.vim +++ b/src/etc/vim/indent/rust.vim @@ -30,7 +30,7 @@ endif " Come here when loading the script the first time. -function s:get_line_trimmed(lnum) +function! s:get_line_trimmed(lnum) " Get the line and remove a trailing comment. " Use syntax highlighting attributes when possible. " NOTE: this is not accurate; /* */ or a line continuation could trick it @@ -61,6 +61,20 @@ function s:get_line_trimmed(lnum) endif endfunction +function! s:is_string_comment(lnum, col) + if has('syntax_items') + for id in synstack(a:lnum, a:col) + let synname = synIDattr(id, "name") + if synname == "rustString" || synname =~ "^rustComment" + return 1 + endif + endfor + else + " without syntax, let's not even try + return 0 + endif +endfunction + function GetRustIndent(lnum) " Starting assumption: cindent (called at the end) will do it right @@ -152,8 +166,10 @@ function GetRustIndent(lnum) " column zero) call cursor(a:lnum, 1) - if searchpair('{\|(', '', '}\|)', 'nbW') == 0 - if searchpair('\[', '', '\]', 'nbW') == 0 + 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 |
