Skip to content

Commit 898a536

Browse files
authored
disambiguate vars
1 parent 6f31d72 commit 898a536

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

indent/javascript.vim

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
" Last Change: August 7, 2016
66

77
" Only load this indent file when no other was loaded.
8-
if exists("b:did_indent")
8+
if exists('b:did_indent')
99
finish
1010
endif
1111
let b:did_indent = 1
@@ -19,7 +19,7 @@ setlocal cinoptions+=j1,J1
1919
let b:undo_indent = 'setlocal indentexpr< indentkeys< cinoptions<'
2020

2121
" Only define the function once.
22-
if exists("*GetJavascriptIndent")
22+
if exists('*GetJavascriptIndent')
2323
finish
2424
endif
2525

@@ -76,7 +76,7 @@ function s:Onescope(lnum,text,add)
7676
\ s:lookForParens('(', ')', 'cbW', 100) > 0 && search((a:add ?
7777
\ '\%(function\*\|[[:lower:][:upper:]_$][[:digit:][:lower:][:upper:]_$]*\)' :
7878
\ '\<\%(for\%(\s\+each\)\=\|if\|let\|w\%(hile\|ith\)\)') . '\_s*\%#\C','bW') &&
79-
\ (a:add || (expand("<cword>") ==# 'while' ? !s:lookForParens('\<do\>\C', '\<while\>\C','bW',100) : 1))
79+
\ (a:add || (expand('<cword>') ==# 'while' ? !s:lookForParens('\<do\>\C', '\<while\>\C','bW',100) : 1))
8080
endfunction
8181

8282
" Auxiliary Functions {{{2
@@ -88,33 +88,33 @@ endfunction
8888

8989
" Find line above 'lnum' that isn't empty, in a comment, or in a string.
9090
function s:PrevCodeLine(lnum)
91-
let lnum = prevnonblank(a:lnum)
92-
while lnum > 0
93-
if synIDattr(synID(lnum,matchend(getline(lnum), '^\s*[^''"]'),0),'name') !~? s:syng_strcom
91+
let l:lnum = prevnonblank(a:lnum)
92+
while l:lnum > 0
93+
if synIDattr(synID(l:lnum,matchend(getline(l:lnum), '^\s*[^''"]'),0),'name') !~? s:syng_strcom
9494
break
9595
endif
96-
let lnum = prevnonblank(lnum - 1)
96+
let l:lnum = prevnonblank(l:lnum - 1)
9797
endwhile
98-
return lnum
98+
return l:lnum
9999
endfunction
100100

101101
" Check if line 'lnum' has a balanced amount of parentheses.
102102
function s:Balanced(lnum)
103103
let open_0 = 0
104104
let open_2 = 0
105105
let open_4 = 0
106-
let line = getline(a:lnum)
107-
let pos = match(line, '[][(){}]', 0)
106+
let l:line = getline(a:lnum)
107+
let pos = match(l:line, '[][(){}]', 0)
108108
while pos != -1
109109
if synIDattr(synID(a:lnum,pos + 1,0),'name') !~? s:syng_strcom
110-
let idx = stridx('(){}[]', line[pos])
110+
let idx = stridx('(){}[]', l:line[pos])
111111
if idx % 2 == 0
112112
let open_{idx} = open_{idx} + 1
113113
else
114114
let open_{idx - 1} = open_{idx - 1} - 1
115115
endif
116116
endif
117-
let pos = match(line, '[][(){}]', pos + 1)
117+
let pos = match(l:line, '[][(){}]', pos + 1)
118118
endwhile
119119
return (!open_4 + !open_2 + !open_0) - 2
120120
endfunction
@@ -125,23 +125,23 @@ function GetJavascriptIndent()
125125
let b:js_cache = [0,0,0]
126126
endif
127127
" Get the current line.
128-
let line = getline(v:lnum)
128+
let l:line = getline(v:lnum)
129129
let syns = synIDattr(synID(v:lnum, 1, 0), 'name')
130130

131131
" start with strings,comments,etc.{{{2
132-
if (line !~ '^[''"`]' && syns =~? 'string\|template') ||
133-
\ (line !~ '^\s*[/*]' && syns =~? s:syng_comment)
132+
if (l:line !~ '^[''"`]' && syns =~? 'string\|template') ||
133+
\ (l:line !~ '^\s*[/*]' && syns =~? s:syng_comment)
134134
return -1
135135
endif
136-
if line !~ '^\%(\/\*\|\s*\/\/\)' && syns =~? s:syng_comment
136+
if l:line !~ '^\%(\/\*\|\s*\/\/\)' && syns =~? s:syng_comment
137137
return cindent(v:lnum)
138138
endif
139-
let lnum = s:PrevCodeLine(v:lnum - 1)
140-
if lnum == 0
139+
let l:lnum = s:PrevCodeLine(v:lnum - 1)
140+
if l:lnum == 0
141141
return 0
142142
endif
143143

144-
if (line =~# s:expr_case)
144+
if (l:line =~# s:expr_case)
145145
let cpo_switch = &cpo
146146
set cpo+=%
147147
let ind = cindent(v:lnum)
@@ -153,10 +153,10 @@ function GetJavascriptIndent()
153153
" the containing paren, bracket, curly. Memoize, last lineNr either has the
154154
" same scope or starts a new one, unless if it closed a scope.
155155
call cursor(v:lnum,1)
156-
if b:js_cache[0] >= lnum && b:js_cache[0] <= v:lnum && b:js_cache[0] &&
157-
\ (b:js_cache[0] > lnum || s:Balanced(lnum) > 0)
156+
if b:js_cache[0] >= l:lnum && b:js_cache[0] <= v:lnum && b:js_cache[0] &&
157+
\ (b:js_cache[0] > l:lnum || s:Balanced(l:lnum) > 0)
158158
let num = b:js_cache[1]
159-
elseif syns != '' && line[0] =~ '\s'
159+
elseif syns != '' && l:line[0] =~ '\s'
160160
let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] :
161161
\ syns =~? 'jsbracket'? ['\[','\]'] : ['[({[]','[])}]']
162162
let num = s:lookForParens(pattern[0],pattern[1],'bW',2000)
@@ -165,21 +165,21 @@ function GetJavascriptIndent()
165165
endif
166166
let b:js_cache = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')]
167167

168-
if line =~ s:line_pre . '[])}]'
168+
if l:line =~ s:line_pre . '[])}]'
169169
return indent(num)
170170
endif
171171

172-
let pline = s:StripLine(getline(lnum))
172+
let pline = s:StripLine(getline(l:lnum))
173173
let inb = num == 0 ? 1 : (s:Onescope(num, s:StripLine(strpart(getline(num),0,b:js_cache[2] - 1)),1) ||
174-
\ (line !~ s:line_pre . ',' && pline !~ ',' . s:line_term)) && num < lnum
174+
\ (l:line !~ s:line_pre . ',' && pline !~ ',' . s:line_term)) && num < l:lnum
175175
let switch_offset = (!inb || num == 0) || expand("<cword>") !=# 'switch' ? 0 : &cino !~ ':' || !has('float') ? s:sw() :
176176
\ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (&cino =~# '.*:[^,]*s' ? s:sw() : 1))
177177

178178
" most significant, find the indent amount
179-
if (inb && (line =~# g:javascript_opfirst ||
180-
\ (pline =~# g:javascript_continuation && pline !~# s:expr_case && (pline !~ ':' . s:line_term || line !~#
179+
if (inb && (l:line =~# g:javascript_opfirst ||
180+
\ (pline =~# g:javascript_continuation && pline !~# s:expr_case && (pline !~ ':' . s:line_term || l:line !~#
181181
\ s:line_pre . '\%(d\%(o\|ebugger\)\|else\|f\%(or\|inally\)\|if\|let\|switch\|t\%(hrow\|ry\)\|w\%(hile\|ith\)\)\>')))) ||
182-
\ (num < lnum && s:Onescope(lnum,pline,0) && line !~ s:line_pre . '{')
182+
\ (num < l:lnum && s:Onescope(l:lnum,pline,0) && l:line !~ s:line_pre . '{')
183183
return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset
184184
elseif num > 0
185185
return indent(num) + s:sw() + switch_offset

0 commit comments

Comments
 (0)