Skip to content

Commit 81d8502

Browse files
authored
refactor adjustment and simplify
since the adjustment wasn't working well in blocks with blanks or comments, and there is never a continuation in !blocks this is far more simple
1 parent 0ab4b1d commit 81d8502

1 file changed

Lines changed: 4 additions & 12 deletions

File tree

indent/javascript.vim

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ endfunction
125125

126126
function GetJavascriptIndent()
127127
if !exists('b:js_cache')
128-
let b:js_cache = [0,0,0,0]
128+
let b:js_cache = [0,0,0]
129129
endif
130130
" Get the current line.
131131
let l:line = getline(v:lnum)
@@ -153,14 +153,11 @@ function GetJavascriptIndent()
153153
endif
154154
"}}}
155155

156-
let known = 0
157-
let pcounts = [0]
158156
" the containing paren, bracket, curly. Memoize, last lineNr either has the
159157
" same scope or starts a new one, unless if it closed a scope.
160158
call cursor(v:lnum,1)
161159
if b:js_cache[0] < v:lnum && b:js_cache[0] >= l:lnum &&
162-
\ (map(pcounts,'s:Balanced(l:lnum)')[0] > 0 || b:js_cache[0] > l:lnum)
163-
let known = pcounts[0] > 0
160+
\ (s:Balanced(l:lnum) > 0 || b:js_cache[0] > l:lnum)
164161
let num = b:js_cache[1]
165162
elseif syns != '' && l:line[0] =~ '\s'
166163
let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] :
@@ -170,11 +167,7 @@ function GetJavascriptIndent()
170167
let num = s:GetPair('[({[]','[])}]','bW',2000)
171168
endif
172169

173-
if known && b:js_cache[3]
174-
let known = indent(l:lnum) - b:js_cache[3]
175-
endif
176-
177-
let b:js_cache[:2] = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')]
170+
let b:js_cache = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')]
178171

179172
if l:line =~ s:line_pre . '[])}]'
180173
return indent(num)
@@ -192,8 +185,7 @@ function GetJavascriptIndent()
192185
\ l:line !~ s:line_pre . '{'
193186
return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset
194187
elseif num > 0
195-
let b:js_cache[3] = indent(num) + s:sw() + switch_offset
196-
return b:js_cache[3] + (isOp ? known : 0)
188+
return isOp && num < l:lnum ? indent(l:lnum) : indent(num) + s:sw() + switch_offset
197189
endif
198190

199191
endfunction

0 commit comments

Comments
 (0)