26
26
let s: cpo_save = &cpo
27
27
set cpo &vim
28
28
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
+
29
40
" 1. Variables {{{1
30
41
" ============
31
42
@@ -55,7 +66,7 @@ let s:continuation_regex = '\%([\\*+/.:]\|\%(<%\)\@<![=-]\|\W[|&?]\|||\|&&\|[^=]
55
66
" TODO: this needs to deal with if ...: and so on
56
67
let s: msl_regex = s: continuation_regex .' |' .s: expr_case
57
68
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
59
70
60
71
" Regex that defines blocks.
61
72
let s: block_regex = ' \%([{[]\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s: line_term
@@ -68,15 +79,15 @@ let s:comma_last = ',\s*$'
68
79
let s: ternary = ' ^\s\+[?|:]'
69
80
let s: ternary_q = ' ^\s\+?'
70
81
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 ]
76
87
endif
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 ]
80
91
endif
81
92
" 2. Auxiliary Functions {{{1
82
93
" ======================
@@ -201,9 +212,9 @@ function s:GetVarIndent(lnum)
201
212
202
213
" if the previous line doesn't end in a comma, return to regular indent
203
214
if (line !~ s: comma_last )
204
- return indent (prev_lnum) - & sw
215
+ return indent (prev_lnum) - s: sw ()
205
216
else
206
- return indent (lvar) + & sw
217
+ return indent (lvar) + s: sw ()
207
218
endif
208
219
endif
209
220
@@ -342,7 +353,7 @@ function GetJavascriptIndent()
342
353
return indent (prevline)
343
354
" otherwise we indent 1 level
344
355
else
345
- return indent (lvar) + & sw
356
+ return indent (lvar) + s: sw ()
346
357
endif
347
358
endif
348
359
endif
@@ -361,7 +372,7 @@ function GetJavascriptIndent()
361
372
362
373
" If the line is comma first, dedent 1 level
363
374
if (getline (prevline) = ~ s: comma_first )
364
- return indent (prevline) - & sw
375
+ return indent (prevline) - s: sw ()
365
376
endif
366
377
if (getline (prevline) = ~ s: expr_case )
367
378
return indent (prevline) + s: case_indent_after
@@ -371,7 +382,7 @@ function GetJavascriptIndent()
371
382
if (getline (prevline) = ~ s: ternary_q )
372
383
return indent (prevline)
373
384
else
374
- return indent (prevline) + & sw
385
+ return indent (prevline) + s: sw ()
375
386
endif
376
387
endif
377
388
@@ -413,9 +424,9 @@ function GetJavascriptIndent()
413
424
" If the previous line ended with a block opening, add a level of indent.
414
425
if s: Match (lnum, s: block_regex )
415
426
if (line = ~ s: expr_case )
416
- return indent (s: GetMSL (lnum, 0 )) + & sw /2
427
+ return indent (s: GetMSL (lnum, 0 )) + s: sw () /2
417
428
else
418
- return indent (s: GetMSL (lnum, 0 )) + & sw
429
+ return indent (s: GetMSL (lnum, 0 )) + s: sw ()
419
430
endif
420
431
endif
421
432
@@ -428,12 +439,12 @@ function GetJavascriptIndent()
428
439
let counts = s: LineHasOpeningBrackets (lnum)
429
440
if counts[0 ] == ' 1' && searchpair (' (' , ' ' , ' )' , ' bW' , s: skip_expr ) > 0
430
441
if col (' .' ) + 1 == col (' $' )
431
- return ind + & sw
442
+ return ind + s: sw ()
432
443
else
433
444
return virtcol (' .' )
434
445
endif
435
446
elseif counts[1 ] == ' 1' || counts[2 ] == ' 1'
436
- return ind + & sw
447
+ return ind + s: sw ()
437
448
else
438
449
call cursor (v: lnum , vcol)
439
450
end
@@ -443,18 +454,18 @@ function GetJavascriptIndent()
443
454
" --------------------------
444
455
445
456
let ind_con = ind
446
- let ind = s: IndentWithContinuation (lnum, ind_con, & sw )
457
+ let ind = s: IndentWithContinuation (lnum, ind_con, s: sw () )
447
458
448
459
" }}}2
449
460
"
450
461
"
451
462
let ols = s: InOneLineScope (lnum)
452
463
if ols > 0
453
- let ind = ind + & sw
464
+ let ind = ind + s: sw ()
454
465
else
455
466
let ols = s: ExitingOneLineScope (lnum)
456
467
while ols > 0 && ind > 0
457
- let ind = ind - & sw
468
+ let ind = ind - s: sw ()
458
469
let ols = s: InOneLineScope (ols - 1 )
459
470
endwhile
460
471
endif
0 commit comments