37
37
endfunction
38
38
endif
39
39
40
- let s: line_pre = ' ^\s*\%(\%(\%(\/\*.\{-}\)\=\*\+\/\s*\)\=\)\@>'
41
-
42
40
let s: expr_case = ' \<\%(\%(case\>\s*\S.\{-}\)\|default\)\s*:\C'
43
41
" Regex of syntax group names that are or delimit string or are comments.
44
42
let s: syng_strcom = ' \%(s\%(tring\|pecial\)\|comment\|regex\|doc\|template\)'
@@ -111,7 +109,9 @@ function s:iscontOne(i,num,cont)
111
109
if indent (l: i ) < ind " first line always true for !a:cont, false for !!a:cont
112
110
if s: OneScope (l: i ,s: Trimline (l: i ))
113
111
if expand (' <cword>' ) == # ' while' &&
114
- \ s: GetPair (s: line_pre . ' \C\<do\>' ,' \C\<while\>' ,' bW' ,s: skip_expr ,100 ,l: num + ! ! a: num ) > 0
112
+ \ s: GetPair (' \C\<do\>' ,' \C\<while\>' ,' bW' ,' line2byte(line(".")) + col(".") <'
113
+ \ . (line2byte (l: num ) + b: js_cache [2 ]) . ' ||'
114
+ \ . s: skip_expr . ' || !s:IsBlock()' ,100 ,l: num ) > 0
115
115
return 0
116
116
endif
117
117
let bL += 1
@@ -128,38 +128,36 @@ endfunction
128
128
129
129
" https://github.com/sweet-js/sweet.js/wiki/design#give-lookbehind-to-the-reader
130
130
function s: IsBlock ()
131
- if getline (line (' .' ))[col (' .' )-1 ] == ' {'
132
- let l: ln = line (' .' )
133
- if search (' \S' ,' bW' )
131
+ let l: ln = line (' .' )
132
+ if search (' \S' ,' bW' )
133
+ let char = getline (line (' .' ))[col (' .' )-1 ]
134
+ let pchar = getline (line (' .' ))[col (' .' )-2 ]
135
+ let syn = synIDattr (synID (line (' .' ),col (' .' )-1 ,0 ),' name' )
136
+ if pchar . char == ' */' && syn = ~? ' comment'
137
+ if ! search (' \/\*' ,' bW' ) || ! search (' \S' ,' bW' )
138
+ return 1
139
+ endif
134
140
let char = getline (line (' .' ))[col (' .' )-1 ]
135
141
let pchar = getline (line (' .' ))[col (' .' )-2 ]
136
142
let syn = synIDattr (synID (line (' .' ),col (' .' )-1 ,0 ),' name' )
137
- if pchar . char == ' */' && syn = ~? ' comment'
138
- if ! search (' \/\*' ,' bW' ) || ! search (' \S' ,' bW' )
139
- return 1
140
- endif
141
- let char = getline (line (' .' ))[col (' .' )-1 ]
142
- let pchar = getline (line (' .' ))[col (' .' )-2 ]
143
- let syn = synIDattr (synID (line (' .' ),col (' .' )-1 ,0 ),' name' )
144
- endif
145
- if syn = ~? ' \%(xml\|jsx\)'
146
- return char != ' {'
147
- elseif char = ~# ' \l'
148
- if line (' .' ) == l: ln && expand (' <cword>' ) == # ' return'
149
- return 0
150
- endif
151
- return expand (' <cword>' ) !~#
152
- \ ' ^\%(const\|let\|import\|export\|yield\|de\%(fault\|lete\)\|v\%(ar\|oid\)\|t\%(ypeof\|hrow\)\|new\|in\%(stanceof\)\=\)$'
153
- elseif char == ' >'
154
- return pchar == ' =' || syn = ~? ' ^jsflow'
155
- elseif char == ' :'
156
- return strpart (getline (line (' .' )),0 ,col (' .' )) = ~# s: expr_case . ' $'
157
- else
158
- return char !~# ' [-=~!<*+,/?^%|&([]'
143
+ endif
144
+ if syn = ~? ' \%(xml\|jsx\)'
145
+ return char != ' {'
146
+ elseif char = ~# ' \l'
147
+ if line (' .' ) == l: ln && expand (' <cword>' ) == # ' return'
148
+ return 0
159
149
endif
150
+ return index (split (' const let import export yield default delete var void typeof throw new in instanceof' )
151
+ \ , expand (' <cword>' )) < 0
152
+ elseif char == ' >'
153
+ return pchar == ' =' || syn = ~? ' ^jsflow'
154
+ elseif char == ' :'
155
+ return strpart (getline (line (' .' )),0 ,col (' .' )) = ~# s: expr_case . ' $'
160
156
else
161
- return 1
157
+ return char !~# ' [-=~!<*+,/?^%|&([] '
162
158
endif
159
+ else
160
+ return 1
163
161
endif
164
162
endfunction
165
163
@@ -254,14 +252,14 @@ function GetJavascriptIndent()
254
252
let num = s: GetPair (' [({[]' ,' [])}]' ,' bW' ,s: skip_expr ,200 ,l: lnum )
255
253
endif
256
254
257
- let num = ( num > 0 ) * num
255
+ let num = max ([ num, 0 ])
258
256
if l: line = ~ ' ^[])}]'
259
257
return ! ! num * indent (num)
260
258
endif
261
- let b: js_cache = [v: lnum ,num,line (' .' ) == v: lnum ? b: js_cache [2 ] : col (' .' )]
259
+ let b: js_cache = [v: lnum ,num,line (' .' ) == v: lnum && num ? b: js_cache [2 ] : col (' .' )]
262
260
263
261
call cursor (v: lnum ,1 )
264
- if l: line = ~# ' ^while\>' && s: GetPair (s: line_pre . ' \C\<do\>' ,' \C\<while\>' ,' bW' ,s: skip_expr ,100 ,num + 1 ) > 0
262
+ if l: line = ~# ' ^while\>' && s: GetPair (' \C\<do\>' ,' \C\<while\>' ,' bW' ,s: skip_expr . ' || !s:IsBlock() ' ,100 ,num + 1 ) > 0
265
263
return indent (line (' .' ))
266
264
endif
267
265
@@ -277,7 +275,7 @@ function GetJavascriptIndent()
277
275
let isOp = l: line = ~# g: javascript_opfirst || pline !~# s: expr_case . ' $' && pline = ~# g: javascript_continuation
278
276
let bL = s: iscontOne (l: lnum ,num,isOp)
279
277
let bL -= (bL && l: line = ~ ' ^{' ) * s: W
280
- if isOp && (! num || cursor (b: js_cache [1 ],b: js_cache [2 ]) || s: IsBlock ())
278
+ if isOp && (! num || cursor (b: js_cache [1 ],b: js_cache [2 ]) || ( getline ( line ( ' . ' ))[ col ( ' . ' ) -1 ] == ' { ' && s: IsBlock () ))
281
279
return (num ? indent (num) : - s: W ) + (s: W * 2 ) + switch_offset + bL
282
280
elseif num
283
281
return indent (num) + s: W + switch_offset + bL
0 commit comments