Skip to content

Commit 9404db5

Browse files
authored
clean: remove cursor call (pangloss#1060)
1 parent 3ed61c9 commit 9404db5

1 file changed

Lines changed: 15 additions & 18 deletions

File tree

indent/javascript.vim

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,14 @@ let s:opfirst = '^' . get(g:,'javascript_opfirst',
215215
let s:continuation = get(g:,'javascript_continuation',
216216
\ '\C\%([<=,.~!?/*^%|&:]\|+\@<!+\|-\@<!-\|=\@<!>\|\<\%(typeof\|new\|delete\|void\|in\|instanceof\|await\)\)') . '$'
217217

218-
function s:Continues(ln,con)
219-
let tok = matchstr(a:con[-15:],s:continuation)
218+
function s:Continues()
219+
let tok = matchstr(strpart(getline('.'),col('.')-15,15),s:continuation)
220220
if tok =~ '[a-z:]'
221-
call cursor(a:ln, len(a:con))
222221
return tok == ':' ? s:ExprCol() : s:PreviousToken() != '.'
223222
elseif tok !~ '[/>]'
224223
return tok isnot ''
225224
endif
226-
return s:SynAt(a:ln, len(a:con)) !~? (tok == '>' ? 'jsflow\|^html' : 'regex')
225+
return s:SynAt(line('.'),col('.')) !~? (tok == '>' ? 'jsflow\|^html' : 'regex')
227226
endfunction
228227

229228
" Check if line 'lnum' has a balanced amount of parentheses.
@@ -269,9 +268,9 @@ endfunction
269268
" returns total offset from braceless contexts. 'num' is the lineNr which
270269
" encloses the entire context, 'cont' if whether a:firstline is a continued
271270
" expression, which could have started in a braceless context
272-
function s:IsContOne(num,cont)
273-
let [l:num, b_l] = [a:num + !a:num, 0]
274-
let pind = a:num ? indent(a:num) + s:sw() : 0
271+
function s:IsContOne(cont)
272+
let [l:num, b_l] = [b:js_cache[1] + !b:js_cache[1], 0]
273+
let pind = b:js_cache[1] ? indent(b:js_cache[1]) + s:sw() : 0
275274
let ind = indent('.') + !a:cont
276275
while line('.') > l:num && ind > pind || line('.') == l:num
277276
if indent('.') < ind && s:OneScope()
@@ -401,26 +400,24 @@ function GetJavascriptIndent()
401400
endif
402401
endif
403402
if idx == -1 && pline[-1:] !~ '[{;]'
403+
call cursor(l:lnum, len(pline))
404404
let sol = matchstr(l:line,s:opfirst)
405405
if sol is '' || sol == '/' && s:SynAt(v:lnum,
406406
\ 1 + len(getline(v:lnum)) - len(l:line)) =~? 'regex'
407-
if s:Continues(l:lnum,pline)
407+
if s:Continues()
408408
let is_op = s:sw()
409409
endif
410-
elseif num && sol =~# '^\%(in\%(stanceof\)\=\|\*\)$'
411-
call cursor(l:lnum, len(pline))
412-
if s:LookingAt() == '}' && s:GetPair('{','}','bW',s:skip_expr) &&
413-
\ s:PreviousToken() == ')' && s:GetPair('(',')','bW',s:skip_expr) &&
414-
\ (s:PreviousToken() == ']' || s:Token() =~ '\k' &&
415-
\ s:{s:PreviousToken() == '*' ? 'Previous' : ''}Token() !=# 'function')
416-
return num_ind + s:sw()
417-
endif
418-
let is_op = s:sw()
410+
elseif num && sol =~# '^\%(in\%(stanceof\)\=\|\*\)$' &&
411+
\ s:LookingAt() == '}' && s:GetPair('{','}','bW',s:skip_expr) &&
412+
\ s:PreviousToken() == ')' && s:GetPair('(',')','bW',s:skip_expr) &&
413+
\ (s:PreviousToken() == ']' || s:LookingAt() =~ '\k' &&
414+
\ s:{s:PreviousToken() == '*' ? 'Previous' : ''}Token() !=# 'function')
415+
return num_ind + s:sw()
419416
else
420417
let is_op = s:sw()
421418
endif
422419
call cursor(l:lnum, len(pline))
423-
let b_l = s:Nat(s:IsContOne(b:js_cache[1],is_op) - (!is_op && l:line =~ '^{')) * s:sw()
420+
let b_l = s:Nat(s:IsContOne(is_op) - (!is_op && l:line =~ '^{')) * s:sw()
424421
endif
425422
elseif idx.s:LookingAt().&cino =~ '^-1(.*(' && (search('\m\S','nbW',num) || s:ParseCino('U'))
426423
let pval = s:ParseCino('(')

0 commit comments

Comments
 (0)