Skip to content

Commit dc67840

Browse files
authored
more optimization (#646)
1 parent 02c8c64 commit dc67840

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

indent/javascript.vim

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ function GetJavascriptIndent()
178178
return ind
179179
endif
180180

181+
let l:line = substitute(l:line,s:line_pre,'','')
182+
181183
" the containing paren, bracket, curly. Memoize, last lineNr either has the
182184
" same scope or starts a new one, unless if it closed a scope.
183185
call cursor(v:lnum,1)
@@ -186,7 +188,10 @@ function GetJavascriptIndent()
186188
if b:js_cache[0] < v:lnum && b:js_cache[0] >= l:lnum &&
187189
\ (b:js_cache[0] > l:lnum || s:Balanced(l:lnum))
188190
let num = b:js_cache[1]
189-
elseif syns != '' && l:line[0] =~ '\s'
191+
elseif l:line =~ '^[])}]'
192+
let id = stridx('])}',l:line[0])
193+
let num = s:GetPair(escape('[({'[id],'['), escape('])}'[id],']'),'bW','s:skip_func(s:looksyn)',2000)
194+
elseif syns != '' && getline(v:lnum)[0] =~ '\s'
190195
let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] :
191196
\ syns =~? 'jsbracket'? ['\[','\]'] : ['[({[]','[])}]']
192197
let num = s:GetPair(pattern[0],pattern[1],'bW','s:skip_func(s:looksyn)',2000)
@@ -200,7 +205,6 @@ function GetJavascriptIndent()
200205
let num = (num > 0) * num
201206
let b:js_cache = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')]
202207

203-
let l:line = substitute(l:line,s:line_pre,'','')
204208
if l:line =~ '^[])}]'
205209
return !!num * indent(num)
206210
endif

0 commit comments

Comments
 (0)