Skip to content

operators & continuation #566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 21, 2016
Merged
Changes from 1 commit
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
Next Next commit
operators & continuation
  • Loading branch information
bounceme authored Jul 21, 2016
commit 5cf7570a1a72e095ba9ca3bf8ba38cc99696ff7b
18 changes: 12 additions & 6 deletions indent/javascript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,16 @@ endfunc

let s:line_term = '\s*\%(\%(:\@<!\/\/.*\)\=\|\%(\/\*.*\*\/\s*\)*\)$'

" Regex that defines continuation lines, not including (, {, or [.
let s:continuation_regex = '\%([*,.?:]\|+\@<!+\|-\@<!-\|\*\@<!\/\|=\|||\|&&\)' . s:line_term
" configurable regexes that define continuation lines, not including (, {, or [.
if !exists('g:js_opfirst')
let g:js_opfirst = '\%([,:?]\|\([-/.+*]\)\%(\1\|\*\|\/\)\@!\|||\|&&\)'
endif
let g:js_opfirst = s:line_pre . g:js_opfirst

if !exists('g:js_continuation')
let g:js_continuation = '\%([*,.?:]\|+\@<!+\|-\@<!-\|\*\@<!\/\|=\|||\|&&\)'
endif
let g:js_continuation .= s:line_term

function s:Onescope(lnum)
return getline(a:lnum) =~ '\%(\<else\|\<do\|=>\)\C' . s:line_term ||
Expand All @@ -70,8 +78,6 @@ function s:Onescope(lnum)
\ (expand("<cword>") =~ 'while\C' ? !s:lookForParens('\<do\>\C', '\<while\>\C','bw',100) : 1)
endfunction

let s:operator_first = s:line_pre . '\%([,:?]\|\([-/.+*]\)\%(\1\|\*\|\/\)\@!\|||\|&&\)'

" Auxiliary Functions {{{2
" ======================

Expand Down Expand Up @@ -194,8 +200,8 @@ function GetJavascriptIndent()
let num = max([num,bnum])
let b:js_cache[1] = num
endif
if (line =~ s:operator_first ||
\ (getline(lnum) =~ s:continuation_regex && getline(lnum) !~ s:expr_case) ||
if (line =~ g:js_opfirst ||
\ (getline(lnum) =~ g:js_continuation && getline(lnum) !~ s:expr_case) ||
\ (s:Onescope(lnum) && line !~ s:line_pre . '{')) &&
\ (num != lnum &&
\ synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsdestructuringblock\|args\|jsbracket\|jsparen\|jsobject')
Expand Down