From 924a6456ccff5783d9f8811bf901882282bd0c6e Mon Sep 17 00:00:00 2001 From: bounceme Date: Fri, 29 Jul 2016 00:00:51 -0700 Subject: [PATCH 01/52] misc fixes (#578) make sure to calculate switch_offset even when using 'c-style' and fix block comments at the very top of a file --- indent/javascript.vim | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 6844dc2f..dde72676 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -71,11 +71,11 @@ let g:javascript_continuation .= s:line_term function s:Onescope(lnum,text,add) return a:text =~ '\%(\' . (a:add ? '\|\ -1 && + \ ((a:add && a:text =~ s:line_pre . s:line_term && search('\%' . s:PrevCodeLine(a:lnum - 1) . 'l.)' . s:line_term)) || + \ cursor(a:lnum, match(a:text, ')' . s:line_term)) > -1) && \ s:lookForParens('(', ')', 'cbW', 100) > 0 && \ search((a:add ? '\%(function\*\|[A-Za-z_$][0-9A-Za-z_$]*\)\C' : - \ '\<\%(for\%(\s+each\)\=\|if\|let\|switch\|while\|with\)\C') . '\_s*\%#','bW')) && + \ '\<\%(for\%(\s+each\)\=\|if\|let\|while\|with\)\C') . '\_s*\%#','bW') && \ (a:add || (expand("") == 'while' ? !s:lookForParens('\\C', '\\C','bW',100) : 1)) endfunction @@ -132,10 +132,6 @@ function GetJavascriptIndent() " previous nonblank line number let prevline = prevnonblank(v:lnum - 1) " previous line of code - let lnum = s:PrevCodeLine(v:lnum - 1) - if lnum == 0 - return 0 - endif " start with strings,comments,etc.{{{2 if (line !~ '^[''"`]' && s:IsSyn(v:lnum,1,'string\|template')) || @@ -145,6 +141,10 @@ function GetJavascriptIndent() if line !~ '^\%(\/\*\|\s*\/\/\)' && s:IsSyn(v:lnum,1,s:syng_comment) return cindent(v:lnum) endif + let lnum = s:PrevCodeLine(v:lnum - 1) + if lnum == 0 + return 0 + endif if (line =~ s:expr_case) let cpo_switch = &cpo From ee3183e7f2773a82c17cd1f819cc2da9374b2206 Mon Sep 17 00:00:00 2001 From: bounceme Date: Fri, 29 Jul 2016 21:12:49 -0700 Subject: [PATCH 02/52] fix ftplugin var and clean indent (#580) * fix ftplugin var and clean indent --- after/ftplugin/javascript.vim | 6 +++++- indent/javascript.vim | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/after/ftplugin/javascript.vim b/after/ftplugin/javascript.vim index e2d471dd..c6c42d60 100644 --- a/after/ftplugin/javascript.vim +++ b/after/ftplugin/javascript.vim @@ -5,4 +5,8 @@ setlocal iskeyword+=$ suffixesadd+=.js -let b:undo_ftplugin .= ' | setlocal iskeyword< suffixesadd<' +if exists('b:undo_ftplugin') + let b:undo_ftplugin .= ' | setlocal iskeyword< suffixesadd<' +else + let b:undo_ftplugin = 'setlocal iskeyword< suffixesadd<' +endif diff --git a/indent/javascript.vim b/indent/javascript.vim index dde72676..9121c81e 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -3,6 +3,7 @@ " Maintainer: vim-javascript community " URL: https://github.com/pangloss/vim-javascript " Acknowledgement: Based off of vim-ruby maintained by Nikolai Weibull http://vim-ruby.rubyforge.org +" Last Change: July 29, 2016 " Only load this indent file when no other was loaded. if exists("b:did_indent") @@ -56,7 +57,7 @@ func s:lookForParens(start,end,flags,time) endtry endfunc -let s:line_term = '\s*\%(\%(:\@ Date: Sat, 30 Jul 2016 01:04:45 -0700 Subject: [PATCH 03/52] comment on performance, angle brackets --- indent/javascript.vim | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 9121c81e..618105f4 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -61,12 +61,12 @@ let s:line_term = '\s*\%(\/\*.*\*\/\s*\)*\%(:\@\@!\||\|&\|in\%(stanceof\)\=\>\)\C' + let g:javascript_opfirst = '\%([<>,:?^%]\|\([-/.+]\)\%(\1\|\*\|\/\)\@!\|\*\/\@!\|=>\@!\||\|&\|in\%(stanceof\)\=\>\)\C' endif let g:javascript_opfirst = s:line_pre . g:javascript_opfirst if !exists('g:javascript_continuation') - let g:javascript_continuation = '\%([*,.?:^%]\|+\@\|\*\@= lnum && b:js_cache[0] <= v:lnum && b:js_cache[0] && \ (b:js_cache[0] > lnum || map(pcounts,'s:LineHasOpeningBrackets(lnum)')[0][0] !~ '2') From e8bb2bad78296f06e7945960c72b45ac9022f145 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sat, 30 Jul 2016 21:32:45 -0700 Subject: [PATCH 04/52] remove line comment appended to code (#581) * remove line comment appended to code --- indent/javascript.vim | 52 +++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 618105f4..6d063669 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -1,9 +1,9 @@ " Vim indent file " Language: Javascript -" Maintainer: vim-javascript community -" URL: https://github.com/pangloss/vim-javascript +" Maintainer: vim-javascript community +" URL: https://github.com/pangloss/vim-javascript " Acknowledgement: Based off of vim-ruby maintained by Nikolai Weibull http://vim-ruby.rubyforge.org -" Last Change: July 29, 2016 +" Last Change: July 30, 2016 " Only load this indent file when no other was loaded. if exists("b:did_indent") @@ -29,13 +29,13 @@ set cpo&vim " Get shiftwidth value if exists('*shiftwidth') - func s:sw() + function s:sw() return shiftwidth() - endfunc + endfunction else - func s:sw() + function s:sw() return &sw - endfunc + endfunction endif let s:line_pre = '^\s*\%(\/\*.*\*\/\s*\)*' @@ -49,15 +49,15 @@ let s:syng_comment = '\%(comment\|doc\)\c' " Expression used to check whether we should skip a match with searchpair(). let s:skip_expr = "line('.') < (prevnonblank(v:lnum) - 2000) ? dummy : s:IsSyn(line('.'),col('.'),'')" -func s:lookForParens(start,end,flags,time) +function s:lookForParens(start,end,flags,time) try return searchpair(a:start,'',a:end,a:flags,s:skip_expr,0,a:time) catch /E118/ return searchpair(a:start,'',a:end,a:flags,0,0) endtry -endfunc +endfunction -let s:line_term = '\s*\%(\/\*.*\*\/\s*\)*\%(:\@' . (a:add ? '\|\ -1 && + \ cursor(line('.'),match(s:Stripline(getline(line('.'))), ')' . s:line_term))>-1) || \ cursor(a:lnum, match(a:text, ')' . s:line_term)) > -1) && \ s:lookForParens('(', ')', 'cbW', 100) > 0 && \ search((a:add ? '\%(function\*\|[A-Za-z_$][0-9A-Za-z_$]*\)\C' : @@ -82,6 +83,11 @@ endfunction " Auxiliary Functions {{{2 +" strip line of comment +function s:StripLine(c) + return substitute(a:c, '\%(:\@ 0 ? lnum : -1 endfunction " Check if line 'lnum' has more opening brackets than closing ones. @@ -127,7 +133,7 @@ endfunction function GetJavascriptIndent() if !exists('b:js_cache') let b:js_cache = [0,0,0] - end + endif " Get the current line. let line = getline(v:lnum) " previous nonblank line number @@ -142,7 +148,9 @@ function GetJavascriptIndent() return cindent(v:lnum) endif let lnum = s:PrevCodeLine(v:lnum - 1) - if lnum == 0 + let pline = s:StripLine(getline(lnum)) + let line = s:StripLine(line) + if lnum <= 0 return 0 endif @@ -163,7 +171,7 @@ function GetJavascriptIndent() let num = pcounts[0][0] =~ '1' ? lnum : b:js_cache[1] if pcounts[0][0] =~'1' call cursor(lnum,pcounts[0][1]) - end + endif else call cursor(v:lnum,1) let syns = synIDattr(synID(v:lnum, 1, 1), 'name') @@ -173,24 +181,24 @@ function GetJavascriptIndent() let num = s:lookForParens(pattern[0],pattern[1],'bW',2000) else let num = s:lookForParens('(\|{\|\[',')\|}\|\]','bW',2000) - end - end + endif + endif let b:js_cache = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] " most significant part if line =~ s:line_pre . '[])}]' return indent(num) - end - let inb = num == 0 ? 1 : s:Onescope(num, strpart(getline(num),0,b:js_cache[2] - 1),1) + endif + let inb = num == 0 ? 1 : s:Onescope(num, s:StripLine(strpart(getline(num),0,b:js_cache[2] - 1)),1) let switch_offset = (!inb || num == 0) || expand("") != 'switch' ? 0 : &cino !~ ':' || !has('float') ? s:sw() : \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (match(&cino,'.*:\zs[^,]*s') ? s:sw() : 1)) if ((line =~ g:javascript_opfirst || - \ (getline(lnum) =~ g:javascript_continuation && getline(lnum) !~ s:expr_case)) && - \ inb) || (s:Onescope(lnum,getline(lnum),0) && line !~ s:line_pre . '{') + \ (pline =~ g:javascript_continuation && pline !~ s:expr_case)) && + \ inb) || (s:Onescope(lnum,pline,0) && line !~ s:line_pre . '{') return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset elseif num > 0 return indent(num) + s:sw() + switch_offset - end + endif endfunction From bc6422b5a452d707e0c8c737196a83e5ac1a5163 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sat, 30 Jul 2016 22:02:11 -0700 Subject: [PATCH 05/52] had a problem with some of the changes --- indent/javascript.vim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 6d063669..e5b9c8a6 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -72,8 +72,7 @@ let g:javascript_continuation .= s:line_term function s:Onescope(lnum,text,add) return a:text =~ '\%(\' . (a:add ? '\|\ -1 && - \ cursor(line('.'),match(s:Stripline(getline(line('.'))), ')' . s:line_term))>-1) || + \ ((a:add && a:text =~ s:line_pre . s:line_term && search('\%' . s:PrevCodeLine(a:lnum - 1) . 'l.)' . s:line_term)) || \ cursor(a:lnum, match(a:text, ')' . s:line_term)) > -1) && \ s:lookForParens('(', ')', 'cbW', 100) > 0 && \ search((a:add ? '\%(function\*\|[A-Za-z_$][0-9A-Za-z_$]*\)\C' : From 60eaba7be5f5ac1ec69d7ce04e8e5b5c3accce8a Mon Sep 17 00:00:00 2001 From: bounceme Date: Sat, 30 Jul 2016 22:21:06 -0700 Subject: [PATCH 06/52] Update javascript.vim --- indent/javascript.vim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index e5b9c8a6..67f99951 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -2,7 +2,6 @@ " Language: Javascript " Maintainer: vim-javascript community " URL: https://github.com/pangloss/vim-javascript -" Acknowledgement: Based off of vim-ruby maintained by Nikolai Weibull http://vim-ruby.rubyforge.org " Last Change: July 30, 2016 " Only load this indent file when no other was loaded. @@ -147,11 +146,10 @@ function GetJavascriptIndent() return cindent(v:lnum) endif let lnum = s:PrevCodeLine(v:lnum - 1) - let pline = s:StripLine(getline(lnum)) - let line = s:StripLine(line) if lnum <= 0 return 0 endif + let line = s:StripLine(line) if (line =~ s:expr_case) let cpo_switch = &cpo @@ -191,6 +189,7 @@ function GetJavascriptIndent() let inb = num == 0 ? 1 : s:Onescope(num, s:StripLine(strpart(getline(num),0,b:js_cache[2] - 1)),1) let switch_offset = (!inb || num == 0) || expand("") != 'switch' ? 0 : &cino !~ ':' || !has('float') ? s:sw() : \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (match(&cino,'.*:\zs[^,]*s') ? s:sw() : 1)) + let pline = s:StripLine(getline(lnum)) if ((line =~ g:javascript_opfirst || \ (pline =~ g:javascript_continuation && pline !~ s:expr_case)) && \ inb) || (s:Onescope(lnum,pline,0) && line !~ s:line_pre . '{') From 6706a2442b757ecc631b220b4a2cbcd7e1d9f8a1 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sat, 30 Jul 2016 22:35:09 -0700 Subject: [PATCH 07/52] few remaining touches --- indent/javascript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 67f99951..3f273ea1 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -100,7 +100,7 @@ function s:PrevCodeLine(lnum) endif let lnum = prevnonblank(lnum - 1) endwhile - return lnum > 0 ? lnum : -1 + return lnum endfunction " Check if line 'lnum' has more opening brackets than closing ones. @@ -146,7 +146,7 @@ function GetJavascriptIndent() return cindent(v:lnum) endif let lnum = s:PrevCodeLine(v:lnum - 1) - if lnum <= 0 + if lnum == 0 return 0 endif let line = s:StripLine(line) From a328e8175f4763a4221bbb86047f5a4d615caffd Mon Sep 17 00:00:00 2001 From: bounceme Date: Sun, 31 Jul 2016 10:07:25 -0700 Subject: [PATCH 08/52] add label support (#582) * add label support --- indent/javascript.vim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 3f273ea1..f9d64664 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -2,7 +2,7 @@ " Language: Javascript " Maintainer: vim-javascript community " URL: https://github.com/pangloss/vim-javascript -" Last Change: July 30, 2016 +" Last Change: July 31, 2016 " Only load this indent file when no other was loaded. if exists("b:did_indent") @@ -191,7 +191,9 @@ function GetJavascriptIndent() \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (match(&cino,'.*:\zs[^,]*s') ? s:sw() : 1)) let pline = s:StripLine(getline(lnum)) if ((line =~ g:javascript_opfirst || - \ (pline =~ g:javascript_continuation && pline !~ s:expr_case)) && + \ (pline =~ g:javascript_continuation && pline !~ s:expr_case && + \ (pline !~ ':' . s:line_term || line !~# s:line_pre . + \ '\%(debugger\|do\|else\|finally\|for\|if\|let\|switch\|throw\|try\|while\|with\)'))) && \ inb) || (s:Onescope(lnum,pline,0) && line !~ s:line_pre . '{') return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset elseif num > 0 From 5ba6eab7648c705535b494b79bbcc9850b9e37df Mon Sep 17 00:00:00 2001 From: bounceme Date: Sun, 31 Jul 2016 11:01:36 -0700 Subject: [PATCH 09/52] case-sensitivity (#583) * case-sensitivity --- indent/javascript.vim | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index f9d64664..64ca942f 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -38,12 +38,12 @@ else endif let s:line_pre = '^\s*\%(\/\*.*\*\/\s*\)*' -let s:expr_case = s:line_pre . '\%(\%(case\>.*\)\|default\)\s*:\C' +let s:expr_case = s:line_pre . '\%(\%(case\>.*\)\|default\)\s*:' " Regex of syntax group names that are or delimit string or are comments. -let s:syng_strcom = '\%(string\|regex\|special\|doc\|comment\|template\)\c' +let s:syng_strcom = '\%(string\|regex\|special\|doc\|comment\|template\)' " Regex of syntax group names that are strings or documentation. -let s:syng_comment = '\%(comment\|doc\)\c' +let s:syng_comment = '\%(comment\|doc\)' " Expression used to check whether we should skip a match with searchpair(). let s:skip_expr = "line('.') < (prevnonblank(v:lnum) - 2000) ? dummy : s:IsSyn(line('.'),col('.'),'')" @@ -60,23 +60,23 @@ let s:line_term = '\s*\%(\/\*.*\*\/\s*\)*$' " configurable regexes that define continuation lines, not including (, {, or [. if !exists('g:javascript_opfirst') - let g:javascript_opfirst = '\%([<>,:?^%]\|\([-/.+]\)\%(\1\|\*\|\/\)\@!\|\*\/\@!\|=>\@!\||\|&\|in\%(stanceof\)\=\>\)\C' + let g:javascript_opfirst = '\%([<>,:?^%]\|\([-/.+]\)\%(\1\|\*\|\/\)\@!\|\*\/\@!\|=>\@!\||\|&\|in\%(stanceof\)\=\>\)' endif let g:javascript_opfirst = s:line_pre . g:javascript_opfirst if !exists('g:javascript_continuation') - let g:javascript_continuation = '\%([<*,.?:^%]\|+\@\|\*\@\|\*\@' . (a:add ? '\|\' . (a:add ? '\|\ -1) && \ s:lookForParens('(', ')', 'cbW', 100) > 0 && - \ search((a:add ? '\%(function\*\|[A-Za-z_$][0-9A-Za-z_$]*\)\C' : - \ '\<\%(for\%(\s+each\)\=\|if\|let\|while\|with\)\C') . '\_s*\%#','bW') && - \ (a:add || (expand("") == 'while' ? !s:lookForParens('\\C', '\\C','bW',100) : 1)) + \ search((a:add ? '\%(function\*\|[A-Za-z_$][0-9A-Za-z_$]*\)' : + \ '\<\%(for\%(\s+each\)\=\|if\|let\|while\|with\)') . '\_s*\%#\C','bW') && + \ (a:add || (expand("") ==# 'while' ? !s:lookForParens('\\C', '\\C','bW',100) : 1)) endfunction " Auxiliary Functions {{{2 @@ -151,7 +151,7 @@ function GetJavascriptIndent() endif let line = s:StripLine(line) - if (line =~ s:expr_case) + if (line =~# s:expr_case) let cpo_switch = &cpo set cpo+=% let ind = cindent(v:lnum) @@ -187,13 +187,13 @@ function GetJavascriptIndent() return indent(num) endif let inb = num == 0 ? 1 : s:Onescope(num, s:StripLine(strpart(getline(num),0,b:js_cache[2] - 1)),1) - let switch_offset = (!inb || num == 0) || expand("") != 'switch' ? 0 : &cino !~ ':' || !has('float') ? s:sw() : + let switch_offset = (!inb || num == 0) || expand("") !=# 'switch' ? 0 : &cino !~ ':' || !has('float') ? s:sw() : \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (match(&cino,'.*:\zs[^,]*s') ? s:sw() : 1)) let pline = s:StripLine(getline(lnum)) - if ((line =~ g:javascript_opfirst || - \ (pline =~ g:javascript_continuation && pline !~ s:expr_case && + if ((line =~# g:javascript_opfirst || + \ (pline =~# g:javascript_continuation && pline !~# s:expr_case && \ (pline !~ ':' . s:line_term || line !~# s:line_pre . - \ '\%(debugger\|do\|else\|finally\|for\|if\|let\|switch\|throw\|try\|while\|with\)'))) && + \ '\%(debugger\|do\|else\|finally\|for\|if\|let\|switch\|throw\|try\|while\|with\)\>'))) && \ inb) || (s:Onescope(lnum,pline,0) && line !~ s:line_pre . '{') return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset elseif num > 0 From 86413728b55e1ffb7a31521339c5c851114fa582 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sun, 31 Jul 2016 12:26:39 -0700 Subject: [PATCH 10/52] Don't join strings in multiple lines easier to read in one line --- indent/javascript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 64ca942f..56ad87e1 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -192,8 +192,8 @@ function GetJavascriptIndent() let pline = s:StripLine(getline(lnum)) if ((line =~# g:javascript_opfirst || \ (pline =~# g:javascript_continuation && pline !~# s:expr_case && - \ (pline !~ ':' . s:line_term || line !~# s:line_pre . - \ '\%(debugger\|do\|else\|finally\|for\|if\|let\|switch\|throw\|try\|while\|with\)\>'))) && + \ (pline !~ ':' . s:line_term || line !~# + \ s:line_pre . '\%(debugger\|do\|else\|finally\|for\|if\|let\|switch\|throw\|try\|while\|with\)\>'))) && \ inb) || (s:Onescope(lnum,pline,0) && line !~ s:line_pre . '{') return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset elseif num > 0 From c003d8b9745c897de819d05ac39bd0674db14df2 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sun, 31 Jul 2016 12:53:10 -0700 Subject: [PATCH 11/52] join lines --- indent/javascript.vim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 56ad87e1..90d9dc4e 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -73,9 +73,8 @@ function s:Onescope(lnum,text,add) return a:text =~# '\%(\' . (a:add ? '\|\ -1) && - \ s:lookForParens('(', ')', 'cbW', 100) > 0 && - \ search((a:add ? '\%(function\*\|[A-Za-z_$][0-9A-Za-z_$]*\)' : - \ '\<\%(for\%(\s+each\)\=\|if\|let\|while\|with\)') . '\_s*\%#\C','bW') && + \ s:lookForParens('(', ')', 'cbW', 100) > 0 && search((a:add ? + \ '\%(function\*\|[A-Za-z_$][0-9A-Za-z_$]*\)' : '\<\%(for\%(\s+each\)\=\|if\|let\|while\|with\)') . '\_s*\%#\C','bW') && \ (a:add || (expand("") ==# 'while' ? !s:lookForParens('\\C', '\\C','bW',100) : 1)) endfunction From 58095d8647aaaaa50478c3a19b52c7ee5bb32f01 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sun, 31 Jul 2016 22:00:25 -0700 Subject: [PATCH 12/52] regex char classes --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 90d9dc4e..035e30e9 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -74,7 +74,7 @@ function s:Onescope(lnum,text,add) \ ((a:add && a:text =~ s:line_pre . s:line_term && search('\%' . s:PrevCodeLine(a:lnum - 1) . 'l.)' . s:line_term)) || \ cursor(a:lnum, match(a:text, ')' . s:line_term)) > -1) && \ s:lookForParens('(', ')', 'cbW', 100) > 0 && search((a:add ? - \ '\%(function\*\|[A-Za-z_$][0-9A-Za-z_$]*\)' : '\<\%(for\%(\s+each\)\=\|if\|let\|while\|with\)') . '\_s*\%#\C','bW') && + \ '\%(function\*\|\%(\h\|\$\)\%(\w\|\$\)*\)' : '\<\%(for\%(\s+each\)\=\|if\|let\|while\|with\)') . '\_s*\%#\C','bW') && \ (a:add || (expand("") ==# 'while' ? !s:lookForParens('\\C', '\\C','bW',100) : 1)) endfunction From bd4c5270e72a198b544f8a8a56faec6d17e4bb77 Mon Sep 17 00:00:00 2001 From: bounceme Date: Mon, 1 Aug 2016 12:08:00 -0700 Subject: [PATCH 13/52] limit regex lookbehind --- indent/javascript.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 035e30e9..1be39302 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -40,7 +40,7 @@ endif let s:line_pre = '^\s*\%(\/\*.*\*\/\s*\)*' let s:expr_case = s:line_pre . '\%(\%(case\>.*\)\|default\)\s*:' " Regex of syntax group names that are or delimit string or are comments. -let s:syng_strcom = '\%(string\|regex\|special\|doc\|comment\|template\)' +let s:syng_strcom = '\%(s\%(tring\|pecial\)\|regex\|doc\|comment\|template\)' " Regex of syntax group names that are strings or documentation. let s:syng_comment = '\%(comment\|doc\)' @@ -74,7 +74,7 @@ function s:Onescope(lnum,text,add) \ ((a:add && a:text =~ s:line_pre . s:line_term && search('\%' . s:PrevCodeLine(a:lnum - 1) . 'l.)' . s:line_term)) || \ cursor(a:lnum, match(a:text, ')' . s:line_term)) > -1) && \ s:lookForParens('(', ')', 'cbW', 100) > 0 && search((a:add ? - \ '\%(function\*\|\%(\h\|\$\)\%(\w\|\$\)*\)' : '\<\%(for\%(\s+each\)\=\|if\|let\|while\|with\)') . '\_s*\%#\C','bW') && + \ '\%(function\*\|\%(\h\|\$\)\%(\w\|\$\)*\)' : '\<\%(for\%(\s+each\)\=\|if\|let\|w\%(hile\|ith\)\)') . '\_s*\%#\C','bW') && \ (a:add || (expand("") ==# 'while' ? !s:lookForParens('\\C', '\\C','bW',100) : 1)) endfunction @@ -192,7 +192,7 @@ function GetJavascriptIndent() if ((line =~# g:javascript_opfirst || \ (pline =~# g:javascript_continuation && pline !~# s:expr_case && \ (pline !~ ':' . s:line_term || line !~# - \ s:line_pre . '\%(debugger\|do\|else\|finally\|for\|if\|let\|switch\|throw\|try\|while\|with\)\>'))) && + \ s:line_pre . '\%(d\%(ebugger\|o\)\|else\|f\%(inally\|or\)\|if\|let\|switch\|t\%(hrow\|ry\)\|w\%(hile\|ith\)\)\>'))) && \ inb) || (s:Onescope(lnum,pline,0) && line !~ s:line_pre . '{') return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset elseif num > 0 From 4278caa2757940d581117a325e118004a21a517f Mon Sep 17 00:00:00 2001 From: bounceme Date: Mon, 1 Aug 2016 19:46:33 -0700 Subject: [PATCH 14/52] unicode identifiers javascript allows for much more than just [A-Za-z] for identifiers. this is also faster on more recent versions of vim. --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 1be39302..a8276802 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -74,7 +74,7 @@ function s:Onescope(lnum,text,add) \ ((a:add && a:text =~ s:line_pre . s:line_term && search('\%' . s:PrevCodeLine(a:lnum - 1) . 'l.)' . s:line_term)) || \ cursor(a:lnum, match(a:text, ')' . s:line_term)) > -1) && \ s:lookForParens('(', ')', 'cbW', 100) > 0 && search((a:add ? - \ '\%(function\*\|\%(\h\|\$\)\%(\w\|\$\)*\)' : '\<\%(for\%(\s+each\)\=\|if\|let\|w\%(hile\|ith\)\)') . '\_s*\%#\C','bW') && + \ '\%(function\*\|[[:lower:][:upper:]_$][[:digit:][:lower:][:upper:]_$]*\)' : '\<\%(for\%(\s+each\)\=\|if\|let\|w\%(hile\|ith\)\)') . '\_s*\%#\C','bW') && \ (a:add || (expand("") ==# 'while' ? !s:lookForParens('\\C', '\\C','bW',100) : 1)) endfunction From 6de8f62f669952941e6ea57da854d579486ca2db Mon Sep 17 00:00:00 2001 From: bounceme Date: Tue, 2 Aug 2016 09:41:48 -0700 Subject: [PATCH 15/52] more regex --- indent/javascript.vim | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index a8276802..a23a4c4f 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -37,10 +37,10 @@ else endfunction endif -let s:line_pre = '^\s*\%(\/\*.*\*\/\s*\)*' +let s:line_pre = '^\s*\%(\/\*.\{-}\*\/\s*\)*' let s:expr_case = s:line_pre . '\%(\%(case\>.*\)\|default\)\s*:' " Regex of syntax group names that are or delimit string or are comments. -let s:syng_strcom = '\%(s\%(tring\|pecial\)\|regex\|doc\|comment\|template\)' +let s:syng_strcom = '\%(s\%(tring\|pecial\)\|comment\|regex\|doc\|template\)' " Regex of syntax group names that are strings or documentation. let s:syng_comment = '\%(comment\|doc\)' @@ -56,7 +56,7 @@ function s:lookForParens(start,end,flags,time) endtry endfunction -let s:line_term = '\s*\%(\/\*.*\*\/\s*\)*$' +let s:line_term = '\s*\%(\/\*.\{-}\*\/\s*\)*$' " configurable regexes that define continuation lines, not including (, {, or [. if !exists('g:javascript_opfirst') @@ -74,7 +74,8 @@ function s:Onescope(lnum,text,add) \ ((a:add && a:text =~ s:line_pre . s:line_term && search('\%' . s:PrevCodeLine(a:lnum - 1) . 'l.)' . s:line_term)) || \ cursor(a:lnum, match(a:text, ')' . s:line_term)) > -1) && \ s:lookForParens('(', ')', 'cbW', 100) > 0 && search((a:add ? - \ '\%(function\*\|[[:lower:][:upper:]_$][[:digit:][:lower:][:upper:]_$]*\)' : '\<\%(for\%(\s+each\)\=\|if\|let\|w\%(hile\|ith\)\)') . '\_s*\%#\C','bW') && + \ '\%(function\*\|[[:lower:][:upper:]_$][[:digit:][:lower:][:upper:]_$]*\)' : + \ '\<\%(for\%(\s+each\)\=\|if\|let\|w\%(hile\|ith\)\)') . '\_s*\%#\C','bW') && \ (a:add || (expand("") ==# 'while' ? !s:lookForParens('\\C', '\\C','bW',100) : 1)) endfunction @@ -192,7 +193,7 @@ function GetJavascriptIndent() if ((line =~# g:javascript_opfirst || \ (pline =~# g:javascript_continuation && pline !~# s:expr_case && \ (pline !~ ':' . s:line_term || line !~# - \ s:line_pre . '\%(d\%(ebugger\|o\)\|else\|f\%(inally\|or\)\|if\|let\|switch\|t\%(hrow\|ry\)\|w\%(hile\|ith\)\)\>'))) && + \ s:line_pre . '\%(d\%(o\|ebugger\)\|else\|f\%(or\|inally\)\|if\|let\|switch\|t\%(hrow\|ry\)\|w\%(hile\|ith\)\)\>'))) && \ inb) || (s:Onescope(lnum,pline,0) && line !~ s:line_pre . '{') return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset elseif num > 0 From 27a37b4a77783628cf988fbbffa8e8e0be29288a Mon Sep 17 00:00:00 2001 From: bounceme Date: Tue, 2 Aug 2016 19:32:37 -0700 Subject: [PATCH 16/52] for 585 (#586) changes operator behavior inside of invoking parens, object literals, and arrays. --- indent/javascript.vim | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index a23a4c4f..c47d7223 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -186,15 +186,17 @@ function GetJavascriptIndent() if line =~ s:line_pre . '[])}]' return indent(num) endif - let inb = num == 0 ? 1 : s:Onescope(num, s:StripLine(strpart(getline(num),0,b:js_cache[2] - 1)),1) + + let pline = s:StripLine(getline(lnum)) + let inb = num == 0 ? 1 : s:Onescope(num, s:StripLine(strpart(getline(num),0,b:js_cache[2] - 1)),1) || + \ (num < lnum && (line !~ s:line_pre . ',' && pline !~ ',' . s:line_term)) let switch_offset = (!inb || num == 0) || expand("") !=# 'switch' ? 0 : &cino !~ ':' || !has('float') ? s:sw() : \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (match(&cino,'.*:\zs[^,]*s') ? s:sw() : 1)) - let pline = s:StripLine(getline(lnum)) - if ((line =~# g:javascript_opfirst || - \ (pline =~# g:javascript_continuation && pline !~# s:expr_case && - \ (pline !~ ':' . s:line_term || line !~# - \ s:line_pre . '\%(d\%(o\|ebugger\)\|else\|f\%(or\|inally\)\|if\|let\|switch\|t\%(hrow\|ry\)\|w\%(hile\|ith\)\)\>'))) && - \ inb) || (s:Onescope(lnum,pline,0) && line !~ s:line_pre . '{') + + if (inb && (line =~# g:javascript_opfirst || + \ (pline =~# g:javascript_continuation && pline !~# s:expr_case && (pline !~ ':' . s:line_term || line !~# + \ s:line_pre . '\%(d\%(o\|ebugger\)\|else\|f\%(or\|inally\)\|if\|let\|switch\|t\%(hrow\|ry\)\|w\%(hile\|ith\)\)\>')))) || + \ (num < lnum && s:Onescope(lnum,pline,0) && line !~ s:line_pre . '{') return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset elseif num > 0 return indent(num) + s:sw() + switch_offset From b65cd1447236c3ee5fdec81f7bd601ab5fb08dcb Mon Sep 17 00:00:00 2001 From: bounceme Date: Tue, 2 Aug 2016 20:00:54 -0700 Subject: [PATCH 17/52] update comments --- indent/javascript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index c47d7223..d598b1db 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -2,7 +2,7 @@ " Language: Javascript " Maintainer: vim-javascript community " URL: https://github.com/pangloss/vim-javascript -" Last Change: July 31, 2016 +" Last Change: August 2, 2016 " Only load this indent file when no other was loaded. if exists("b:did_indent") @@ -182,7 +182,6 @@ function GetJavascriptIndent() endif let b:js_cache = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] - " most significant part if line =~ s:line_pre . '[])}]' return indent(num) endif @@ -193,6 +192,7 @@ function GetJavascriptIndent() let switch_offset = (!inb || num == 0) || expand("") !=# 'switch' ? 0 : &cino !~ ':' || !has('float') ? s:sw() : \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (match(&cino,'.*:\zs[^,]*s') ? s:sw() : 1)) + " most significant, find the indent amount if (inb && (line =~# g:javascript_opfirst || \ (pline =~# g:javascript_continuation && pline !~# s:expr_case && (pline !~ ':' . s:line_term || line !~# \ s:line_pre . '\%(d\%(o\|ebugger\)\|else\|f\%(or\|inally\)\|if\|let\|switch\|t\%(hrow\|ry\)\|w\%(hile\|ith\)\)\>')))) || From 97e5fcab6693fa006d6552ece9b72c60e7f04373 Mon Sep 17 00:00:00 2001 From: bounceme Date: Tue, 2 Aug 2016 21:16:25 -0700 Subject: [PATCH 18/52] last commit extended to blocks --- indent/javascript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index d598b1db..419e5ce5 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -187,8 +187,8 @@ function GetJavascriptIndent() endif let pline = s:StripLine(getline(lnum)) - let inb = num == 0 ? 1 : s:Onescope(num, s:StripLine(strpart(getline(num),0,b:js_cache[2] - 1)),1) || - \ (num < lnum && (line !~ s:line_pre . ',' && pline !~ ',' . s:line_term)) + let inb = num == 0 ? 1 : (s:Onescope(num, s:StripLine(strpart(getline(num),0,b:js_cache[2] - 1)),1) || + \ (line !~ s:line_pre . ',' && pline !~ ',' . s:line_term)) && num < lnum let switch_offset = (!inb || num == 0) || expand("") !=# 'switch' ? 0 : &cino !~ ':' || !has('float') ? s:sw() : \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (match(&cino,'.*:\zs[^,]*s') ? s:sw() : 1)) From 23b4639fc6038e15c1a01c1d8e3126d801f3c1fb Mon Sep 17 00:00:00 2001 From: bounceme Date: Tue, 2 Aug 2016 21:35:05 -0700 Subject: [PATCH 19/52] accuracy and speed increase for line_term regex --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 419e5ce5..ecec5257 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -56,7 +56,7 @@ function s:lookForParens(start,end,flags,time) endtry endfunction -let s:line_term = '\s*\%(\/\*.\{-}\*\/\s*\)*$' +let s:line_term = '\%(\s*\%(\/\*.\{-}\*\/\s*\)\=\)\@>$' " configurable regexes that define continuation lines, not including (, {, or [. if !exists('g:javascript_opfirst') From 73c85a3f7e0749edad7c6c10e946b2d4ac73e1b9 Mon Sep 17 00:00:00 2001 From: bounceme Date: Wed, 3 Aug 2016 01:22:47 -0700 Subject: [PATCH 20/52] awful off-by-one bug so it appears that my testing didn't reveal this because I use (and apparently most people use): ``` function a() { var i = 1, c = 2 } ``` instead of: ``` function a(){ var i = 1, c = 2 } ``` --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index ecec5257..4e2568a5 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -116,7 +116,7 @@ function s:LineHasOpeningBrackets(lnum) let idx = stridx('(){}[]', line[pos]) if idx % 2 == 0 let open_{idx} = open_{idx} + 1 - let last = pos + let last = pos + 1 else let open_{idx - 1} = open_{idx - 1} - 1 endif From b8762e8af610cf98d42e4b8ff610060953a5a3a9 Mon Sep 17 00:00:00 2001 From: bounceme Date: Wed, 3 Aug 2016 09:15:02 -0700 Subject: [PATCH 21/52] remove buggy linehasopeningbracket trick --- indent/javascript.vim | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 4e2568a5..aea64c43 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -110,21 +110,19 @@ function s:LineHasOpeningBrackets(lnum) let open_4 = 0 let line = getline(a:lnum) let pos = match(line, '[][(){}]', 0) - let last = 0 while pos != -1 if !s:IsSyn(a:lnum, pos + 1, '') let idx = stridx('(){}[]', line[pos]) if idx % 2 == 0 let open_{idx} = open_{idx} + 1 - let last = pos + 1 else let open_{idx - 1} = open_{idx - 1} - 1 endif endif let pos = match(line, '[][(){}]', pos + 1) endwhile - return [(open_0 > 0 ? 1 : (open_0 == 0 ? 0 : 2)) . (open_2 > 0 ? 1 : (open_2 == 0 ? 0 : 2)) . - \ (open_4 > 0 ? 1 : (open_4 == 0 ? 0 : 2)), last] + return (open_0 > 0 ? 1 : (open_0 == 0 ? 0 : 2)) . (open_2 > 0 ? 1 : (open_2 == 0 ? 0 : 2)) . + \ (open_4 > 0 ? 1 : (open_4 == 0 ? 0 : 2)) endfunction " }}} @@ -162,15 +160,15 @@ function GetJavascriptIndent() " the containing paren, bracket, curly. Memoize, last lineNr either has the " same scope or starts a new one, unless if it closed a scope. + call cursor(v:lnum,1) let pcounts = [0] if b:js_cache[0] >= lnum && b:js_cache[0] <= v:lnum && b:js_cache[0] && - \ (b:js_cache[0] > lnum || map(pcounts,'s:LineHasOpeningBrackets(lnum)')[0][0] !~ '2') - let num = pcounts[0][0] =~ '1' ? lnum : b:js_cache[1] - if pcounts[0][0] =~'1' - call cursor(lnum,pcounts[0][1]) + \ (b:js_cache[0] > lnum || map(pcounts,'s:LineHasOpeningBrackets(lnum)')[0] !~ '2') + let num = pcounts[0] =~ '1' ? lnum : b:js_cache[1] + if pcounts[0] =~'1' + call s:lookForParens('(\|{\|\[',')\|}\|\]','bW',2000) endif else - call cursor(v:lnum,1) let syns = synIDattr(synID(v:lnum, 1, 1), 'name') if line[0] =~ '\s' && syns != '' let pattern = syns =~? 'funcblock' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : syns =~? 'jsbracket'? ['\[','\]'] : From 6a3fac49aa8d6a9e6d2a62b8f7f9eddf4aee74be Mon Sep 17 00:00:00 2001 From: bounceme Date: Wed, 3 Aug 2016 12:07:45 -0700 Subject: [PATCH 22/52] cleaning --- indent/javascript.vim | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index aea64c43..cf99f00a 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -164,10 +164,7 @@ function GetJavascriptIndent() let pcounts = [0] if b:js_cache[0] >= lnum && b:js_cache[0] <= v:lnum && b:js_cache[0] && \ (b:js_cache[0] > lnum || map(pcounts,'s:LineHasOpeningBrackets(lnum)')[0] !~ '2') - let num = pcounts[0] =~ '1' ? lnum : b:js_cache[1] - if pcounts[0] =~'1' - call s:lookForParens('(\|{\|\[',')\|}\|\]','bW',2000) - endif + let num = pcounts[0] =~ '1' ? s:lookForParens('(\|{\|\[',')\|}\|\]','bW',2000) : b:js_cache[1] else let syns = synIDattr(synID(v:lnum, 1, 1), 'name') if line[0] =~ '\s' && syns != '' From 336d4351cea47c820e4c67af4e7afa6e822cc0fb Mon Sep 17 00:00:00 2001 From: bounceme Date: Thu, 4 Aug 2016 19:48:39 -0700 Subject: [PATCH 23/52] more cleaning --- indent/javascript.vim | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index cf99f00a..11bd91e2 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -83,7 +83,7 @@ endfunction " strip line of comment function s:StripLine(c) - return substitute(a:c, '\%(:\@= lnum && b:js_cache[0] <= v:lnum && b:js_cache[0] && \ (b:js_cache[0] > lnum || map(pcounts,'s:LineHasOpeningBrackets(lnum)')[0] !~ '2') - let num = pcounts[0] =~ '1' ? s:lookForParens('(\|{\|\[',')\|}\|\]','bW',2000) : b:js_cache[1] + let num = pcounts[0] =~ '1' ? s:lookForParens('[({[]','[])}]','bW',2000) : b:js_cache[1] else let syns = synIDattr(synID(v:lnum, 1, 1), 'name') if line[0] =~ '\s' && syns != '' let pattern = syns =~? 'funcblock' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : syns =~? 'jsbracket'? ['\[','\]'] : - \ ['(\|{\|\[',')\|}\|\]'] + \ ['[({[]','[])}]'] let num = s:lookForParens(pattern[0],pattern[1],'bW',2000) else - let num = s:lookForParens('(\|{\|\[',')\|}\|\]','bW',2000) + let num = s:lookForParens('[({[]','[])}]','bW',2000) endif endif let b:js_cache = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] From fc43554f2a5d16762451c385f21b3ab754ffc567 Mon Sep 17 00:00:00 2001 From: bounceme Date: Thu, 4 Aug 2016 21:05:27 -0700 Subject: [PATCH 24/52] case-sensitivity --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 11bd91e2..9fa3dbbf 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -83,7 +83,7 @@ endfunction " strip line of comment function s:StripLine(c) - return a:c !~ s:expr_case ? substitute(a:c, '\%(:\@ Date: Thu, 4 Aug 2016 22:20:36 -0700 Subject: [PATCH 25/52] simplify regex --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 9fa3dbbf..f591a0f1 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -71,7 +71,7 @@ let g:javascript_continuation .= s:line_term function s:Onescope(lnum,text,add) return a:text =~# '\%(\' . (a:add ? '\|\ -1) && \ s:lookForParens('(', ')', 'cbW', 100) > 0 && search((a:add ? \ '\%(function\*\|[[:lower:][:upper:]_$][[:digit:][:lower:][:upper:]_$]*\)' : From 2a85b3c34ca6032e1949a50ffe15a2a491e783d9 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sat, 6 Aug 2016 11:35:07 -0700 Subject: [PATCH 26/52] ind updates (#593) --- indent/javascript.vim | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index f591a0f1..e30e272a 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -2,7 +2,7 @@ " Language: Javascript " Maintainer: vim-javascript community " URL: https://github.com/pangloss/vim-javascript -" Last Change: August 2, 2016 +" Last Change: August 6, 2016 " Only load this indent file when no other was loaded. if exists("b:did_indent") @@ -88,7 +88,7 @@ endfunction " Check if the character at lnum:col is inside a string, comment, or is ascii. function s:IsSyn(lnum, col, reg) - return synIDattr(synID(a:lnum, a:col, 1), 'name') =~? (a:reg != '' ? a:reg : s:syng_strcom) + return synIDattr(synID(a:lnum, a:col, 0), 'name') =~? (a:reg != '' ? a:reg : s:syng_strcom) endfunction " Find line above 'lnum' that isn't empty, in a comment, or in a string. @@ -104,7 +104,7 @@ function s:PrevCodeLine(lnum) endfunction " Check if line 'lnum' has more opening brackets than closing ones. -function s:LineHasOpeningBrackets(lnum) +function s:Balanced(lnum) let open_0 = 0 let open_2 = 0 let open_4 = 0 @@ -121,8 +121,7 @@ function s:LineHasOpeningBrackets(lnum) endif let pos = match(line, '[][(){}]', pos + 1) endwhile - return (open_0 > 0 ? 1 : (open_0 == 0 ? 0 : 2)) . (open_2 > 0 ? 1 : (open_2 == 0 ? 0 : 2)) . - \ (open_4 > 0 ? 1 : (open_4 == 0 ? 0 : 2)) + return (!open_4 + !open_2 + !open_0) - 2 endfunction " }}} @@ -160,19 +159,16 @@ function GetJavascriptIndent() " the containing paren, bracket, curly. Memoize, last lineNr either has the " same scope or starts a new one, unless if it closed a scope. call cursor(v:lnum,1) - let pcounts = [0] if b:js_cache[0] >= lnum && b:js_cache[0] <= v:lnum && b:js_cache[0] && - \ (b:js_cache[0] > lnum || map(pcounts,'s:LineHasOpeningBrackets(lnum)')[0] !~ '2') - let num = pcounts[0] =~ '1' ? s:lookForParens('[({[]','[])}]','bW',2000) : b:js_cache[1] - else + \ (b:js_cache[0] > lnum || s:Balanced(lnum) > 0) + let num = b:js_cache[1] + elseif line[0] =~ '\s' let syns = synIDattr(synID(v:lnum, 1, 1), 'name') - if line[0] =~ '\s' && syns != '' - let pattern = syns =~? 'funcblock' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : syns =~? 'jsbracket'? ['\[','\]'] : - \ ['[({[]','[])}]'] - let num = s:lookForParens(pattern[0],pattern[1],'bW',2000) - else - let num = s:lookForParens('[({[]','[])}]','bW',2000) - endif + let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : + \ syns =~? 'jsbracket'? ['\[','\]'] : ['[({[]','[])}]'] + let num = s:lookForParens(pattern[0],pattern[1],'bW',2000) + else + let num = s:lookForParens('[({[]','[])}]','bW',2000) endif let b:js_cache = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] From 4a126ee6aa2ac113f6315e6d97e03035cee049cf Mon Sep 17 00:00:00 2001 From: bounceme Date: Sat, 6 Aug 2016 15:48:39 -0700 Subject: [PATCH 27/52] negatives are truthy in vimscript --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index e30e272a..ec4b07b4 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -180,7 +180,7 @@ function GetJavascriptIndent() let inb = num == 0 ? 1 : (s:Onescope(num, s:StripLine(strpart(getline(num),0,b:js_cache[2] - 1)),1) || \ (line !~ s:line_pre . ',' && pline !~ ',' . s:line_term)) && num < lnum let switch_offset = (!inb || num == 0) || expand("") !=# 'switch' ? 0 : &cino !~ ':' || !has('float') ? s:sw() : - \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (match(&cino,'.*:\zs[^,]*s') ? s:sw() : 1)) + \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (&cino =~ '.*:[^,]*s' ? s:sw() : 1)) " most significant, find the indent amount if (inb && (line =~# g:javascript_opfirst || From 29519c62a56e54934b7ae4887cc2ae2ecedb2331 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sat, 6 Aug 2016 17:06:12 -0700 Subject: [PATCH 28/52] case sensitive keep forgetting this --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index ec4b07b4..00a4206a 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -180,7 +180,7 @@ function GetJavascriptIndent() let inb = num == 0 ? 1 : (s:Onescope(num, s:StripLine(strpart(getline(num),0,b:js_cache[2] - 1)),1) || \ (line !~ s:line_pre . ',' && pline !~ ',' . s:line_term)) && num < lnum let switch_offset = (!inb || num == 0) || expand("") !=# 'switch' ? 0 : &cino !~ ':' || !has('float') ? s:sw() : - \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (&cino =~ '.*:[^,]*s' ? s:sw() : 1)) + \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (&cino =~# '.*:[^,]*s' ? s:sw() : 1)) " most significant, find the indent amount if (inb && (line =~# g:javascript_opfirst || From 0a7432f3e1afaf02becba648fdc62ea80bf489c8 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sat, 6 Aug 2016 19:39:07 -0700 Subject: [PATCH 29/52] remove transparent syntax check --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 00a4206a..bca66262 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -163,7 +163,7 @@ function GetJavascriptIndent() \ (b:js_cache[0] > lnum || s:Balanced(lnum) > 0) let num = b:js_cache[1] elseif line[0] =~ '\s' - let syns = synIDattr(synID(v:lnum, 1, 1), 'name') + let syns = synIDattr(synID(v:lnum, 1, 0), 'name') let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : \ syns =~? 'jsbracket'? ['\[','\]'] : ['[({[]','[])}]'] let num = s:lookForParens(pattern[0],pattern[1],'bW',2000) From a7e60bbe490215c3983c871bfd16de146d140fa1 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sun, 7 Aug 2016 08:18:53 -0700 Subject: [PATCH 30/52] remove repeated syn checking --- indent/javascript.vim | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index bca66262..74ffa97d 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -132,14 +132,14 @@ function GetJavascriptIndent() " Get the current line. let line = getline(v:lnum) " previous nonblank line number - let prevline = prevnonblank(v:lnum - 1) + let syns = synIDattr(synID(v:lnum, 1, 0), 'name') " start with strings,comments,etc.{{{2 - if (line !~ '^[''"`]' && s:IsSyn(v:lnum,1,'string\|template')) || - \ (line !~ '^\s*[/*]' && s:IsSyn(v:lnum,1,s:syng_comment)) + if (line !~ '^[''"`]' && syns =~? 'string\|template') || + \ (line !~ '^\s*[/*]' && syns =~? s:syng_comment) return -1 endif - if line !~ '^\%(\/\*\|\s*\/\/\)' && s:IsSyn(v:lnum,1,s:syng_comment) + if line !~ '^\%(\/\*\|\s*\/\/\)' && syns =~? s:syng_comment return cindent(v:lnum) endif let lnum = s:PrevCodeLine(v:lnum - 1) @@ -162,8 +162,7 @@ function GetJavascriptIndent() if b:js_cache[0] >= lnum && b:js_cache[0] <= v:lnum && b:js_cache[0] && \ (b:js_cache[0] > lnum || s:Balanced(lnum) > 0) let num = b:js_cache[1] - elseif line[0] =~ '\s' - let syns = synIDattr(synID(v:lnum, 1, 0), 'name') + elseif syns != '' && line[0] =~ '\s' let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : \ syns =~? 'jsbracket'? ['\[','\]'] : ['[({[]','[])}]'] let num = s:lookForParens(pattern[0],pattern[1],'bW',2000) From b59dfbc8717f47be84b1a3633bb3a6af4cc70225 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sun, 7 Aug 2016 08:32:00 -0700 Subject: [PATCH 31/52] Update javascript.vim --- indent/javascript.vim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 74ffa97d..4cf644fd 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -2,7 +2,7 @@ " Language: Javascript " Maintainer: vim-javascript community " URL: https://github.com/pangloss/vim-javascript -" Last Change: August 6, 2016 +" Last Change: August 7, 2016 " Only load this indent file when no other was loaded. if exists("b:did_indent") @@ -103,7 +103,7 @@ function s:PrevCodeLine(lnum) return lnum endfunction -" Check if line 'lnum' has more opening brackets than closing ones. +" Check if line 'lnum' has a balanced amount of parentheses. function s:Balanced(lnum) let open_0 = 0 let open_2 = 0 @@ -131,7 +131,6 @@ function GetJavascriptIndent() endif " Get the current line. let line = getline(v:lnum) - " previous nonblank line number let syns = synIDattr(synID(v:lnum, 1, 0), 'name') " start with strings,comments,etc.{{{2 From 9703a61af908ec223fe7fd64ad0d3766aa2693d9 Mon Sep 17 00:00:00 2001 From: bounceme Date: Tue, 9 Aug 2016 12:04:14 -0700 Subject: [PATCH 32/52] cleaning, minor performance improvements --- indent/javascript.vim | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 4cf644fd..32857609 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -46,14 +46,14 @@ let s:syng_strcom = '\%(s\%(tring\|pecial\)\|comment\|regex\|doc\|template\)' let s:syng_comment = '\%(comment\|doc\)' " Expression used to check whether we should skip a match with searchpair(). -let s:skip_expr = "line('.') < (prevnonblank(v:lnum) - 2000) ? dummy : s:IsSyn(line('.'),col('.'),'')" +let s:skip_expr = "line('.') < (prevnonblank(v:lnum) - 2000) ? dummy : synIDattr(synID(line('.'),col('.'),0),'name') =~? '".s:syng_strcom."'" function s:lookForParens(start,end,flags,time) - try + if has('reltime') return searchpair(a:start,'',a:end,a:flags,s:skip_expr,0,a:time) - catch /E118/ + else return searchpair(a:start,'',a:end,a:flags,0,0) - endtry + endif endfunction let s:line_term = '\%(\s*\%(\/\*.\{-}\*\/\s*\)\=\)\@>$' @@ -86,16 +86,11 @@ function s:StripLine(c) return a:c !~# s:expr_case ? substitute(a:c, '\%(:\@ 0 - if !s:IsSyn(lnum, matchend(getline(lnum), '^\s*[^''"]'),'') + if synIDattr(synID(lnum,matchend(getline(lnum), '^\s*[^''"]'),0),'name') !~? s:syng_strcom break endif let lnum = prevnonblank(lnum - 1) @@ -111,7 +106,7 @@ function s:Balanced(lnum) let line = getline(a:lnum) let pos = match(line, '[][(){}]', 0) while pos != -1 - if !s:IsSyn(a:lnum, pos + 1, '') + if synIDattr(synID(a:lnum,pos + 1,0),'name') !~? s:syng_strcom let idx = stridx('(){}[]', line[pos]) if idx % 2 == 0 let open_{idx} = open_{idx} + 1 From 6f31d721380443c808ce04403363a70d9f6f07ac Mon Sep 17 00:00:00 2001 From: bounceme Date: Fri, 12 Aug 2016 01:09:54 -0700 Subject: [PATCH 33/52] fix regex --- indent/javascript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 32857609..222028bd 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -38,7 +38,7 @@ else endif let s:line_pre = '^\s*\%(\/\*.\{-}\*\/\s*\)*' -let s:expr_case = s:line_pre . '\%(\%(case\>.*\)\|default\)\s*:' +let s:expr_case = s:line_pre . '\%(\%(case\>.\+\)\|default\)\s*:' " Regex of syntax group names that are or delimit string or are comments. let s:syng_strcom = '\%(s\%(tring\|pecial\)\|comment\|regex\|doc\|template\)' @@ -75,7 +75,7 @@ function s:Onescope(lnum,text,add) \ cursor(a:lnum, match(a:text, ')' . s:line_term)) > -1) && \ s:lookForParens('(', ')', 'cbW', 100) > 0 && search((a:add ? \ '\%(function\*\|[[:lower:][:upper:]_$][[:digit:][:lower:][:upper:]_$]*\)' : - \ '\<\%(for\%(\s+each\)\=\|if\|let\|w\%(hile\|ith\)\)') . '\_s*\%#\C','bW') && + \ '\<\%(for\%(\s\+each\)\=\|if\|let\|w\%(hile\|ith\)\)') . '\_s*\%#\C','bW') && \ (a:add || (expand("") ==# 'while' ? !s:lookForParens('\\C', '\\C','bW',100) : 1)) endfunction From 898a536e024b840e68f2efc09679e79ead823453 Mon Sep 17 00:00:00 2001 From: bounceme Date: Fri, 12 Aug 2016 01:39:24 -0700 Subject: [PATCH 34/52] disambiguate vars --- indent/javascript.vim | 56 +++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 222028bd..f40cf605 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -5,7 +5,7 @@ " Last Change: August 7, 2016 " Only load this indent file when no other was loaded. -if exists("b:did_indent") +if exists('b:did_indent') finish endif let b:did_indent = 1 @@ -19,7 +19,7 @@ setlocal cinoptions+=j1,J1 let b:undo_indent = 'setlocal indentexpr< indentkeys< cinoptions<' " Only define the function once. -if exists("*GetJavascriptIndent") +if exists('*GetJavascriptIndent') finish endif @@ -76,7 +76,7 @@ function s:Onescope(lnum,text,add) \ s:lookForParens('(', ')', 'cbW', 100) > 0 && search((a:add ? \ '\%(function\*\|[[:lower:][:upper:]_$][[:digit:][:lower:][:upper:]_$]*\)' : \ '\<\%(for\%(\s\+each\)\=\|if\|let\|w\%(hile\|ith\)\)') . '\_s*\%#\C','bW') && - \ (a:add || (expand("") ==# 'while' ? !s:lookForParens('\\C', '\\C','bW',100) : 1)) + \ (a:add || (expand('') ==# 'while' ? !s:lookForParens('\\C', '\\C','bW',100) : 1)) endfunction " Auxiliary Functions {{{2 @@ -88,14 +88,14 @@ endfunction " Find line above 'lnum' that isn't empty, in a comment, or in a string. function s:PrevCodeLine(lnum) - let lnum = prevnonblank(a:lnum) - while lnum > 0 - if synIDattr(synID(lnum,matchend(getline(lnum), '^\s*[^''"]'),0),'name') !~? s:syng_strcom + let l:lnum = prevnonblank(a:lnum) + while l:lnum > 0 + if synIDattr(synID(l:lnum,matchend(getline(l:lnum), '^\s*[^''"]'),0),'name') !~? s:syng_strcom break endif - let lnum = prevnonblank(lnum - 1) + let l:lnum = prevnonblank(l:lnum - 1) endwhile - return lnum + return l:lnum endfunction " Check if line 'lnum' has a balanced amount of parentheses. @@ -103,18 +103,18 @@ function s:Balanced(lnum) let open_0 = 0 let open_2 = 0 let open_4 = 0 - let line = getline(a:lnum) - let pos = match(line, '[][(){}]', 0) + let l:line = getline(a:lnum) + let pos = match(l:line, '[][(){}]', 0) while pos != -1 if synIDattr(synID(a:lnum,pos + 1,0),'name') !~? s:syng_strcom - let idx = stridx('(){}[]', line[pos]) + let idx = stridx('(){}[]', l:line[pos]) if idx % 2 == 0 let open_{idx} = open_{idx} + 1 else let open_{idx - 1} = open_{idx - 1} - 1 endif endif - let pos = match(line, '[][(){}]', pos + 1) + let pos = match(l:line, '[][(){}]', pos + 1) endwhile return (!open_4 + !open_2 + !open_0) - 2 endfunction @@ -125,23 +125,23 @@ function GetJavascriptIndent() let b:js_cache = [0,0,0] endif " Get the current line. - let line = getline(v:lnum) + let l:line = getline(v:lnum) let syns = synIDattr(synID(v:lnum, 1, 0), 'name') " start with strings,comments,etc.{{{2 - if (line !~ '^[''"`]' && syns =~? 'string\|template') || - \ (line !~ '^\s*[/*]' && syns =~? s:syng_comment) + if (l:line !~ '^[''"`]' && syns =~? 'string\|template') || + \ (l:line !~ '^\s*[/*]' && syns =~? s:syng_comment) return -1 endif - if line !~ '^\%(\/\*\|\s*\/\/\)' && syns =~? s:syng_comment + if l:line !~ '^\%(\/\*\|\s*\/\/\)' && syns =~? s:syng_comment return cindent(v:lnum) endif - let lnum = s:PrevCodeLine(v:lnum - 1) - if lnum == 0 + let l:lnum = s:PrevCodeLine(v:lnum - 1) + if l:lnum == 0 return 0 endif - if (line =~# s:expr_case) + if (l:line =~# s:expr_case) let cpo_switch = &cpo set cpo+=% let ind = cindent(v:lnum) @@ -153,10 +153,10 @@ function GetJavascriptIndent() " the containing paren, bracket, curly. Memoize, last lineNr either has the " same scope or starts a new one, unless if it closed a scope. call cursor(v:lnum,1) - if b:js_cache[0] >= lnum && b:js_cache[0] <= v:lnum && b:js_cache[0] && - \ (b:js_cache[0] > lnum || s:Balanced(lnum) > 0) + if b:js_cache[0] >= l:lnum && b:js_cache[0] <= v:lnum && b:js_cache[0] && + \ (b:js_cache[0] > l:lnum || s:Balanced(l:lnum) > 0) let num = b:js_cache[1] - elseif syns != '' && line[0] =~ '\s' + elseif syns != '' && l:line[0] =~ '\s' let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : \ syns =~? 'jsbracket'? ['\[','\]'] : ['[({[]','[])}]'] let num = s:lookForParens(pattern[0],pattern[1],'bW',2000) @@ -165,21 +165,21 @@ function GetJavascriptIndent() endif let b:js_cache = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] - if line =~ s:line_pre . '[])}]' + if l:line =~ s:line_pre . '[])}]' return indent(num) endif - let pline = s:StripLine(getline(lnum)) + let pline = s:StripLine(getline(l:lnum)) let inb = num == 0 ? 1 : (s:Onescope(num, s:StripLine(strpart(getline(num),0,b:js_cache[2] - 1)),1) || - \ (line !~ s:line_pre . ',' && pline !~ ',' . s:line_term)) && num < lnum + \ (l:line !~ s:line_pre . ',' && pline !~ ',' . s:line_term)) && num < l:lnum let switch_offset = (!inb || num == 0) || expand("") !=# 'switch' ? 0 : &cino !~ ':' || !has('float') ? s:sw() : \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (&cino =~# '.*:[^,]*s' ? s:sw() : 1)) " most significant, find the indent amount - if (inb && (line =~# g:javascript_opfirst || - \ (pline =~# g:javascript_continuation && pline !~# s:expr_case && (pline !~ ':' . s:line_term || line !~# + if (inb && (l:line =~# g:javascript_opfirst || + \ (pline =~# g:javascript_continuation && pline !~# s:expr_case && (pline !~ ':' . s:line_term || l:line !~# \ s:line_pre . '\%(d\%(o\|ebugger\)\|else\|f\%(or\|inally\)\|if\|let\|switch\|t\%(hrow\|ry\)\|w\%(hile\|ith\)\)\>')))) || - \ (num < lnum && s:Onescope(lnum,pline,0) && line !~ s:line_pre . '{') + \ (num < l:lnum && s:Onescope(l:lnum,pline,0) && l:line !~ s:line_pre . '{') return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset elseif num > 0 return indent(num) + s:sw() + switch_offset From debb9bf72249cc3290fa9e8f54709f609b1cf0e9 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sat, 13 Aug 2016 19:47:18 -0700 Subject: [PATCH 35/52] Readme Updates (#599) * Readme Updates * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index bcefe6c6..662a2006 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,11 @@ variables: let g:javascript_conceal_super = "Ω" let g:javascript_conceal_arrow_function = "⇒" +## Indentation Specific + +* `:h cino-:` +* End-of-line continuations : `g:javascript_continuation` ( slightly complicated, look at the source code ) +* Start-of-line continuations : `g:javascript_opfirst` ( same as above ) ## Contributing From 0cab45687178cb67c4bf19173e24ab010cd6fa26 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sun, 14 Aug 2016 13:00:18 -0700 Subject: [PATCH 36/52] regex improvements --- indent/javascript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index f40cf605..1a6eedde 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -60,12 +60,12 @@ let s:line_term = '\%(\s*\%(\/\*.\{-}\*\/\s*\)\=\)\@>$' " configurable regexes that define continuation lines, not including (, {, or [. if !exists('g:javascript_opfirst') - let g:javascript_opfirst = '\%([<>,:?^%]\|\([-/.+]\)\%(\1\|\*\|\/\)\@!\|\*\/\@!\|=>\@!\||\|&\|in\%(stanceof\)\=\>\)' + let g:javascript_opfirst = '\%([<>,:?^%|&]\|\([-/.+]\)\%(\1\|\*\|\/\)\@!\|\*\/\@!\|=>\@!\|in\%(stanceof\)\=\>\)' endif let g:javascript_opfirst = s:line_pre . g:javascript_opfirst if !exists('g:javascript_continuation') - let g:javascript_continuation = '\%([<*,.?:^%]\|+\@\|\*\@\|\*\@ Date: Mon, 15 Aug 2016 18:44:52 -0700 Subject: [PATCH 37/52] block statement (#596) this uses the same algorithm from https://github.com/sweet-js/sweet.js/wiki/design#give-lookbehind-to-the-reader which the acorn parser also uses. it actually is basically the same as what i had originally but with support for labeled block statements and plain block statements. --- indent/javascript.vim | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 1a6eedde..38acae0d 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -2,7 +2,7 @@ " Language: Javascript " Maintainer: vim-javascript community " URL: https://github.com/pangloss/vim-javascript -" Last Change: August 7, 2016 +" Last Change: August 15, 2016 " Only load this indent file when no other was loaded. if exists('b:did_indent') @@ -70,13 +70,19 @@ endif let g:javascript_continuation .= s:line_term function s:Onescope(lnum,text,add) - return a:text =~# '\%(\' . (a:add ? '\|\\)' . s:line_term ? 'no b' : \ ((a:add && a:text =~ s:line_pre . '$' && search('\%' . s:PrevCodeLine(a:lnum - 1) . 'l.)' . s:line_term)) || \ cursor(a:lnum, match(a:text, ')' . s:line_term)) > -1) && - \ s:lookForParens('(', ')', 'cbW', 100) > 0 && search((a:add ? - \ '\%(function\*\|[[:lower:][:upper:]_$][[:digit:][:lower:][:upper:]_$]*\)' : - \ '\<\%(for\%(\s\+each\)\=\|if\|let\|w\%(hile\|ith\)\)') . '\_s*\%#\C','bW') && - \ (a:add || (expand('') ==# 'while' ? !s:lookForParens('\\C', '\\C','bW',100) : 1)) + \ s:lookForParens('(', ')', 'cbW', 100) > 0 && search('\C\l\+\_s*\%#','bW') && + \ (a:add || ((expand('') !=# 'while' || !s:lookForParens('\C\', '\C\','nbW',100)) && + \ expand('cword') !=# 'each' || search('\C\') : '' +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\%(\%([-=~!<*+,.?^%|&\[(]\|=\@\|\*\@") !=# 'switch' ? 0 : &cino !~ ':' || !has('float') ? s:sw() : + call cursor(b:js_cache[1:]) + let inb = num == 0 || num < l:lnum && ((l:line !~ s:line_pre . ',' && pline !~ ',' . s:line_term) || s:isBlock()) + let switch_offset = num == 0 || s:Onescope(num, s:StripLine(strpart(getline(num),0,b:js_cache[2] - 1)),1) !=# 'switch' ? 0 : + \ &cino !~ ':' || !has('float') ? s:sw() : \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (&cino =~# '.*:[^,]*s' ? s:sw() : 1)) " most significant, find the indent amount if (inb && (l:line =~# g:javascript_opfirst || - \ (pline =~# g:javascript_continuation && pline !~# s:expr_case && (pline !~ ':' . s:line_term || l:line !~# - \ s:line_pre . '\%(d\%(o\|ebugger\)\|else\|f\%(or\|inally\)\|if\|let\|switch\|t\%(hrow\|ry\)\|w\%(hile\|ith\)\)\>')))) || - \ (num < l:lnum && s:Onescope(l:lnum,pline,0) && l:line !~ s:line_pre . '{') + \ (pline =~# g:javascript_continuation && pline !~# s:expr_case))) || + \ (num < l:lnum && s:Onescope(l:lnum,pline,0) =~# '\%(for\|each\|if\|let\|no\sb\|w\%(hile\|ith\)\)' && + \ l:line !~ s:line_pre . '{') return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset elseif num > 0 return indent(num) + s:sw() + switch_offset From 3a20412d264f369dc09d2f29dd6e5f95614c0a22 Mon Sep 17 00:00:00 2001 From: bounceme Date: Tue, 16 Aug 2016 19:21:52 -0700 Subject: [PATCH 38/52] cleaning (#601) cleaning and improving readability --- indent/javascript.vim | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 38acae0d..882fe48a 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -2,7 +2,7 @@ " Language: Javascript " Maintainer: vim-javascript community " URL: https://github.com/pangloss/vim-javascript -" Last Change: August 15, 2016 +" Last Change: August 16, 2016 " Only load this indent file when no other was loaded. if exists('b:did_indent') @@ -46,15 +46,17 @@ let s:syng_strcom = '\%(s\%(tring\|pecial\)\|comment\|regex\|doc\|template\)' let s:syng_comment = '\%(comment\|doc\)' " Expression used to check whether we should skip a match with searchpair(). -let s:skip_expr = "line('.') < (prevnonblank(v:lnum) - 2000) ? dummy : synIDattr(synID(line('.'),col('.'),0),'name') =~? '".s:syng_strcom."'" +let s:skip_expr = "synIDattr(synID(line('.'),col('.'),0),'name') =~? '".s:syng_strcom."'" -function s:lookForParens(start,end,flags,time) - if has('reltime') - return searchpair(a:start,'',a:end,a:flags,s:skip_expr,0,a:time) - else - return searchpair(a:start,'',a:end,a:flags,0,0) - endif -endfunction +if has('reltime') + function s:lookForParens(start,end,flags,time) + return searchpair(a:start,'',a:end,a:flags,s:skip_expr,max([prevnonblank(v:lnum) - 2000,0]),a:time) + endfunction +else + function s:lookForParens(start,end,flags,n) + return searchpair(a:start,'',a:end,a:flags,0,max([prevnonblank(v:lnum) - 2000,0])) + endfunction +endif let s:line_term = '\%(\s*\%(\/\*.\{-}\*\/\s*\)\=\)\@>$' @@ -62,11 +64,11 @@ let s:line_term = '\%(\s*\%(\/\*.\{-}\*\/\s*\)\=\)\@>$' if !exists('g:javascript_opfirst') let g:javascript_opfirst = '\%([<>,:?^%|&]\|\([-/.+]\)\%(\1\|\*\|\/\)\@!\|\*\/\@!\|=>\@!\|in\%(stanceof\)\=\>\)' endif -let g:javascript_opfirst = s:line_pre . g:javascript_opfirst - if !exists('g:javascript_continuation') let g:javascript_continuation = '\%([<=*,.?:^%|&]\|+\@\|\*\@ 0 + while l:lnum if synIDattr(synID(l:lnum,matchend(getline(l:lnum), '^\s*[^''"]'),0),'name') !~? s:syng_strcom - break + return l:lnum endif let l:lnum = prevnonblank(l:lnum - 1) endwhile - return l:lnum endfunction " Check if line 'lnum' has a balanced amount of parentheses. @@ -176,7 +177,7 @@ function GetJavascriptIndent() endif let pline = s:StripLine(getline(l:lnum)) - call cursor(b:js_cache[1:]) + call cursor(b:js_cache[1],b:js_cache[2]) let inb = num == 0 || num < l:lnum && ((l:line !~ s:line_pre . ',' && pline !~ ',' . s:line_term) || s:isBlock()) let switch_offset = num == 0 || s:Onescope(num, s:StripLine(strpart(getline(num),0,b:js_cache[2] - 1)),1) !=# 'switch' ? 0 : \ &cino !~ ':' || !has('float') ? s:sw() : From cef306faf8ae064fed37590c03d4ffbca15e7836 Mon Sep 17 00:00:00 2001 From: bounceme Date: Wed, 17 Aug 2016 13:23:43 -0700 Subject: [PATCH 39/52] settings (#603) these don't seem to be very relevant when using indentexprs, and may override the indentation script, opinions on this are welcomed, and honestly I don't know exactly what effect these have. the clojure indent file and a few others included with vim has these options set to off --- indent/javascript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 882fe48a..21fdf3aa 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -12,11 +12,11 @@ let b:did_indent = 1 " Now, set up our indentation expression and keys that trigger it. setlocal indentexpr=GetJavascriptIndent() -setlocal nolisp +setlocal nolisp noautoindent nosmartindent setlocal indentkeys=0{,0},0),0],:,!^F,o,O,e setlocal cinoptions+=j1,J1 -let b:undo_indent = 'setlocal indentexpr< indentkeys< cinoptions<' +let b:undo_indent = 'setlocal indentexpr< smartindent< autoindent< indentkeys< cinoptions<' " Only define the function once. if exists('*GetJavascriptIndent') From aadf36b731716105d0b63454f508c7272b67a69e Mon Sep 17 00:00:00 2001 From: bounceme Date: Wed, 17 Aug 2016 19:11:37 -0700 Subject: [PATCH 40/52] cache can be invalid for he current line --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 21fdf3aa..ec756641 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -160,7 +160,7 @@ function GetJavascriptIndent() " the containing paren, bracket, curly. Memoize, last lineNr either has the " same scope or starts a new one, unless if it closed a scope. call cursor(v:lnum,1) - if b:js_cache[0] >= l:lnum && b:js_cache[0] <= v:lnum && b:js_cache[0] && + if b:js_cache[0] >= l:lnum && b:js_cache[0] < v:lnum && b:js_cache[0] && \ (b:js_cache[0] > l:lnum || s:Balanced(l:lnum) > 0) let num = b:js_cache[1] elseif syns != '' && l:line[0] =~ '\s' From f16fe69f0f6fee588c96ce4131dd4c93860cbb04 Mon Sep 17 00:00:00 2001 From: bounceme Date: Thu, 18 Aug 2016 11:50:57 -0700 Subject: [PATCH 41/52] Change function names --- indent/javascript.vim | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index ec756641..bae12128 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -49,11 +49,11 @@ let s:syng_comment = '\%(comment\|doc\)' let s:skip_expr = "synIDattr(synID(line('.'),col('.'),0),'name') =~? '".s:syng_strcom."'" if has('reltime') - function s:lookForParens(start,end,flags,time) + function s:GetPair(start,end,flags,time) return searchpair(a:start,'',a:end,a:flags,s:skip_expr,max([prevnonblank(v:lnum) - 2000,0]),a:time) endfunction else - function s:lookForParens(start,end,flags,n) + function s:GetPair(start,end,flags,n) return searchpair(a:start,'',a:end,a:flags,0,max([prevnonblank(v:lnum) - 2000,0])) endfunction endif @@ -75,16 +75,16 @@ function s:Onescope(lnum,text,add) return a:text =~# '\%(\\)' . s:line_term ? 'no b' : \ ((a:add && a:text =~ s:line_pre . '$' && search('\%' . s:PrevCodeLine(a:lnum - 1) . 'l.)' . s:line_term)) || \ cursor(a:lnum, match(a:text, ')' . s:line_term)) > -1) && - \ s:lookForParens('(', ')', 'cbW', 100) > 0 && search('\C\l\+\_s*\%#','bW') && - \ (a:add || ((expand('') !=# 'while' || !s:lookForParens('\C\', '\C\','nbW',100)) && + \ s:GetPair('(', ')', 'cbW', 100) > 0 && search('\C\l\+\_s*\%#','bW') && + \ (a:add || ((expand('') !=# 'while' || !s:GetPair('\C\', '\C\','nbW',100)) && \ expand('cword') !=# 'each' || search('\C\') : '' endfunction " https://github.com/sweet-js/sweet.js/wiki/design#give-lookbehind-to-the-reader -function s:isBlock() +function s:IsBlock() return getline(line('.'))[col('.')-1] == '{' && !search( \ '\C\%(\%([-=~!<*+,.?^%|&\[(]\|=\@\|\*\@ Date: Thu, 18 Aug 2016 11:54:00 -0700 Subject: [PATCH 42/52] Rename function --- indent/javascript.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index bae12128..4b11fdd3 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -71,7 +71,7 @@ endif let g:javascript_opfirst = s:line_pre . g:javascript_opfirst let g:javascript_continuation .= s:line_term -function s:Onescope(lnum,text,add) +function s:OneScope(lnum,text,add) return a:text =~# '\%(\\)' . s:line_term ? 'no b' : \ ((a:add && a:text =~ s:line_pre . '$' && search('\%' . s:PrevCodeLine(a:lnum - 1) . 'l.)' . s:line_term)) || \ cursor(a:lnum, match(a:text, ')' . s:line_term)) > -1) && @@ -179,14 +179,14 @@ function GetJavascriptIndent() let pline = s:StripLine(getline(l:lnum)) call cursor(b:js_cache[1],b:js_cache[2]) let inb = num == 0 || num < l:lnum && ((l:line !~ s:line_pre . ',' && pline !~ ',' . s:line_term) || s:IsBlock()) - let switch_offset = num == 0 || s:Onescope(num, s:StripLine(strpart(getline(num),0,b:js_cache[2] - 1)),1) !=# 'switch' ? 0 : + let switch_offset = num == 0 || s:OneScope(num, s:StripLine(strpart(getline(num),0,b:js_cache[2] - 1)),1) !=# 'switch' ? 0 : \ &cino !~ ':' || !has('float') ? s:sw() : \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (&cino =~# '.*:[^,]*s' ? s:sw() : 1)) " most significant, find the indent amount if (inb && (l:line =~# g:javascript_opfirst || \ (pline =~# g:javascript_continuation && pline !~# s:expr_case))) || - \ (num < l:lnum && s:Onescope(l:lnum,pline,0) =~# '\%(for\|each\|if\|let\|no\sb\|w\%(hile\|ith\)\)' && + \ (num < l:lnum && s:OneScope(l:lnum,pline,0) =~# '\%(for\|each\|if\|let\|no\sb\|w\%(hile\|ith\)\)' && \ l:line !~ s:line_pre . '{') return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset elseif num > 0 From 67f2990a8b74d8e72387fced7a8b6d09b9c62e22 Mon Sep 17 00:00:00 2001 From: bounceme Date: Thu, 18 Aug 2016 17:41:47 -0700 Subject: [PATCH 43/52] regex improvements (#607) small regex improvements --- indent/javascript.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 4b11fdd3..321d56f1 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -37,7 +37,7 @@ else endfunction endif -let s:line_pre = '^\s*\%(\/\*.\{-}\*\/\s*\)*' +let s:line_pre = '^\s*\%(\%(\/\*.\{-}\)\=\*\+\/\s*\)\=' let s:expr_case = s:line_pre . '\%(\%(case\>.\+\)\|default\)\s*:' " Regex of syntax group names that are or delimit string or are comments. let s:syng_strcom = '\%(s\%(tring\|pecial\)\|comment\|regex\|doc\|template\)' @@ -58,14 +58,14 @@ else endfunction endif -let s:line_term = '\%(\s*\%(\/\*.\{-}\*\/\s*\)\=\)\@>$' +let s:line_term = '\s*\%(\%(\/\%(\%(\*.\{-}\*\/\)\|\%(\*\+\)\)\)\s*\)\=$' " configurable regexes that define continuation lines, not including (, {, or [. if !exists('g:javascript_opfirst') - let g:javascript_opfirst = '\%([<>,:?^%|&]\|\([-/.+]\)\%(\1\|\*\|\/\)\@!\|\*\/\@!\|=>\@!\|in\%(stanceof\)\=\>\)' + let g:javascript_opfirst = '\%([<>,:?^%|*&]\|\([-/.+]\)\1\@!\|=>\@!\|in\%(stanceof\)\=\>\)' endif if !exists('g:javascript_continuation') - let g:javascript_continuation = '\%([<=*,.?:^%|&]\|+\@\|\*\@\|\ Date: Thu, 18 Aug 2016 21:03:43 -0700 Subject: [PATCH 44/52] more regex (#608) --- indent/javascript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 321d56f1..214d83d5 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -37,7 +37,7 @@ else endfunction endif -let s:line_pre = '^\s*\%(\%(\/\*.\{-}\)\=\*\+\/\s*\)\=' +let s:line_pre = '^\s*\%(\%(\%(\/\*.\{-}\)\=\*\+\/\s*\)\=\)\@>' let s:expr_case = s:line_pre . '\%(\%(case\>.\+\)\|default\)\s*:' " Regex of syntax group names that are or delimit string or are comments. let s:syng_strcom = '\%(s\%(tring\|pecial\)\|comment\|regex\|doc\|template\)' @@ -83,7 +83,7 @@ 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\%(\%([-=~!<*+,.?^%|&\[(]\|=\@\|\*\@\|\*\@ Date: Fri, 19 Aug 2016 14:58:34 -0700 Subject: [PATCH 45/52] function removed,cleaning --- indent/javascript.vim | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 214d83d5..b7b463ec 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -89,11 +89,6 @@ endfunction " Auxiliary Functions {{{2 -" strip line of comment -function s:StripLine(c) - return a:c !~# s:expr_case ? substitute(a:c, '\%(:\@ 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset From 8eea63270067ca03cadbd0548866684729a986ac Mon Sep 17 00:00:00 2001 From: bounceme Date: Fri, 19 Aug 2016 18:53:03 -0700 Subject: [PATCH 46/52] fix foreach method calls --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index b7b463ec..5a16f2ac 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -182,7 +182,7 @@ function GetJavascriptIndent() " most significant, find the indent amount if (inb && (l:line =~# g:javascript_opfirst || (!swcase && pline =~# g:javascript_continuation))) || - \ (num < l:lnum && s:OneScope(l:lnum,pline,0) =~# '\%(for\|each\|if\|let\|no\sb\|w\%(hile\|ith\)\)' && + \ (num < l:lnum && s:OneScope(l:lnum,pline,0) =~# '\%(for\|each\|if\|let\|no\sb\|w\%(hile\|ith\)\)\>' && \ l:line !~ s:line_pre . '{') return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset elseif num > 0 From efab7db0bb6ee2898b716962c69b10697c04822c Mon Sep 17 00:00:00 2001 From: bounceme Date: Fri, 19 Aug 2016 19:15:43 -0700 Subject: [PATCH 47/52] date --- indent/javascript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 5a16f2ac..d68b3971 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -2,7 +2,7 @@ " Language: Javascript " Maintainer: vim-javascript community " URL: https://github.com/pangloss/vim-javascript -" Last Change: August 16, 2016 +" Last Change: August 19, 2016 " Only load this indent file when no other was loaded. if exists('b:did_indent') @@ -182,7 +182,7 @@ function GetJavascriptIndent() " most significant, find the indent amount if (inb && (l:line =~# g:javascript_opfirst || (!swcase && pline =~# g:javascript_continuation))) || - \ (num < l:lnum && s:OneScope(l:lnum,pline,0) =~# '\%(for\|each\|if\|let\|no\sb\|w\%(hile\|ith\)\)\>' && + \ (num < l:lnum && s:OneScope(l:lnum,pline,0) =~# '\<\%(for\|each\|if\|let\|no\sb\|w\%(hile\|ith\)\)\>' && \ l:line !~ s:line_pre . '{') return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset elseif num > 0 From 055ce0ca67955c4d457b08ec3fe6f84a619ed951 Mon Sep 17 00:00:00 2001 From: bounceme Date: Fri, 19 Aug 2016 21:02:33 -0700 Subject: [PATCH 48/52] switch stuff --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index d68b3971..18c5dae9 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -181,7 +181,7 @@ function GetJavascriptIndent() \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (&cino =~# '.*:[^,]*s' ? s:sw() : 1)) " most significant, find the indent amount - if (inb && (l:line =~# g:javascript_opfirst || (!swcase && pline =~# g:javascript_continuation))) || + if (inb && (!swcase && (l:line =~# g:javascript_opfirst || pline =~# g:javascript_continuation))) || \ (num < l:lnum && s:OneScope(l:lnum,pline,0) =~# '\<\%(for\|each\|if\|let\|no\sb\|w\%(hile\|ith\)\)\>' && \ l:line !~ s:line_pre . '{') return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset From 95161928410806a14974284195304364f4557547 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sat, 20 Aug 2016 00:39:34 -0700 Subject: [PATCH 49/52] case statements update --- indent/javascript.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 18c5dae9..02e332a9 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -2,7 +2,7 @@ " Language: Javascript " Maintainer: vim-javascript community " URL: https://github.com/pangloss/vim-javascript -" Last Change: August 19, 2016 +" Last Change: August 20, 2016 " Only load this indent file when no other was loaded. if exists('b:did_indent') @@ -181,8 +181,8 @@ function GetJavascriptIndent() \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (&cino =~# '.*:[^,]*s' ? s:sw() : 1)) " most significant, find the indent amount - if (inb && (!swcase && (l:line =~# g:javascript_opfirst || pline =~# g:javascript_continuation))) || - \ (num < l:lnum && s:OneScope(l:lnum,pline,0) =~# '\<\%(for\|each\|if\|let\|no\sb\|w\%(hile\|ith\)\)\>' && + if inb && !swcase && ((l:line =~# g:javascript_opfirst || pline =~# g:javascript_continuation) || + \ num < l:lnum && s:OneScope(l:lnum,pline,0) =~# '\<\%(for\|each\|if\|let\|no\sb\|w\%(hile\|ith\)\)\>' && \ l:line !~ s:line_pre . '{') return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset elseif num > 0 From 34a070cc3d8a3c71812f82bceb6b559e41dffff1 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sat, 20 Aug 2016 11:57:11 -0700 Subject: [PATCH 50/52] minor style changes --- indent/javascript.vim | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 02e332a9..51881d16 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -102,9 +102,7 @@ endfunction " Check if line 'lnum' has a balanced amount of parentheses. function s:Balanced(lnum) - let open_0 = 0 - let open_2 = 0 - let open_4 = 0 + let [open_0,open_2,open_4] = [0,0,0] let l:line = getline(a:lnum) let pos = match(l:line, '[][(){}]', 0) while pos != -1 @@ -131,7 +129,7 @@ function GetJavascriptIndent() let syns = synIDattr(synID(v:lnum, 1, 0), 'name') " start with strings,comments,etc.{{{2 - if (l:line !~ '^[''"`]' && syns =~? 'string\|template') || + if (l:line !~ '^[''"`]' && syns =~? '\%(string\|template\)') || \ (l:line !~ '^\s*[/*]' && syns =~? s:syng_comment) return -1 endif From 6787729dca38a1e4be5c13586b1e94e2624f5762 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sat, 20 Aug 2016 21:28:58 -0700 Subject: [PATCH 51/52] remove ugly function call --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 51881d16..612771f9 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -174,7 +174,7 @@ function GetJavascriptIndent() let swcase = getline(l:lnum) =~# s:expr_case let pline = swcase ? getline(l:lnum) : substitute(getline(l:lnum), '\%(:\@ Date: Sat, 20 Aug 2016 21:36:24 -0700 Subject: [PATCH 52/52] last commit revert --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 612771f9..51881d16 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -174,7 +174,7 @@ function GetJavascriptIndent() let swcase = getline(l:lnum) =~# s:expr_case let pline = swcase ? getline(l:lnum) : substitute(getline(l:lnum), '\%(:\@