@@ -71,20 +71,19 @@ endif
71
71
let g: javascript_opfirst = s: line_pre . g: javascript_opfirst
72
72
let g: javascript_continuation .= s: line_term
73
73
74
- function s: OneScope (lnum,text, add )
74
+ function s: OneScope (lnum,text)
75
75
return a: text = ~# ' \%(\<else\|\<do\|=>\)' . s: line_term ? ' no b' :
76
- \ ((a: add && a: text = ~ s: line_pre . ' $' && search (' \%' . s: PrevCodeLine (a: lnum - 1 ) . ' l.)' . s: line_term )) ||
77
- \ cursor (a: lnum , match (a: text , ' )' . s: line_term )) > -1 ) &&
78
- \ s: GetPair (' (' , ' )' , ' cbW' , 100 ) > 0 && search (' \C\l\+\_s*\%#' ,' bW' ) &&
79
- \ (a: add || ((expand (' <cword>' ) !=# ' while' || ! s: GetPair (' \C\<do\>' , ' \C\<while\>' ,' nbW' ,100 )) &&
80
- \ (expand (' <cword>' ) !=# ' each' || search (' \C\<for\_s\+\%#' ,' nbW' )))) ? expand (' <cword>' ) : ' '
76
+ \ 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 ) &&
79
+ \ (expand (' <cword>' ) !=# ' each' || search (' \C\<for\_s\+\%#' ,' nbW' )) ? expand (' <cword>' ) : ' '
81
80
endfunction
82
81
83
82
" https://github.com/sweet-js/sweet.js/wiki/design#give-lookbehind-to-the-reader
84
83
function s: IsBlock ()
85
84
return getline (line (' .' ))[col (' .' )-1 ] == ' {' && ! search (
86
85
\ ' \C\%(\<return\s*\|\%([-=~!<*+,.?^%|&\[(]\|=\@<!>\|\*\@<!\/\|\<\%(var\|const\|let\|import\|export\%(\_s\+default\)\=\|yield\|delete\|void\|t\%(ypeof\|hrow\)\|new\|in\%(stanceof\)\=\)\)\_s*\)\%#' ,' bnW' ) &&
87
- \ (! search (' \%({\|:\zs\)\ _s*\%#' ,' bW ' ) || search (s: expr_case . ' \ %#' , ' nbW ' ) || s: IsBlock ())
86
+ \ (search (s: expr_case . ' \ _s*\%#' ,' nbW ' ) || ! search (' [{:]\_s*\ %#' , ' bW ' ) || s: IsBlock ())
88
87
endfunction
89
88
90
89
" Auxiliary Functions {{{2
@@ -174,14 +173,16 @@ function GetJavascriptIndent()
174
173
endif
175
174
176
175
let pline = substitute (substitute (getline (l: lnum ),s: expr_case ,' \=repeat(" ",strlen(submatch(0)))' ,' ' ), ' \%(:\@<!\/\/.*\)$' , ' ' ,' ' )
177
- let switch_offset = num <= 0 || s: OneScope (num, strpart (getline (num),0 ,b: js_cache [2 ] - 1 ),1 ) !=# ' switch' ? 0 :
178
- \ &cino !~ ' :' || ! has (' float' ) ? s: sw () :
176
+ call cursor (b: js_cache [1 ],b: js_cache [2 ])
177
+ let switch_offset = num <= 0 || ! (search (' )\_s*\%#' ,' bW' ) &&
178
+ \ s: GetPair (' (' , ' )' , ' bW' , 100 ) > 0 && search (' \C\<switch\_s*\%#' ,' bW' )) ? 0 :
179
+ \ &cino !~ ' :' || ! has (' float' ) ? s: sw () :
179
180
\ float2nr (str2float (matchstr (&cino ,' .*:\zs[-0-9.]*' )) * (&cino = ~# ' .*:[^,]*s' ? s: sw () : 1 ))
180
181
181
182
" most significant, find the indent amount
182
183
let isOp = l: line = ~# g: javascript_opfirst || pline = ~# g: javascript_continuation
183
184
if isOp && (num <= 0 || cursor (b: js_cache [1 ],b: js_cache [2 ]) || s: IsBlock ()) ||
184
- \ s: OneScope (l: lnum ,pline, 0 ) = ~# ' \<\%(for\|each\|if\|let\|no\sb\|w\%(hile\|ith\)\)\>' &&
185
+ \ s: OneScope (l: lnum ,pline) = ~# ' \<\%(for\|each\|if\|let\|no\sb\|w\%(hile\|ith\)\)\>' &&
185
186
\ l: line !~ s: line_pre . ' {'
186
187
return (num > 0 ? indent (num) : - s: sw ()) + (s: sw () * 2 ) + switch_offset
187
188
elseif num > 0
0 commit comments