From 32137f1f0c228d25b45057bd4e0b7329ab181c0e Mon Sep 17 00:00:00 2001 From: Zheng Chaoping Date: Fri, 29 Jan 2016 23:07:52 +0800 Subject: [PATCH] Use shfitwidth() instead of &sw in indent/javascript.vim --- indent/javascript.vim | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index e1e1fc7e..1aeeb89a 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -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 " ============ @@ -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] @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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