Skip to content

Commit eeda1b8

Browse files
committed
auto merge of #17212 : mahkoh/rust/vim, r=kballard
There are currently two huge problems with the indent file: 1. Long list-like things cannot be indented. See #14446 for one example. Another one is long enums with over 100 lines, including comments. The indentation process stops after 100 lines and the rest is in column 0. 2. In certain files, opening a new line at mod level is extremely slow. See [this](https://github.com/mahkoh/posix.rs/blob/master/src/unistd/mod.rs) for an example. Opening a line at the very end and holing \<cr> down will freeze vim temporarily. The reason for 1. is that cindent doesn't properly indent things that end with a `,` and the indent file tries to work around this by using the indentation of the previous line. It does this by recursively calling a function on the previous lines until it reaches the start of the block. Naturally O(n^2) function calls don't scale very well. Instead of recalculating the indentation of the previous line, we will now simply use the given indentation of the previous line and let the user deal with the rest. This is sufficient unless the user manually mis-indents a line. The reason for 2. seems to be function calls of the form ``` searchpair('{\|(', '', '}\|)', 'nbW', 's:is_string_comment(line("."), col("."))') ``` I've no idea what this even does or why it is there since I cannot reproduce the mistake cindent is supposed to make without this fix. Therefore I've simply removed that part.
2 parents cbb07e8 + 39116d0 commit eeda1b8

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

src/etc/vim/indent/rust.vim

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" Vim indent file
22
" Language: Rust
33
" Author: Chris Morgan <[email protected]>
4-
" Last Change: 2013 Oct 29
4+
" Last Change: 2014 Sep 13
55

66
" Only load this indent file when no other was loaded.
77
if exists("b:did_indent")
@@ -10,7 +10,7 @@ endif
1010
let b:did_indent = 1
1111

1212
setlocal cindent
13-
setlocal cinoptions=L0,(0,Ws,JN,j1
13+
setlocal cinoptions=L0,(0,Ws,J1,j1
1414
setlocal cinkeys=0{,0},!^F,o,O,0[,0]
1515
" Don't think cinwords will actually do anything at all... never mind
1616
setlocal cinwords=for,if,else,while,loop,impl,mod,unsafe,trait,struct,enum,fn,extern
@@ -151,40 +151,42 @@ function GetRustIndent(lnum)
151151
"
152152
" There are probably other cases where we don't want to do this as
153153
" well. Add them as needed.
154-
return GetRustIndent(a:lnum - 1)
154+
return indent(prevlinenum)
155155
endif
156156

157-
" cindent doesn't do the module scope well at all; e.g.::
158-
"
159-
" static FOO : &'static [bool] = [
160-
" true,
161-
" false,
162-
" false,
163-
" true,
164-
" ];
165-
"
166-
" uh oh, next statement is indented further!
157+
if !has("patch-7.4.355")
158+
" cindent before 7.4.355 doesn't do the module scope well at all; e.g.::
159+
"
160+
" static FOO : &'static [bool] = [
161+
" true,
162+
" false,
163+
" false,
164+
" true,
165+
" ];
166+
"
167+
" uh oh, next statement is indented further!
167168

168-
" Note that this does *not* apply the line continuation pattern properly;
169-
" that's too hard to do correctly for my liking at present, so I'll just
170-
" start with these two main cases (square brackets and not returning to
171-
" column zero)
169+
" Note that this does *not* apply the line continuation pattern properly;
170+
" that's too hard to do correctly for my liking at present, so I'll just
171+
" start with these two main cases (square brackets and not returning to
172+
" column zero)
172173

173-
call cursor(a:lnum, 1)
174-
if searchpair('{\|(', '', '}\|)', 'nbW',
175-
\ 's:is_string_comment(line("."), col("."))') == 0
176-
if searchpair('\[', '', '\]', 'nbW',
174+
call cursor(a:lnum, 1)
175+
if searchpair('{\|(', '', '}\|)', 'nbW',
177176
\ 's:is_string_comment(line("."), col("."))') == 0
178-
" Global scope, should be zero
179-
return 0
180-
else
181-
" At the module scope, inside square brackets only
182-
"if getline(a:lnum)[0] == ']' || search('\[', '', '\]', 'nW') == a:lnum
183-
if line =~ "^\\s*]"
184-
" It's the closing line, dedent it
177+
if searchpair('\[', '', '\]', 'nbW',
178+
\ 's:is_string_comment(line("."), col("."))') == 0
179+
" Global scope, should be zero
185180
return 0
186181
else
187-
return &shiftwidth
182+
" At the module scope, inside square brackets only
183+
"if getline(a:lnum)[0] == ']' || search('\[', '', '\]', 'nW') == a:lnum
184+
if line =~ "^\\s*]"
185+
" It's the closing line, dedent it
186+
return 0
187+
else
188+
return &shiftwidth
189+
endif
188190
endif
189191
endif
190192
endif

0 commit comments

Comments
 (0)