Skip to content

Use shiftwidth() instead of &sw in indent/javascript.vim #348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions indent/javascript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ endif
let s:cpo_save = &cpo
set cpo&vim

" Get shiftwidth value
if exists('*shiftwidth')
func s:sw()
return shiftwidth()
endfunc
else
func s:sw()
return &sw
endfunc
endif

" 1. Variables {{{1
" ============

Expand Down Expand Up @@ -68,8 +79,8 @@ let s:comma_last = ',\s*$'
let s:ternary = '^\s\+[?|:]'
let s:ternary_q = '^\s\+?'

let s:case_indent = &sw
let s:case_indent_after = &sw
let s:case_indent = s:sw()
let s:case_indent_after = s:sw()
let s:m = matchlist(&cinoptions, ':\(.\)')
if (len(s:m) > 2)
let s:case_indent = s:m[1]
Expand Down Expand Up @@ -201,9 +212,9 @@ function s:GetVarIndent(lnum)

" if the previous line doesn't end in a comma, return to regular indent
if (line !~ s:comma_last)
return indent(prev_lnum) - &sw
return indent(prev_lnum) - s:sw()
else
return indent(lvar) + &sw
return indent(lvar) + s:sw()
endif
endif

Expand Down Expand Up @@ -342,7 +353,7 @@ function GetJavascriptIndent()
return indent(prevline)
" otherwise we indent 1 level
else
return indent(lvar) + &sw
return indent(lvar) + s:sw()
endif
endif
endif
Expand All @@ -361,7 +372,7 @@ function GetJavascriptIndent()

" If the line is comma first, dedent 1 level
if (getline(prevline) =~ s:comma_first)
return indent(prevline) - &sw
return indent(prevline) - s:sw()
endif
if (getline(prevline) =~ s:expr_case)
return indent(prevline) + s:case_indent_after
Expand All @@ -371,7 +382,7 @@ function GetJavascriptIndent()
if (getline(prevline) =~ s:ternary_q)
return indent(prevline)
else
return indent(prevline) + &sw
return indent(prevline) + s:sw()
endif
endif

Expand Down Expand Up @@ -413,9 +424,9 @@ function GetJavascriptIndent()
" If the previous line ended with a block opening, add a level of indent.
if s:Match(lnum, s:block_regex)
if (line =~ s:expr_case)
return indent(s:GetMSL(lnum, 0)) + &sw/2
return indent(s:GetMSL(lnum, 0)) + s:sw()/2
else
return indent(s:GetMSL(lnum, 0)) + &sw
return indent(s:GetMSL(lnum, 0)) + s:sw()
endif
endif

Expand All @@ -428,12 +439,12 @@ function GetJavascriptIndent()
let counts = s:LineHasOpeningBrackets(lnum)
if counts[0] == '1' && searchpair('(', '', ')', 'bW', s:skip_expr) > 0
if col('.') + 1 == col('$')
return ind + &sw
return ind + s:sw()
else
return virtcol('.')
endif
elseif counts[1] == '1' || counts[2] == '1'
return ind + &sw
return ind + s:sw()
else
call cursor(v:lnum, vcol)
end
Expand All @@ -443,18 +454,18 @@ function GetJavascriptIndent()
" --------------------------

let ind_con = ind
let ind = s:IndentWithContinuation(lnum, ind_con, &sw)
let ind = s:IndentWithContinuation(lnum, ind_con, s:sw())

" }}}2
"
"
let ols = s:InOneLineScope(lnum)
if ols > 0
let ind = ind + &sw
let ind = ind + s:sw()
else
let ols = s:ExitingOneLineScope(lnum)
while ols > 0 && ind > 0
let ind = ind - &sw
let ind = ind - s:sw()
let ols = s:InOneLineScope(ols - 1)
endwhile
endif
Expand Down