Skip to content

Commit 31232fe

Browse files
authored
collection regex, various (pangloss#1035)
1 parent ee376ba commit 31232fe

1 file changed

Lines changed: 12 additions & 15 deletions

File tree

indent/javascript.vim

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function s:SkipFunc()
120120
let s:check_in = 0
121121
elseif getline('.') =~ '\%<'.col('.').'c\/.\{-}\/\|\%>'.col('.').'c[''"]\|\\$'
122122
if eval(s:skip_expr)
123-
let s:looksyn = line('.')
123+
let s:looksyn = a:firstline
124124
return 1
125125
endif
126126
elseif search('\m`\|\${\|\*\/','nW'.s:z,s:looksyn) && eval(s:skip_expr)
@@ -167,14 +167,14 @@ function s:Token()
167167
endfunction
168168

169169
function s:PreviousToken()
170-
let l:pos = getpos('.')
170+
let l:col = col('.')
171171
if search('\m\k\{1,}\|\S','ebW')
172-
if (strpart(getline('.'),col('.')-2,2) == '*/' || line('.') != l:pos[1] &&
172+
if (strpart(getline('.'),col('.')-2,2) == '*/' || line('.') != a:firstline &&
173173
\ getline('.')[:col('.')-1] =~ '\/\/') && s:SynAt(line('.'),col('.')) =~? s:syng_com
174174
if s:SearchLoop('\S\ze\_s*\/[/*]','bW',"s:SynAt(line('.'),col('.')) =~? s:syng_com")
175175
return s:Token()
176176
endif
177-
call setpos('.',l:pos)
177+
call cursor(a:firstline, l:col)
178178
else
179179
return s:Token()
180180
endif
@@ -183,9 +183,7 @@ function s:PreviousToken()
183183
endfunction
184184

185185
function s:Pure(f,...)
186-
let [l:pos, l:v] = [getpos('.'), call(a:f,a:000)]
187-
call setpos('.',l:pos)
188-
return l:v
186+
return eval('[call(a:f,a:000),cursor(a:firstline,'.col('.').')][0]')
189187
endfunction
190188

191189
function s:SearchLoop(pat,flags,top,...)
@@ -241,9 +239,9 @@ function s:Balanced(lnum)
241239
return
242240
endif
243241
endif
244-
let pos = match(l:line, l:open ?
245-
\ matchstr(['[][]','[()]','[{}]'],l:line[pos]) :
246-
\ '[][(){}]', pos + 1)
242+
let pos = match(l:line, '['.(l:open ?
243+
\ strpart('][(){}', stridx('[({])}', l:line[pos]) % 3 * 2, 2) :
244+
\ '][(){}').']', pos + 1)
247245
endwhile
248246
return !l:open
249247
endfunction
@@ -275,13 +273,13 @@ endfunction
275273
" lineNr which encloses the entire context, 'cont' if whether line 'i' + 1 is
276274
" a continued expression, which could have started in a braceless context
277275
function s:IsContOne(num,cont)
278-
let [l:startline, l:num, b_l] = [line('.'), a:num + !a:num, 0]
276+
let [l:num, b_l] = [a:num + !a:num, 0]
279277
let pind = a:num ? indent(a:num) + s:sw() : 0
280278
let ind = indent('.') + !a:cont
281279
while line('.') > l:num && ind > pind || line('.') == l:num
282280
if indent('.') < ind && s:OneScope()
283281
let b_l += 1
284-
elseif !a:cont || b_l || ind < indent(l:startline)
282+
elseif !a:cont || b_l || ind < indent(a:firstline)
285283
break
286284
else
287285
call cursor(0,1)
@@ -306,7 +304,6 @@ endfunction
306304

307305
" https://github.com/sweet-js/sweet.js/wiki/design#give-lookbehind-to-the-reader
308306
function s:IsBlock()
309-
let l:n = line('.')
310307
let tok = s:PreviousToken()
311308
if match(s:stack,'\cxml\|jsx') != -1 && s:SynAt(line('.'),col('.')-1) =~? 'xml\|jsx'
312309
return tok != '{'
@@ -315,7 +312,7 @@ function s:IsBlock()
315312
return s:Pure('eval',"s:PreviousToken() !~# '^\\%(im\\|ex\\)port$' || s:PreviousToken() == '.'")
316313
endif
317314
return index(split('return const let import export extends yield default delete var await void typeof throw case new of in instanceof')
318-
\ ,tok) < (line('.') != l:n) || s:Pure('s:PreviousToken') == '.'
315+
\ ,tok) < (line('.') != a:firstline) || s:Pure('s:PreviousToken') == '.'
319316
elseif tok == '>'
320317
return getline('.')[col('.')-2] == '=' || s:SynAt(line('.'),col('.')) =~? 'jsflow\|^html'
321318
elseif tok == '*'
@@ -325,7 +322,7 @@ function s:IsBlock()
325322
elseif tok == '/'
326323
return s:SynAt(line('.'),col('.')) =~? 'regex'
327324
elseif tok !~ '[=~!<,.?^%|&([]'
328-
return tok !~ '[-+]' || l:n != line('.') && getline('.')[col('.')-2] == tok
325+
return tok !~ '[-+]' || line('.') != a:firstline && getline('.')[col('.')-2] == tok
329326
endif
330327
endfunction
331328

0 commit comments

Comments
 (0)