Skip to content

Commit 15905f2

Browse files
authored
refactor,cleaning isblock
1 parent eac1300 commit 15905f2

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

indent/javascript.vim

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -135,23 +135,22 @@ endfunction
135135
" https://github.com/sweet-js/sweet.js/wiki/design#give-lookbehind-to-the-reader
136136
function s:IsBlock(...)
137137
let l:ln = get(a:000,0,line('.'))
138-
if search('\S','bW')
139-
let char = s:token()
140-
let syn = char =~ '[{>/]' || l:ln != line('.') ? synIDattr(synID(line('.'),col('.')-(char == '{'),0),'name') : ''
141-
if syn =~? '\%(xml\|jsx\)'
142-
return char != '{'
143-
elseif syn =~? 'comment'
144-
return search('\/[/*]','bW') && s:IsBlock(l:ln)
145-
elseif char == '>'
146-
return getline('.')[col('.')-2] == '=' || syn =~? '^jsflow'
147-
elseif char == ':'
148-
return cursor(0,match(' ' . strpart(getline('.'),0,col('.')),'.*\zs' . s:expr_case . '$')) + 1 &&
149-
\ (expand('<cword>') !=# 'default' || s:previous_token() !~ '[,{]')
150-
endif
151-
return index(split('return const let import export yield default delete var void typeof throw new in instanceof'
152-
\ . ' - = ~ ! < * + , / ? ^ % | & ( ['), char) < (0 + (line('.') != l:ln))
138+
let char = s:previous_token()
139+
let syn = char =~ '[{>/]' || l:ln != line('.') ? synIDattr(synID(line('.'),col('.')-(char == '{'),0),'name') : ''
140+
if char is ''
141+
return 1
142+
elseif syn =~? '\%(xml\|jsx\)'
143+
return char != '{'
144+
elseif syn =~? 'comment'
145+
return search('\/[/*]','bW') && s:IsBlock(l:ln)
146+
elseif char == '>'
147+
return getline('.')[col('.')-2] == '=' || syn =~? '^jsflow'
148+
elseif char == ':'
149+
return cursor(0,match(' ' . strpart(getline('.'),0,col('.')),'.*\zs' . s:expr_case . '$')) + 1 &&
150+
\ (expand('<cword>') !=# 'default' || s:previous_token() !~ '[,{]')
153151
endif
154-
return 1
152+
return index(split('return const let import export yield default delete var void typeof throw new in instanceof'
153+
\ . ' - = ~ ! < * + , / ? ^ % | & ( ['), char) < (0 + (line('.') != l:ln))
155154
endfunction
156155

157156
" Find line above 'lnum' that isn't empty, in a comment, or in a string.

0 commit comments

Comments
 (0)