diff --git a/README.md b/README.md index 662a2006..1cd79f4c 100644 --- a/README.md +++ b/README.md @@ -100,8 +100,6 @@ variables: ## Indentation Specific * `:h cino-:` -* End-of-line continuations : `g:javascript_continuation` ( slightly complicated, look at the source code ) -* Start-of-line continuations : `g:javascript_opfirst` ( same as above ) ## Contributing diff --git a/indent/javascript.vim b/indent/javascript.vim index 694403af..07800524 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -62,10 +62,10 @@ let s:line_term = '\s*\%(\%(\/\%(\%(\*.\{-}\*\/\)\|\%(\*\+\)\)\)\s*\)\=$' " configurable regexes that define continuation lines, not including (, {, or [. if !exists('g:javascript_opfirst') - let g:javascript_opfirst = '\%([<>,:?^%|*&]\|\/[^/*]\|\([-.+]\)\1\@!\|=>\@!\|in\%(stanceof\)\=\>\)' + let g:javascript_opfirst = '\%([<>,?^%|*&]\|\/[^/*]\|\([-.:+]\)\1\@!\|=>\@!\|in\%(stanceof\)\=\>\)' endif if !exists('g:javascript_continuation') - let g:javascript_continuation = '\%([<=,.?/*:^%|&]\|+\@\|\= l:lnum && b:js_cache[0] < v:lnum && b:js_cache[0] && \ (b:js_cache[0] > l:lnum || s:Balanced(l:lnum) > 0) + let known = 1 let num = b:js_cache[1] elseif syns != '' && l:line[0] =~ '\s' let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : @@ -163,28 +168,32 @@ function GetJavascriptIndent() else let num = s:GetPair('[({[]','[])}]','bW',2000) endif - let b:js_cache = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] + + if known && b:js_cache[3] + let known = indent(b:js_cache[0]) - b:js_cache[3] + endif + + let b:js_cache[:2] = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] if l:line =~ s:line_pre . '[])}]' return indent(num) endif - call cursor(b:js_cache[1],b:js_cache[2]) - let swcase = getline(l:lnum) =~# s:expr_case - let pline = swcase ? getline(l:lnum) : substitute(getline(l:lnum), '\%(:\@' && - \ l:line !~ s:line_pre . '{') - return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset + if ((l:line =~# g:javascript_opfirst || pline !~# s:expr_case . s:line_term && pline =~# g:javascript_continuation) || + \ s:OneScope(l:lnum,pline,0) =~# '\<\%(for\|each\|if\|let\|no\sb\|w\%(hile\|ith\)\)\>' && + \ l:line !~ s:line_pre . '{') && (num == 0 || cursor(b:js_cache[1],b:js_cache[2]) || s:IsBlock()) + let b:js_cache[3] = (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset + return b:js_cache[3] + known elseif num > 0 - return indent(num) + s:sw() + switch_offset + let b:js_cache[3] = indent(num) + s:sw() + switch_offset + return b:js_cache[3] + known endif endfunction