Skip to content

Commit b7176e7

Browse files
committed
indent: for '.<expr>;' cases, uses searchpair heuristics
Fixes rust-lang#366.
1 parent 70bd1e3 commit b7176e7

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

indent/rust.vim

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,12 @@ function GetRustIndent(lnum)
191191
" A line that ends with '.<expr>;' is probably an end of a long list
192192
" of method operations.
193193
if prevline =~# '\V\^\s\*.' && l:last_prevline_character ==# ';'
194-
return indent(prevlinenum) - s:shiftwidth()
194+
call cursor(a:lnum - 1, 1)
195+
let l:scope_start = searchpair('{\|(', '', '}\|)', 'nbW',
196+
\ 's:is_string_comment(line("."), col("."))')
197+
if l:scope_start != 0 && l:scope_start < a:lnum
198+
return indent(l:scope_start) + 4
199+
endif
195200
endif
196201

197202
if l:last_prevline_character ==# ","

test/indent.vader

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,51 @@ Expect rust (issue #5):
225225
}
226226
}
227227

228+
############################################
229+
# Issue #366
230+
231+
Given rust:
232+
fn f() {
233+
g(|_| {
234+
h();
235+
})
236+
.unwrap();
237+
h();
238+
}
239+
240+
Do:
241+
vip=
242+
243+
Expect rust (issue #366):
244+
fn f() {
245+
g(|_| {
246+
h();
247+
})
248+
.unwrap();
249+
h();
250+
}
251+
252+
Given rust:
253+
fn f() {
254+
let a = g(|_| {
255+
h();
256+
})
257+
.unwrap();
258+
h();
259+
}
260+
261+
Do:
262+
vip=
263+
264+
Expect rust (issue #366, variation #2):
265+
fn f() {
266+
let a = g(|_| {
267+
h();
268+
})
269+
.unwrap();
270+
h();
271+
}
272+
228273
############################################
229274

230275
Given rust:

0 commit comments

Comments
 (0)