Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions indent/javascript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,31 @@ endfunction

" https://github.com/sweet-js/sweet.js/wiki/design#give-lookbehind-to-the-reader
function s:IsBlock()
return getline(line('.'))[col('.')-1] == '{' && !search('\C\<return\s*\%#','nbW') &&
\ (!search('\*\/\_s*\%#','bW') || synIDattr(synID(line('.'),col('.'),0),'name') =~? 'comment' &&
\ searchpair('\/\*','','\*\/','bW')) && (search('\l\_s*\%#','bW') ? expand('<cword>') !~#
\ '\<\%(var\|const\|let\|\%(im\|ex\)port\|yield\|de\%(fault\|lete\)\|void\|t\%(ypeof\|hrow\)\|new\|in\%(stanceof\)\=\)\>'
\ : !search('[-=~!<*+,./?^%|&\[(]\_s*\%#','nbW') && (search('>\_s*\%#','bW') ? search('=\%#','bW') ||
\ synIDattr(synID(line('.'),col('.'),0),'name') =~? 'flownoise' :
\ search(s:expr_case . '\_s*\%#','nbW') || !search('[{:]\_s*\%#','bW') || s:IsBlock()))
if getline(line('.'))[col('.')-1] == '{'
if search('\C\<return\s*\%#','nbW')
return 0
endif
if search('\*\/\_s*\%#','bW') && synIDattr(synID(line('.'),col('.'),0),'name') =~? 'comment'
call searchpair('\/\*','','\*\/','bW')
endif
if search('\S','bW')
let char = getline(line('.'))[col('.')-1]
if char =~# '\l'
return expand('<cword>') !~#
\ '\<\%(var\|const\|let\|\%(im\|ex\)port\|yield\|de\%(fault\|lete\)\|void\|t\%(ypeof\|hrow\)\|new\|in\%(stanceof\)\=\)\>'
elseif char == '>'
return search('=\%#','bW') || synIDattr(synID(line('.'),col('.'),0),'name') =~? 'flownoise'
elseif char == ':'
return strpart(getline(line('.')),0,col('.')) =~# s:expr_case . '$'
elseif char == '{'
return s:IsBlock()
else
return char !~# '[-=~!<*+,./?^%|&\[(]'
endif
else
return 1
endif
endif
endfunction

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