@@ -47,13 +47,23 @@ let s:syng_comment = '\%(comment\|doc\)'
47
47
48
48
" Expression used to check whether we should skip a match with searchpair().
49
49
let s: skip_expr = " synIDattr(synID(line('.'),col('.'),0),'name') =~? '" .s: syng_strcom ." '"
50
+ function s: skip_func (lnum)
51
+ if ! s: free || getline (line (' .' )) = ~ ' ['' /"\\]'
52
+ return eval (s: skip_expr )
53
+ endif
54
+ if search (' `' ,' nW' ,a: lnum ) || search (' \*\/' ,' nW' ,a: lnum )
55
+ let s: free = ! eval (s: skip_expr )
56
+ endif
57
+ let s: looksyn = s: free ? line (' .' ) : s: looksyn
58
+ return ! s: free
59
+ endfunction
50
60
51
61
if has (' reltime' )
52
- function s: GetPair (start ,end ,flags,time)
53
- return searchpair (a: start ,' ' ,a: end ,a: flags ,s: skip_expr ,max ([prevnonblank (v: lnum ) - 2000 ,0 ]),a: time )
62
+ function s: GetPair (start ,end ,flags,skip , time)
63
+ return searchpair (a: start ,' ' ,a: end ,a: flags ,a: skip ,max ([prevnonblank (v: lnum ) - 2000 ,0 ]),a: time )
54
64
endfunction
55
65
else
56
- function s: GetPair (start ,end ,flags,n )
66
+ function s: GetPair (start ,end ,flags,... )
57
67
return searchpair (a: start ,' ' ,a: end ,a: flags ,0 ,max ([prevnonblank (v: lnum ) - 2000 ,0 ]))
58
68
endfunction
59
69
endif
@@ -74,8 +84,8 @@ let g:javascript_continuation .= s:line_term
74
84
function s: OneScope (lnum,text)
75
85
return a: text = ~# ' \%(\<else\|\<do\|=>\)' . s: line_term ? ' no b' :
76
86
\ cursor (a: lnum , match (' ' . a: text , ' )' . s: line_term )) > -1 &&
77
- \ s: GetPair (' (' , ' )' , ' bW' , 100 ) > 0 && search (' \C\l\+\_s*\%#' ,' bW' ) &&
78
- \ (expand (' <cword>' ) !=# ' while' || s: GetPair (' \C\<do\>' , ' \C\<while\>' ,' nbW' ,100 ) <= 0 ) &&
87
+ \ s: GetPair (' (' , ' )' , ' bW' , s: skip_expr , 100 ) > 0 && search (' \C\l\+\_s*\%#' ,' bW' ) &&
88
+ \ (expand (' <cword>' ) !=# ' while' || s: GetPair (' \C\<do\>' , ' \C\<while\>' ,' nbW' ,s: skip_expr , 100 ) <= 0 ) &&
79
89
\ (expand (' <cword>' ) !=# ' each' || search (' \C\<for\_s\+\%#' ,' nbW' )) ? expand (' <cword>' ) : ' '
80
90
endfunction
81
91
@@ -131,7 +141,7 @@ function GetJavascriptIndent()
131
141
let syns = synIDattr (synID (v: lnum , 1 , 0 ), ' name' )
132
142
133
143
" start with strings,comments,etc.{{{2
134
- if (l: line !~ ' ^['' "` ]' && syns = ~? ' \%(string\|template\)' ) ||
144
+ if (l: line !~ ' ^['' "]' && syns = ~? ' \%(string\|template\)' ) ||
135
145
\ (l: line !~ ' ^\s*[/*]' && syns = ~? s: syng_comment )
136
146
return -1
137
147
endif
@@ -154,16 +164,17 @@ function GetJavascriptIndent()
154
164
155
165
" the containing paren, bracket, curly. Memoize, last lineNr either has the
156
166
" same scope or starts a new one, unless if it closed a scope.
167
+ let [s: looksyn ,s: free ] = [v: lnum - 1 ,1 ]
157
168
call cursor (v: lnum ,1 )
158
169
if b: js_cache [0 ] < v: lnum && b: js_cache [0 ] >= l: lnum &&
159
170
\ (b: js_cache [0 ] > l: lnum || s: Balanced (l: lnum ) > 0 )
160
171
let num = b: js_cache [1 ]
161
172
elseif syns != ' ' && l: line [0 ] = ~ ' \s'
162
173
let pattern = syns = ~? ' block' ? [' {' ,' }' ] : syns = ~? ' jsparen' ? [' (' ,' )' ] :
163
174
\ syns = ~? ' jsbracket' ? [' \[' ,' \]' ] : [' [({[]' ,' [])}]' ]
164
- let num = s: GetPair (pattern[0 ],pattern[1 ],' bW' ,2000 )
175
+ let num = s: GetPair (pattern[0 ],pattern[1 ],' bW' ,' s:skip_func(s:looksyn) ' , 2000 )
165
176
else
166
- let num = s: GetPair (' [({[]' ,' [])}]' ,' bW' ,2000 )
177
+ let num = s: GetPair (' [({[]' ,' [])}]' ,' bW' ,' s:skip_func(s:looksyn) ' , 2000 )
167
178
endif
168
179
169
180
let b: js_cache = [v: lnum ,num,line (' .' ) == v: lnum ? b: js_cache [2 ] : col (' .' )]
@@ -175,7 +186,7 @@ function GetJavascriptIndent()
175
186
let pline = substitute (substitute (getline (l: lnum ),s: expr_case ,' \=repeat(" ",strlen(submatch(0)))' ,' ' ), ' \%(:\@<!\/\/.*\)$' , ' ' ,' ' )
176
187
call cursor (b: js_cache [1 ],b: js_cache [2 ])
177
188
let switch_offset = num <= 0 || ! (search (' )\_s*\%#' ,' bW' ) &&
178
- \ s: GetPair (' (' , ' )' , ' bW' , 100 ) > 0 && search (' \C\<switch\_s*\%#' ,' bW' )) ? 0 :
189
+ \ s: GetPair (' (' , ' )' , ' bW' , s: skip_expr , 100 ) > 0 && search (' \C\<switch\_s*\%#' ,' bW' )) ? 0 :
179
190
\ &cino !~ ' :' || ! has (' float' ) ? s: sw () :
180
191
\ float2nr (str2float (matchstr (&cino ,' .*:\zs[-0-9.]*' )) * (&cino = ~# ' .*:[^,]*s' ? s: sw () : 1 ))
181
192
0 commit comments