Skip to content

Commit 85804bb

Browse files
authored
optimize
1 parent a0e1442 commit 85804bb

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

indent/javascript.vim

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,18 +240,18 @@ function s:Continues()
240240
endfunction
241241

242242
" Check if line 'lnum' has a balanced amount of parentheses.
243-
function s:Balanced(lnum)
244-
let [l:open, l:line] = [0, getline(a:lnum)]
245-
let pos = match(l:line, '[][(){}]')
243+
function s:Balanced(lnum,line)
244+
let l:open = 0
245+
let pos = match(a:line, '[][(){}]')
246246
while pos != -1
247247
if s:SynAt(a:lnum,pos + 1) !~? b:syng_strcom
248-
let l:open += match(' ' . l:line[pos],'[[({]')
248+
let l:open += match(' ' . a:line[pos],'[[({]')
249249
if l:open < 0
250250
return
251251
endif
252252
endif
253-
let pos = match(l:line, !l:open ? '[][(){}]' : '()' =~ l:line[pos] ?
254-
\ '[()]' : '{}' =~ l:line[pos] ? '[{}]' : '[][]', pos + 1)
253+
let pos = match(a:line, !l:open ? '[][(){}]' : '()' =~ a:line[pos] ?
254+
\ '[()]' : '{}' =~ a:line[pos] ? '[{}]' : '[][]', pos + 1)
255255
endwhile
256256
return !l:open
257257
endfunction
@@ -356,7 +356,7 @@ function GetJavascriptIndent()
356356
return -1
357357
endif
358358
elseif s:stack[-1] =~? b:syng_str
359-
if b:js_cache[0] == v:lnum - 1 && s:Balanced(v:lnum-1)
359+
if b:js_cache[0] == v:lnum - 1 && s:Balanced(v:lnum-1,getline(v:lnum-1))
360360
let b:js_cache[0] = v:lnum
361361
endif
362362
return -1
@@ -383,7 +383,7 @@ function GetJavascriptIndent()
383383
call cursor(v:lnum,1)
384384
let idx = index([']',')','}'],l:line[0])
385385
if b:js_cache[0] > l:lnum && b:js_cache[0] < v:lnum ||
386-
\ b:js_cache[0] == l:lnum && s:Balanced(l:lnum)
386+
\ b:js_cache[0] == l:lnum && s:Balanced(l:lnum,pline)
387387
call call('cursor',b:js_cache[1:])
388388
else
389389
let [s:looksyn, s:top_col, s:check_in, s:l1] = [v:lnum - 1,0,0,

0 commit comments

Comments
 (0)