Skip to content

Commit 0059286

Browse files
authored
operators & continuation (#566)
* operators & continuation
1 parent c68ecbe commit 0059286

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

indent/javascript.vim

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,16 @@ endfunc
5858

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

61-
" Regex that defines continuation lines, not including (, {, or [.
62-
let s:continuation_regex = '\%([*,.?:]\|+\@<!+\|-\@<!-\|\*\@<!\/\|=\|||\|&&\)' . s:line_term
61+
" configurable regexes that define continuation lines, not including (, {, or [.
62+
if !exists('g:javascript_opfirst')
63+
let g:javascript_opfirst = '\%([,:?]\|\([-/.+*]\)\%(\1\|\*\|\/\)\@!\|||\|&&\)'
64+
endif
65+
let g:javascript_opfirst = s:line_pre . g:javascript_opfirst
66+
67+
if !exists('g:javascript_continuation')
68+
let g:javascript_continuation = '\%([*,.?:]\|+\@<!+\|-\@<!-\|\*\@<!\/\|=\|||\|&&\)'
69+
endif
70+
let g:javascript_continuation .= s:line_term
6371

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

73-
let s:operator_first = s:line_pre . '\%([,:?]\|\([-/.+*]\)\%(\1\|\*\|\/\)\@!\|||\|&&\)'
74-
7581
" Auxiliary Functions {{{2
7682
" ======================
7783

@@ -194,8 +200,8 @@ function GetJavascriptIndent()
194200
let num = max([num,bnum])
195201
let b:js_cache[1] = num
196202
endif
197-
if (line =~ s:operator_first ||
198-
\ (getline(lnum) =~ s:continuation_regex && getline(lnum) !~ s:expr_case) ||
203+
if (line =~ g:javascript_opfirst ||
204+
\ (getline(lnum) =~ g:javascript_continuation && getline(lnum) !~ s:expr_case) ||
199205
\ (s:Onescope(lnum) && line !~ s:line_pre . '{')) &&
200206
\ (num != lnum &&
201207
\ synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsdestructuringblock\|args\|jsbracket\|jsparen\|jsobject')

0 commit comments

Comments
 (0)