|
2 | 2 | " Language: Javascript |
3 | 3 | " Maintainer: vim-javascript community |
4 | 4 | " URL: https://github.com/pangloss/vim-javascript |
5 | | -" Last Change: August 15, 2016 |
| 5 | +" Last Change: August 16, 2016 |
6 | 6 |
|
7 | 7 | " Only load this indent file when no other was loaded. |
8 | 8 | if exists('b:did_indent') |
@@ -46,27 +46,29 @@ let s:syng_strcom = '\%(s\%(tring\|pecial\)\|comment\|regex\|doc\|template\)' |
46 | 46 | let s:syng_comment = '\%(comment\|doc\)' |
47 | 47 |
|
48 | 48 | " Expression used to check whether we should skip a match with searchpair(). |
49 | | -let s:skip_expr = "line('.') < (prevnonblank(v:lnum) - 2000) ? dummy : synIDattr(synID(line('.'),col('.'),0),'name') =~? '".s:syng_strcom."'" |
| 49 | +let s:skip_expr = "synIDattr(synID(line('.'),col('.'),0),'name') =~? '".s:syng_strcom."'" |
50 | 50 |
|
51 | | -function s:lookForParens(start,end,flags,time) |
52 | | - if has('reltime') |
53 | | - return searchpair(a:start,'',a:end,a:flags,s:skip_expr,0,a:time) |
54 | | - else |
55 | | - return searchpair(a:start,'',a:end,a:flags,0,0) |
56 | | - endif |
57 | | -endfunction |
| 51 | +if has('reltime') |
| 52 | + function s:lookForParens(start,end,flags,time) |
| 53 | + return searchpair(a:start,'',a:end,a:flags,s:skip_expr,max([prevnonblank(v:lnum) - 2000,0]),a:time) |
| 54 | + endfunction |
| 55 | +else |
| 56 | + function s:lookForParens(start,end,flags,n) |
| 57 | + return searchpair(a:start,'',a:end,a:flags,0,max([prevnonblank(v:lnum) - 2000,0])) |
| 58 | + endfunction |
| 59 | +endif |
58 | 60 |
|
59 | 61 | let s:line_term = '\%(\s*\%(\/\*.\{-}\*\/\s*\)\=\)\@>$' |
60 | 62 |
|
61 | 63 | " configurable regexes that define continuation lines, not including (, {, or [. |
62 | 64 | if !exists('g:javascript_opfirst') |
63 | 65 | let g:javascript_opfirst = '\%([<>,:?^%|&]\|\([-/.+]\)\%(\1\|\*\|\/\)\@!\|\*\/\@!\|=>\@!\|in\%(stanceof\)\=\>\)' |
64 | 66 | endif |
65 | | -let g:javascript_opfirst = s:line_pre . g:javascript_opfirst |
66 | | - |
67 | 67 | if !exists('g:javascript_continuation') |
68 | 68 | let g:javascript_continuation = '\%([<=*,.?:^%|&]\|+\@<!+\|-\@<!-\|=\@<!>\|\*\@<!\/\|\<in\%(stanceof\)\=\)' |
69 | 69 | endif |
| 70 | + |
| 71 | +let g:javascript_opfirst = s:line_pre . g:javascript_opfirst |
70 | 72 | let g:javascript_continuation .= s:line_term |
71 | 73 |
|
72 | 74 | function s:Onescope(lnum,text,add) |
@@ -95,13 +97,12 @@ endfunction |
95 | 97 | " Find line above 'lnum' that isn't empty, in a comment, or in a string. |
96 | 98 | function s:PrevCodeLine(lnum) |
97 | 99 | let l:lnum = prevnonblank(a:lnum) |
98 | | - while l:lnum > 0 |
| 100 | + while l:lnum |
99 | 101 | if synIDattr(synID(l:lnum,matchend(getline(l:lnum), '^\s*[^''"]'),0),'name') !~? s:syng_strcom |
100 | | - break |
| 102 | + return l:lnum |
101 | 103 | endif |
102 | 104 | let l:lnum = prevnonblank(l:lnum - 1) |
103 | 105 | endwhile |
104 | | - return l:lnum |
105 | 106 | endfunction |
106 | 107 |
|
107 | 108 | " Check if line 'lnum' has a balanced amount of parentheses. |
@@ -176,7 +177,7 @@ function GetJavascriptIndent() |
176 | 177 | endif |
177 | 178 |
|
178 | 179 | let pline = s:StripLine(getline(l:lnum)) |
179 | | - call cursor(b:js_cache[1:]) |
| 180 | + call cursor(b:js_cache[1],b:js_cache[2]) |
180 | 181 | let inb = num == 0 || num < l:lnum && ((l:line !~ s:line_pre . ',' && pline !~ ',' . s:line_term) || s:isBlock()) |
181 | 182 | let switch_offset = num == 0 || s:Onescope(num, s:StripLine(strpart(getline(num),0,b:js_cache[2] - 1)),1) !=# 'switch' ? 0 : |
182 | 183 | \ &cino !~ ':' || !has('float') ? s:sw() : |
|
0 commit comments