2626let s: cpo_save = &cpo
2727set cpo &vim
2828
29+ " Get shiftwidth value
30+ if exists (' *shiftwidth' )
31+ func s: sw ()
32+ return shiftwidth ()
33+ endfunc
34+ else
35+ func s: sw ()
36+ return &sw
37+ endfunc
38+ endif
39+
2940" 1. Variables {{{1
3041" ============
3142
@@ -55,7 +66,7 @@ let s:continuation_regex = '\%([\\*+/.:]\|\%(<%\)\@<![=-]\|\W[|&?]\|||\|&&\|[^=]
5566" TODO: this needs to deal with if ...: and so on
5667let s: msl_regex = s: continuation_regex .' |' .s: expr_case
5768
58- let s: one_line_scope_regex = ' \<\ %(if\|else\| for\|while\)\>[^{;]* ' . s: line_term
69+ let s: one_line_scope_regex = ' \%(\<else\>\|\<\ %(if\|for\|while\)\>\s*(.*)\) ' . s: line_term
5970
6071" Regex that defines blocks.
6172let s: block_regex = ' \%([{[]\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s: line_term
@@ -68,15 +79,15 @@ let s:comma_last = ',\s*$'
6879let s: ternary = ' ^\s\+[?|:]'
6980let s: ternary_q = ' ^\s\+?'
7081
71- let s: case_indent = & sw
72- let s: case_indent_after = & sw
73- let m = matchlist (&cinoptions , ' :\(.\)' )
74- if (len (m ) > 2 )
75- let s: case_indent = m [1 ]
82+ let s: case_indent = s: sw ()
83+ let s: case_indent_after = s: sw ()
84+ let s: m = matchlist (&cinoptions , ' :\(.\)' )
85+ if (len (s: m ) > 2 )
86+ let s: case_indent = s: m [1 ]
7687endif
77- let m = matchlist (&cinoptions , ' =\(.\)' )
78- if (len (m ) > 2 )
79- let s: case_indent_after = m [1 ]
88+ let s: m = matchlist (&cinoptions , ' =\(.\)' )
89+ if (len (s: m ) > 2 )
90+ let s: case_indent_after = s: m [1 ]
8091endif
8192" 2. Auxiliary Functions {{{1
8293" ======================
@@ -201,9 +212,9 @@ function s:GetVarIndent(lnum)
201212
202213 " if the previous line doesn't end in a comma, return to regular indent
203214 if (line !~ s: comma_last )
204- return indent (prev_lnum) - & sw
215+ return indent (prev_lnum) - s: sw ()
205216 else
206- return indent (lvar) + & sw
217+ return indent (lvar) + s: sw ()
207218 endif
208219 endif
209220
@@ -342,7 +353,7 @@ function GetJavascriptIndent()
342353 return indent (prevline)
343354 " otherwise we indent 1 level
344355 else
345- return indent (lvar) + & sw
356+ return indent (lvar) + s: sw ()
346357 endif
347358 endif
348359 endif
@@ -361,7 +372,7 @@ function GetJavascriptIndent()
361372
362373 " If the line is comma first, dedent 1 level
363374 if (getline (prevline) = ~ s: comma_first )
364- return indent (prevline) - & sw
375+ return indent (prevline) - s: sw ()
365376 endif
366377 if (getline (prevline) = ~ s: expr_case )
367378 return indent (prevline) + s: case_indent_after
@@ -371,7 +382,7 @@ function GetJavascriptIndent()
371382 if (getline (prevline) = ~ s: ternary_q )
372383 return indent (prevline)
373384 else
374- return indent (prevline) + & sw
385+ return indent (prevline) + s: sw ()
375386 endif
376387 endif
377388
@@ -413,9 +424,9 @@ function GetJavascriptIndent()
413424 " If the previous line ended with a block opening, add a level of indent.
414425 if s: Match (lnum, s: block_regex )
415426 if (line = ~ s: expr_case )
416- return indent (s: GetMSL (lnum, 0 )) + & sw /2
427+ return indent (s: GetMSL (lnum, 0 )) + s: sw () /2
417428 else
418- return indent (s: GetMSL (lnum, 0 )) + & sw
429+ return indent (s: GetMSL (lnum, 0 )) + s: sw ()
419430 endif
420431 endif
421432
@@ -428,12 +439,12 @@ function GetJavascriptIndent()
428439 let counts = s: LineHasOpeningBrackets (lnum)
429440 if counts[0 ] == ' 1' && searchpair (' (' , ' ' , ' )' , ' bW' , s: skip_expr ) > 0
430441 if col (' .' ) + 1 == col (' $' )
431- return ind + & sw
442+ return ind + s: sw ()
432443 else
433444 return virtcol (' .' )
434445 endif
435446 elseif counts[1 ] == ' 1' || counts[2 ] == ' 1'
436- return ind + & sw
447+ return ind + s: sw ()
437448 else
438449 call cursor (v: lnum , vcol)
439450 end
@@ -443,18 +454,18 @@ function GetJavascriptIndent()
443454 " --------------------------
444455
445456 let ind_con = ind
446- let ind = s: IndentWithContinuation (lnum, ind_con, & sw )
457+ let ind = s: IndentWithContinuation (lnum, ind_con, s: sw () )
447458
448459 " }}}2
449460 "
450461 "
451462 let ols = s: InOneLineScope (lnum)
452463 if ols > 0
453- let ind = ind + & sw
464+ let ind = ind + s: sw ()
454465 else
455466 let ols = s: ExitingOneLineScope (lnum)
456467 while ols > 0 && ind > 0
457- let ind = ind - & sw
468+ let ind = ind - s: sw ()
458469 let ols = s: InOneLineScope (ols - 1 )
459470 endwhile
460471 endif
0 commit comments