Skip to content

more optimization #646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 25, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions indent/javascript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ function GetJavascriptIndent()
return ind
endif

let l:line = substitute(l:line,s:line_pre,'','')

" the containing paren, bracket, curly. Memoize, last lineNr either has the
" same scope or starts a new one, unless if it closed a scope.
call cursor(v:lnum,1)
Expand All @@ -186,7 +188,10 @@ function GetJavascriptIndent()
if b:js_cache[0] < v:lnum && b:js_cache[0] >= l:lnum &&
\ (b:js_cache[0] > l:lnum || s:Balanced(l:lnum))
let num = b:js_cache[1]
elseif syns != '' && l:line[0] =~ '\s'
elseif l:line =~ '^[])}]'
let id = stridx('])}',l:line[0])
let num = s:GetPair(escape('[({'[id],'['), escape('])}'[id],']'),'bW','s:skip_func(s:looksyn)',2000)
elseif syns != '' && getline(v:lnum)[0] =~ '\s'
let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] :
\ syns =~? 'jsbracket'? ['\[','\]'] : ['[({[]','[])}]']
let num = s:GetPair(pattern[0],pattern[1],'bW','s:skip_func(s:looksyn)',2000)
Expand All @@ -200,7 +205,6 @@ function GetJavascriptIndent()
let num = (num > 0) * num
let b:js_cache = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')]

let l:line = substitute(l:line,s:line_pre,'','')
if l:line =~ '^[])}]'
return !!num * indent(num)
endif
Expand Down