@@ -13,7 +13,7 @@ setlocal cindent
13
13
setlocal cinoptions = L0,(0 ,Ws,JN,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
- setlocal cinwords = do , for ,if ,else ,while ,loop,impl,mod ,unsafe,trait,struct,enum ,fn,extern
16
+ setlocal cinwords = for ,if ,else ,while ,loop,impl,mod ,unsafe,trait,struct,enum ,fn,extern
17
17
18
18
" Some preliminary settings
19
19
setlocal nolisp " Make sure lisp indenting doesn't supersede us
@@ -40,12 +40,12 @@ function! s:get_line_trimmed(lnum)
40
40
" If the last character in the line is a comment, do a binary search for
41
41
" the start of the comment. synID() is slow, a linear search would take
42
42
" too long on a long line.
43
- if synIDattr (synID (a: lnum , line_len, 1 ), " name" ) = ~ " Comment\| Todo"
43
+ if synIDattr (synID (a: lnum , line_len, 1 ), " name" ) = ~ ' Comment\|Todo'
44
44
let min = 1
45
45
let max = line_len
46
46
while min < max
47
47
let col = (min + max ) / 2
48
- if synIDattr (synID (a: lnum , col , 1 ), " name" ) = ~ " Comment\| Todo"
48
+ if synIDattr (synID (a: lnum , col , 1 ), " name" ) = ~ ' Comment\|Todo'
49
49
let max = col
50
50
else
51
51
let min = col + 1
@@ -87,10 +87,10 @@ function GetRustIndent(lnum)
87
87
if synname == " rustString"
88
88
" If the start of the line is in a string, don't change the indent
89
89
return -1
90
- elseif synname = ~ " \\ (Comment\\ |Todo\\ ) "
91
- \ && line !~ " ^ \\ s*/\\ * " " not /* opening line
90
+ elseif synname = ~ ' \ (Comment\|Todo\) '
91
+ \ && line !~ ' ^\ s*/\* ' " not /* opening line
92
92
if synname = ~ " CommentML" " multi-line
93
- if line !~ " ^ \\ s*\\ * " && getline (a: lnum - 1 ) = ~ " ^ \\ s*/\\ * "
93
+ if line !~ ' ^\ s*\* ' && getline (a: lnum - 1 ) = ~ ' ^\ s*/\* '
94
94
" This is (hopefully) the line after a /*, and it has no
95
95
" leader, so the correct indentation is that of the
96
96
" previous line.
@@ -115,11 +115,16 @@ function GetRustIndent(lnum)
115
115
" };
116
116
117
117
" Search backwards for the previous non-empty line.
118
- let prevline = s: get_line_trimmed (prevnonblank (a: lnum - 1 ))
118
+ let prevlinenum = prevnonblank (a: lnum - 1 )
119
+ let prevline = s: get_line_trimmed (prevlinenum)
120
+ while prevlinenum > 1 && prevline !~ ' [^[:blank:]]'
121
+ let prevlinenum = prevnonblank (prevlinenum - 1 )
122
+ let prevline = s: get_line_trimmed (prevlinenum)
123
+ endwhile
119
124
if prevline[len (prevline) - 1 ] == " ,"
120
- \ && s: get_line_trimmed (a: lnum ) !~ " ^ \\ s*[\\ [ \\ ]{}]"
121
- \ && prevline !~ " ^ \\ s*fn\\ s "
122
- \ && prevline !~ " ([^()]\\ +,$"
125
+ \ && s: get_line_trimmed (a: lnum ) !~ ' ^\ s*[\[\ ]{}]'
126
+ \ && prevline !~ ' ^\ s*fn\s '
127
+ \ && prevline !~ ' ([^()]\+,$'
123
128
" Oh ho! The previous line ended in a comma! I bet cindent will try to
124
129
" take this too far... For now, let's normally use the previous line's
125
130
" indent.
@@ -166,7 +171,7 @@ function GetRustIndent(lnum)
166
171
" column zero)
167
172
168
173
call cursor (a: lnum , 1 )
169
- if searchpair (' {\|(' , ' ' , ' }\|)' , ' nbW'
174
+ if searchpair (' {\|(' , ' ' , ' }\|)' , ' nbW' ,
170
175
\ ' s:is_string_comment(line("."), col("."))' ) == 0
171
176
if searchpair (' \[' , ' ' , ' \]' , ' nbW' ,
172
177
\ ' s:is_string_comment(line("."), col("."))' ) == 0
0 commit comments