|
2 | 2 | " Language: Rust |
3 | 3 | " Author: Chris Morgan <[email protected]> |
4 | 4 | " Last Change: 2023-09-11 |
5 | | -" 2024 Jul 04 by Vim Project: use shiftwidth() instead of hard-coding shifted values (#15138) |
| 5 | +" 2024 Jul 04 by Vim Project: use shiftwidth() instead of hard-coding shifted values #15138 |
| 6 | +" 2025 Dec 28 by Vim Project: clean up, handle opening empty line correctly #18974 |
6 | 7 |
|
7 | 8 | " For bugs, patches and license go to https://github.com/rust-lang/rust.vim |
8 | 9 | " Note: upstream seems umaintained: https://github.com/rust-lang/rust.vim/issues/502 |
@@ -86,16 +87,6 @@ function! s:is_string_comment(lnum, col) |
86 | 87 | endif |
87 | 88 | endfunction |
88 | 89 |
|
89 | | -if exists('*shiftwidth') |
90 | | - function! s:shiftwidth() |
91 | | - return shiftwidth() |
92 | | - endfunc |
93 | | -else |
94 | | - function! s:shiftwidth() |
95 | | - return &shiftwidth |
96 | | - endfunc |
97 | | -endif |
98 | | - |
99 | 90 | function GetRustIndent(lnum) |
100 | 91 | " Starting assumption: cindent (called at the end) will do it right |
101 | 92 | " normally. We just want to fix up a few cases. |
@@ -240,44 +231,10 @@ function GetRustIndent(lnum) |
240 | 231 | return indent(prevlinenum) |
241 | 232 | endif |
242 | 233 |
|
243 | | - if !has("patch-7.4.355") |
244 | | - " cindent before 7.4.355 doesn't do the module scope well at all; e.g.:: |
245 | | - " |
246 | | - " static FOO : &'static [bool] = [ |
247 | | - " true, |
248 | | - " false, |
249 | | - " false, |
250 | | - " true, |
251 | | - " ]; |
252 | | - " |
253 | | - " uh oh, next statement is indented further! |
254 | | - |
255 | | - " Note that this does *not* apply the line continuation pattern properly; |
256 | | - " that's too hard to do correctly for my liking at present, so I'll just |
257 | | - " start with these two main cases (square brackets and not returning to |
258 | | - " column zero) |
259 | | - |
260 | | - call cursor(a:lnum, 1) |
261 | | - if searchpair('{\|(', '', '}\|)', 'nbW', |
262 | | - \ 's:is_string_comment(line("."), col("."))') == 0 |
263 | | - if searchpair('\[', '', '\]', 'nbW', |
264 | | - \ 's:is_string_comment(line("."), col("."))') == 0 |
265 | | - " Global scope, should be zero |
266 | | - return 0 |
267 | | - else |
268 | | - " At the module scope, inside square brackets only |
269 | | - "if getline(a:lnum)[0] == ']' || search('\[', '', '\]', 'nW') == a:lnum |
270 | | - if line =~# "^\\s*]" |
271 | | - " It's the closing line, dedent it |
272 | | - return 0 |
273 | | - else |
274 | | - return shiftwidth() |
275 | | - endif |
276 | | - endif |
277 | | - endif |
278 | | - endif |
279 | | - |
280 | 234 | " Fall back on cindent, which does it mostly right |
| 235 | + if empty(trim(line)) |
| 236 | + return cindent(prevlinenum) |
| 237 | + endif |
281 | 238 | return cindent(a:lnum) |
282 | 239 | endfunction |
283 | 240 |
|
|
0 commit comments