@@ -174,24 +174,23 @@ endfunction
174
174
175
175
" Check if line 'lnum' has a balanced amount of parentheses.
176
176
function s: Balanced (lnum)
177
- let [open_0,open_2,open_4] = [ 0 , 0 , 0 ]
177
+ let l: open = 0
178
178
let l: line = getline (a: lnum )
179
179
let pos = match (l: line , ' [][(){}]' , 0 )
180
180
while pos != -1
181
181
if synIDattr (synID (a: lnum ,pos + 1 ,0 ),' name' ) !~? s: syng_strcom
182
- let idx = stridx (' (){}[]' , l: line [pos])
183
- if ! (idx % 2 )
184
- let open_{idx} += 1
182
+ if l: line [pos] = ~ ' [{([]'
183
+ let l: open += 1
185
184
else
186
- let open_{idx - 1 } -= 1
187
- if open_{idx - 1 } < 0
185
+ let l: open -= 1
186
+ if l: open < 0
188
187
return 0
189
188
endif
190
189
endif
191
190
endif
192
191
let pos = match (l: line , ' [][(){}]' , pos + 1 )
193
192
endwhile
194
- return ! (open_4 || open_2 || open_0)
193
+ return ! l: open
195
194
endfunction
196
195
197
196
function GetJavascriptIndent ()
@@ -230,18 +229,17 @@ function GetJavascriptIndent()
230
229
return ind
231
230
endif
232
231
233
- " the containing paren, bracket, curly. Memoize, last lineNr either has the
234
- " same scope or starts a new one, unless if it closed a scope.
232
+ " the containing paren, bracket, curly. Many hacks for performance
235
233
call cursor (v: lnum ,1 )
236
234
let fclose = l: line = ~ ' ^[])}]'
237
235
if indent (l: lnum )
238
236
let [s: looksyn ,s: free ] = [v: lnum - 1 ,1 ]
239
237
if b: js_cache [0 ] >= l: lnum && b: js_cache [0 ] < v: lnum &&
240
- \ (b: js_cache [0 ] > l: lnum || s: Balanced (l: lnum ))
238
+ \ (b: js_cache [0 ] > l: lnum || ! fclose && s: Balanced (l: lnum ))
241
239
let num = b: js_cache [1 ]
242
240
elseif fclose
243
241
let id = stridx (' ])}' ,l: line [0 ])
244
- let num = s: GetPair (escape (' [({' [id],' [' ), escape ( ' ])}' [id],' ] ' ), ' bW' ,' s:skip_func(s:looksyn)' ,2000 )
242
+ return indent ( s: GetPair (escape (' [({' [id],' [' ), ' ])}' [id],' bW' ,' s:skip_func(s:looksyn)' ,2000 ) )
245
243
elseif indent (v: lnum ) && syns = ~? ' block'
246
244
let num = s: GetPair (' {' ,' }' ,' bW' ,' s:skip_func(s:looksyn)' ,2000 )
247
245
else
@@ -251,10 +249,10 @@ function GetJavascriptIndent()
251
249
let num = s: GetPair (' [({[]' ,' [])}]' ,' bW' ,s: skip_expr ,200 ,l: lnum )
252
250
endif
253
251
254
- let num = max ([num,0 ])
255
252
if fclose
256
- return ! ! num * indent (num)
253
+ return indent (num)
257
254
endif
255
+ let num = max ([num,0 ])
258
256
let b: js_cache = [v: lnum ,num,line (' .' ) == v: lnum && num ? b: js_cache [2 ] : col (' .' )]
259
257
260
258
call cursor (v: lnum ,1 )
@@ -281,11 +279,11 @@ function GetJavascriptIndent()
281
279
return indent (num) + s: W + switch_offset + bL
282
280
endif
283
281
return bL
282
+
284
283
finally
285
284
let &magic = save_magic
286
285
endtry
287
286
endfunction
288
287
289
-
290
288
let &cpo = s: cpo_save
291
289
unlet s: cpo_save
0 commit comments