Skip to content

Commit 32137f1

Browse files
committed
Use shfitwidth() instead of &sw in indent/javascript.vim
1 parent 91fa38c commit 32137f1

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

indent/javascript.vim

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ endif
2626
let s:cpo_save = &cpo
2727
set 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

@@ -68,8 +79,8 @@ let s:comma_last = ',\s*$'
6879
let s:ternary = '^\s\+[?|:]'
6980
let s:ternary_q = '^\s\+?'
7081

71-
let s:case_indent = &sw
72-
let s:case_indent_after = &sw
82+
let s:case_indent = s:sw()
83+
let s:case_indent_after = s:sw()
7384
let s:m = matchlist(&cinoptions, ':\(.\)')
7485
if (len(s:m) > 2)
7586
let s:case_indent = s:m[1]
@@ -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

Comments
 (0)