|
1 | 1 | " Vim indent file |
2 | 2 | " Language: Rust |
3 | 3 | " Author: Chris Morgan <me@chrismorgan.info> |
4 | | -" Last Change: 2013 Oct 29 |
| 4 | +" Last Change: 2014 Sep 13 |
5 | 5 |
|
6 | 6 | " Only load this indent file when no other was loaded. |
7 | 7 | if exists("b:did_indent") |
|
10 | 10 | let b:did_indent = 1 |
11 | 11 |
|
12 | 12 | setlocal cindent |
13 | | -setlocal cinoptions=L0,(0,Ws,JN,j1 |
| 13 | +setlocal cinoptions=L0,(0,Ws,J1,j1 |
14 | 14 | setlocal cinkeys=0{,0},!^F,o,O,0[,0] |
15 | 15 | " Don't think cinwords will actually do anything at all... never mind |
16 | 16 | setlocal cinwords=for,if,else,while,loop,impl,mod,unsafe,trait,struct,enum,fn,extern |
@@ -151,40 +151,42 @@ function GetRustIndent(lnum) |
151 | 151 | " |
152 | 152 | " There are probably other cases where we don't want to do this as |
153 | 153 | " well. Add them as needed. |
154 | | - return GetRustIndent(a:lnum - 1) |
| 154 | + return indent(prevlinenum) |
155 | 155 | endif |
156 | 156 |
|
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! |
167 | 168 |
|
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) |
172 | 173 |
|
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', |
177 | 176 | \ '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 |
185 | 180 | return 0 |
186 | 181 | 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 |
188 | 190 | endif |
189 | 191 | endif |
190 | 192 | endif |
|
0 commit comments