From d3e952cf8ddb556233638915c79be57c752cda7d Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 18 Sep 2016 01:41:39 -0700 Subject: [PATCH 01/42] multi-braceless statements (#636) * multi-braceless statements This changes: ``` if (1) for (;;) i += l ``` to: ``` if (1) for (;;) i += l ``` --- indent/javascript.vim | 60 +++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 1591dac0..b890a43a 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -75,15 +75,38 @@ if !exists('g:javascript_continuation') let g:javascript_continuation = '\%([<=,.?/*^%|&:]\|+\@\|\\)' . s:line_term ? 'no b' : + return cursor(a:lnum, match(' ' . a:text, '\%(\\)' . s:line_term)) > -1 || \ cursor(a:lnum, match(' ' . a:text, ')' . s:line_term)) > -1 && - \ s:GetPair('(', ')', 'bW', s:skip_expr, 100) > 0 && search('\C\l\+\_s*\%#','bW') && - \ (expand('') !=# 'while' || s:GetPair('\C\', '\C\','nbW',s:skip_expr,100) <= 0) && - \ (expand('') !=# 'each' || search('\C\') : '' + \ s:GetPair('(', ')', 'bW', s:skip_expr, 100) > 0 && + \ search('\C\<\%(for\%(\_s\+each\)\=\|if\|let\|w\%(hile\|ith\)\)\_s*\%#','bW') +endfunction + +function s:iscontOne(i,num,cont) + let [l:i, l:cont, l:num] = [a:i, a:cont, a:num > 0 ? a:num : 1] + let pind = a:num > 0 ? indent(l:num) : -s:sw() + let ind = indent(l:i) + (!l:cont ? s:sw() : 0) + let bL = 0 + while l:i >= l:num && (!l:cont || ind > pind + s:sw()) + if indent(l:i) < ind " first line always true for !cont, false for !!cont + if s:OneScope(l:i,substitute(getline(l:i),':\@') ==# 'while' && searchpair(s:line_pre . '\C\','','\C\','bW',s:skip_expr,l:num,100) > 0 + return 0 + endif + let bL += 1 + let l:cont = 0 + let l:i = line('.') + elseif !l:cont + break + endif + let ind = indent(l:i) + endif + let l:i = s:PrevCodeLine(l:i - 1) + endwhile + return bL * s:sw() endfunction " https://github.com/sweet-js/sweet.js/wiki/design#give-lookbehind-to-the-reader @@ -138,8 +161,8 @@ function GetJavascriptIndent() let syns = synIDattr(synID(v:lnum, 1, 0), 'name') " start with strings,comments,etc.{{{2 - if (l:line !~ '^[''"]' && syns =~? '\%(string\|template\)') || - \ (l:line !~ '^\s*[/*]' && syns =~? s:syng_comment) + if l:line !~ '^[''"]' && syns =~? '\%(string\|template\)' || + \ l:line !~ '^\s*[/*]' && syns =~? s:syng_comment return -1 endif if l:line !~ '^\%(\/\*\|\s*\/\/\)' && syns =~? s:syng_comment @@ -150,7 +173,7 @@ function GetJavascriptIndent() return 0 endif - if (l:line =~# s:expr_case) + if l:line =~# s:expr_case let cpo_switch = &cpo set cpo+=% let ind = cindent(v:lnum) @@ -176,11 +199,16 @@ function GetJavascriptIndent() let b:js_cache = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] - if l:line =~ s:line_pre . '[])}]' + let l:line = substitute(l:line,s:line_pre,'','') + if l:line =~ '^[])}]' return indent(num) endif + call cursor(v:lnum,1) + if l:line =~# '^while\>' && searchpair(s:line_pre . '\C\','','\C\','bW',s:skip_expr,num,100) > 0 + return indent(line('.')) + endif - let pline = substitute(substitute(getline(l:lnum),s:expr_case,'\=repeat(" ",strlen(submatch(0)))',''), '\%(:\@ 0 && search('\C\' && - \ l:line !~ s:line_pre . '{' - return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset + let bL = s:iscontOne(l:lnum,num,isOp) + let bL = bL ? bL - (l:line =~ '^{') * s:sw() : bL + if isOp && (num <= 0 || cursor(b:js_cache[1],b:js_cache[2]) || s:IsBlock()) + return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset + bL elseif num > 0 - return indent(num) + s:sw() + switch_offset + return indent(num) + s:sw() + switch_offset + bL endif - + return bL endfunction From ebd222b3dfd05878145be3488573745aa160de70 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 18 Sep 2016 04:00:10 -0700 Subject: [PATCH 02/42] date,format --- indent/javascript.vim | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index b890a43a..42eb0882 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: September 4, 2016 +" Last Change: September 18, 2016 " Only load this indent file when no other was loaded. if exists('b:did_indent') @@ -112,12 +112,10 @@ 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: Sun, 18 Sep 2016 04:06:48 -0700 Subject: [PATCH 03/42] Update javascript.vim --- indent/javascript.vim | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 42eb0882..836fc6d6 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -97,8 +97,7 @@ function s:iscontOne(i,num,cont) return 0 endif let bL += 1 - let l:cont = 0 - let l:i = line('.') + let [l:cont, l:i] = [0, line('.')] elseif !l:cont break endif @@ -148,7 +147,6 @@ function s:Balanced(lnum) endwhile return (!open_4 + !open_2 + !open_0) - 2 endfunction -" }}} function GetJavascriptIndent() if !exists('b:js_cache') From 6426110f831bd2ab6459e87c5bffad99d18697e1 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 18 Sep 2016 14:49:38 -0700 Subject: [PATCH 04/42] Update javascript.vim --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 836fc6d6..646954f2 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -156,7 +156,7 @@ function GetJavascriptIndent() let l:line = getline(v:lnum) let syns = synIDattr(synID(v:lnum, 1, 0), 'name') - " start with strings,comments,etc.{{{2 + " start with strings,comments,etc. if l:line !~ '^[''"]' && syns =~? '\%(string\|template\)' || \ l:line !~ '^\s*[/*]' && syns =~? s:syng_comment return -1 From aa37199ecf040b7003f2d523b83f9ef0f04d25e3 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 18 Sep 2016 15:41:46 -0700 Subject: [PATCH 05/42] change to searchpair helper --- indent/javascript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 646954f2..8d5ced26 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -93,7 +93,7 @@ function s:iscontOne(i,num,cont) while l:i >= l:num && (!l:cont || ind > pind + s:sw()) if indent(l:i) < ind " first line always true for !cont, false for !!cont if s:OneScope(l:i,substitute(getline(l:i),':\@') ==# 'while' && searchpair(s:line_pre . '\C\','','\C\','bW',s:skip_expr,l:num,100) > 0 + if expand('') ==# 'while' && s:GetPair(s:line_pre . '\C\\%>'.l:num-1.'l','\C\','bW',s:skip_expr,100) > 0 return 0 endif let bL += 1 @@ -199,7 +199,7 @@ function GetJavascriptIndent() return indent(num) endif call cursor(v:lnum,1) - if l:line =~# '^while\>' && searchpair(s:line_pre . '\C\','','\C\','bW',s:skip_expr,num,100) > 0 + if l:line =~# '^while\>' && s:GetPair(s:line_pre . '\C\\%>'.num-1.'l','\C\','bW',s:skip_expr,100) > 0 return indent(line('.')) endif From b2ded12588b35aa551240ec33e637f7ef04d52eb Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 18 Sep 2016 16:02:55 -0700 Subject: [PATCH 06/42] change num <= 0 to 0 --- indent/javascript.vim | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 8d5ced26..83e889b6 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -192,6 +192,7 @@ function GetJavascriptIndent() let num = s:GetPair('[({[]','[])}]','bW','s:skip_func(s:looksyn)',2000) endif + let num = num > 0 ? num : 0 let b:js_cache = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] let l:line = substitute(l:line,s:line_pre,'','') @@ -199,13 +200,13 @@ function GetJavascriptIndent() return indent(num) endif call cursor(v:lnum,1) - if l:line =~# '^while\>' && s:GetPair(s:line_pre . '\C\\%>'.num-1.'l','\C\','bW',s:skip_expr,100) > 0 + if l:line =~# '^while\>' && s:GetPair(s:line_pre . '\C\\%>'.(num-!!num).'l','\C\','bW',s:skip_expr,100) > 0 return indent(line('.')) endif let pline = substitute(substitute(getline(l:lnum),s:expr_case,'\=repeat(" ",strlen(submatch(0)))',''), ':\@ 0 && search('\C\ 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset + bL - elseif num > 0 + if isOp && (!num || cursor(b:js_cache[1],b:js_cache[2]) || s:IsBlock()) + return (num ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset + bL + elseif num return indent(num) + s:sw() + switch_offset + bL endif return bL From 5df8b344a49c54be1bfe133a62f4fc00fc313bd7 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 18 Sep 2016 16:15:26 -0700 Subject: [PATCH 07/42] more number conversion --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 83e889b6..2f09133a 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -86,7 +86,7 @@ function s:OneScope(lnum,text) endfunction function s:iscontOne(i,num,cont) - let [l:i, l:cont, l:num] = [a:i, a:cont, a:num > 0 ? a:num : 1] + let [l:i, l:cont, l:num] = [a:i, a:cont, a:num ? a:num : 1] let pind = a:num > 0 ? indent(l:num) : -s:sw() let ind = indent(l:i) + (!l:cont ? s:sw() : 0) let bL = 0 From 3b38947f2f90d8bfa1522ecb67856238f305e606 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 18 Sep 2016 16:19:47 -0700 Subject: [PATCH 08/42] prev --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 2f09133a..30e64eb1 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -87,7 +87,7 @@ endfunction function s:iscontOne(i,num,cont) let [l:i, l:cont, l:num] = [a:i, a:cont, a:num ? a:num : 1] - let pind = a:num > 0 ? indent(l:num) : -s:sw() + let pind = a:num ? indent(l:num) : -s:sw() let ind = indent(l:i) + (!l:cont ? s:sw() : 0) let bL = 0 while l:i >= l:num && (!l:cont || ind > pind + s:sw()) From ff5f3f14418765b487a9071db8f7ff72946f1fe1 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Mon, 19 Sep 2016 01:17:29 -0700 Subject: [PATCH 09/42] fix concat bug --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 30e64eb1..aee8e2c3 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -93,7 +93,7 @@ function s:iscontOne(i,num,cont) while l:i >= l:num && (!l:cont || ind > pind + s:sw()) if indent(l:i) < ind " first line always true for !cont, false for !!cont if s:OneScope(l:i,substitute(getline(l:i),':\@') ==# 'while' && s:GetPair(s:line_pre . '\C\\%>'.l:num-1.'l','\C\','bW',s:skip_expr,100) > 0 + if expand('') ==# 'while' && s:GetPair(s:line_pre . '\C\\%>'.(l:num-1).'l','\C\','bW',s:skip_expr,100) > 0 return 0 endif let bL += 1 From 1219b150b063df8979ab48a4a2e6f3bb6e502840 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Tue, 20 Sep 2016 19:20:01 -0700 Subject: [PATCH 10/42] small skip_func improvements (#637) this will improve performance depending on the file. I will try and clean it a little --- indent/javascript.vim | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index aee8e2c3..3ec4abe6 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -48,11 +48,13 @@ let s:syng_comment = '\%(comment\|doc\)' " Expression used to check whether we should skip a match with searchpair(). let s:skip_expr = "synIDattr(synID(line('.'),col('.'),0),'name') =~? '".s:syng_strcom."'" function s:skip_func(lnum) - if !s:free || getline(line('.')) =~ '[''/"\\]' || search('`','nW',a:lnum) || search('\*\/','nW',a:lnum) + if !s:free || search('`','nW',a:lnum) || search('\*\/','nW',a:lnum) let s:free = !eval(s:skip_expr) + let s:looksyn = s:free ? line('.') : s:looksyn + return !s:free endif - let s:looksyn = s:free ? line('.') : s:looksyn - return !s:free + let s:looksyn = line('.') + return getline(line('.')) =~ '[''/"\\]' && eval(s:skip_expr) endfunction if has('reltime') From afbe2844ee39d0c01a7b27214262d817550ea0c8 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Tue, 20 Sep 2016 22:41:36 -0700 Subject: [PATCH 11/42] more minor optimizations (#638) --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 3ec4abe6..67006e35 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -54,7 +54,7 @@ function s:skip_func(lnum) return !s:free endif let s:looksyn = line('.') - return getline(line('.')) =~ '[''/"\\]' && eval(s:skip_expr) + return (search('\/','nbW',line('.')) || search('[''"\\]','nW',line('.'))) && eval(s:skip_expr) endfunction if has('reltime') From a7225e4bd1882236c5a7db10aadcdfca1de3b352 Mon Sep 17 00:00:00 2001 From: Amadeus Demarzi Date: Thu, 22 Sep 2016 02:07:40 -0700 Subject: [PATCH 12/42] Fix jsGlobalNodeObjects and jsFuncCall priority Give jsGlobalNodeObjects a higher priority that can therefore be targeted if desired. --- syntax/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index 56e7c6d3..20b131b2 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -114,7 +114,7 @@ syntax match jsSwitchColon contained /:/ skipwhite skipempty nextgro " Keywords syntax keyword jsGlobalObjects Array Boolean Date Function Iterator Number Object Symbol Map WeakMap Set RegExp String Proxy Promise Buffer ParallelArray ArrayBuffer DataView Float32Array Float64Array Int16Array Int32Array Int8Array Uint16Array Uint32Array Uint8Array Uint8ClampedArray JSON Math console document window Intl Collator DateTimeFormat NumberFormat syntax keyword jsGlobalNodeObjects module exports global process -syntax match jsGlobalNodeObjects /require/ contains=jsFuncCall +syntax match jsGlobalNodeObjects /require/ containedin=jsFuncCall syntax keyword jsExceptions Error EvalError InternalError RangeError ReferenceError StopIteration SyntaxError TypeError URIError syntax keyword jsBuiltins decodeURI decodeURIComponent encodeURI encodeURIComponent eval isFinite isNaN parseFloat parseInt uneval " DISCUSS: How imporant is this, really? Perhaps it should be linked to an error because I assume the keywords are reserved? From d94ab71e2230896f0d5a30c3c812dcd4058cef3d Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Thu, 22 Sep 2016 21:28:57 -0700 Subject: [PATCH 13/42] optimize top scope indentation speed (#640) makes a huge difference when not in a 'scope'. avoids checking the whole file * improve helper --- indent/javascript.vim | 61 +++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 67006e35..fb500d7d 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -58,12 +58,12 @@ function s:skip_func(lnum) endfunction if has('reltime') - function s:GetPair(start,end,flags,skip,time) - return searchpair(a:start,'',a:end,a:flags,a:skip,max([prevnonblank(v:lnum) - 2000,0]),a:time) + function s:GetPair(start,end,flags,skip,time,...) + return searchpair(a:start,'',a:end,a:flags,a:skip,max([prevnonblank(v:lnum) - 2000,0] + a:000),a:time) endfunction else function s:GetPair(start,end,flags,...) - return searchpair(a:start,'',a:end,a:flags,0,max([prevnonblank(v:lnum) - 2000,0])) + return searchpair(a:start,'',a:end,a:flags,"line('.') < prevnonblank(v:lnum) - 2000 ? dummy : 0") endfunction endif @@ -88,14 +88,14 @@ function s:OneScope(lnum,text) endfunction function s:iscontOne(i,num,cont) - let [l:i, l:cont, l:num] = [a:i, a:cont, a:num ? a:num : 1] - let pind = a:num ? indent(l:num) : -s:sw() - let ind = indent(l:i) + (!l:cont ? s:sw() : 0) + let [l:i, l:cont, l:num] = [a:i, a:cont, a:num + !a:num] + let pind = a:num ? indent(l:num) : -s:W + let ind = indent(l:i) + (!l:cont * s:W) let bL = 0 - while l:i >= l:num && (!l:cont || ind > pind + s:sw()) + while l:i >= l:num && (!l:cont || ind > pind + s:W) if indent(l:i) < ind " first line always true for !cont, false for !!cont if s:OneScope(l:i,substitute(getline(l:i),':\@') ==# 'while' && s:GetPair(s:line_pre . '\C\\%>'.(l:num-1).'l','\C\','bW',s:skip_expr,100) > 0 + if expand('') ==# 'while' && s:GetPair(s:line_pre . '\C\','\C\','bW',s:skip_expr,100,l:num) > 0 return 0 endif let bL += 1 @@ -107,7 +107,7 @@ function s:iscontOne(i,num,cont) endif let l:i = s:PrevCodeLine(l:i - 1) endwhile - return bL * s:sw() + return bL * s:W endfunction " https://github.com/sweet-js/sweet.js/wiki/design#give-lookbehind-to-the-reader @@ -136,7 +136,7 @@ function s:Balanced(lnum) while pos != -1 if synIDattr(synID(a:lnum,pos + 1,0),'name') !~? s:syng_strcom let idx = stridx('(){}[]', l:line[pos]) - if idx % 2 == 0 + if !(idx % 2) let open_{idx} += 1 else let open_{idx - 1} -= 1 @@ -147,7 +147,7 @@ function s:Balanced(lnum) endif let pos = match(l:line, '[][(){}]', pos + 1) endwhile - return (!open_4 + !open_2 + !open_0) - 2 + return !(open_4 || open_2 || open_0) endfunction function GetJavascriptIndent() @@ -181,46 +181,51 @@ 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. - let [s:looksyn,s:free] = [v:lnum - 1,1] call cursor(v:lnum,1) - if b:js_cache[0] < v:lnum && b:js_cache[0] >= l:lnum && - \ (b:js_cache[0] > l:lnum || s:Balanced(l:lnum) > 0) - let num = b:js_cache[1] - elseif syns != '' && l:line[0] =~ '\s' - let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : - \ syns =~? 'jsbracket'? ['\[','\]'] : ['[({[]','[])}]'] - let num = s:GetPair(pattern[0],pattern[1],'bW','s:skip_func(s:looksyn)',2000) + if getline(l:lnum) !~ '^\S' + let [s:looksyn,s:free] = [v:lnum - 1,1] + if b:js_cache[0] < v:lnum && b:js_cache[0] >= l:lnum && + \ (b:js_cache[0] > l:lnum || s:Balanced(l:lnum)) + let num = b:js_cache[1] + elseif syns != '' && l:line[0] =~ '\s' + let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : + \ syns =~? 'jsbracket'? ['\[','\]'] : ['[({[]','[])}]'] + let num = s:GetPair(pattern[0],pattern[1],'bW','s:skip_func(s:looksyn)',2000) + else + let num = s:GetPair('[({[]','[])}]','bW','s:skip_func(s:looksyn)',2000) + endif else - let num = s:GetPair('[({[]','[])}]','bW','s:skip_func(s:looksyn)',2000) + let num = s:GetPair('[({[]','[])}]','bW',s:skip_expr,200,l:lnum) endif - let num = num > 0 ? num : 0 + let num = (num > 0) * num let b:js_cache = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] let l:line = substitute(l:line,s:line_pre,'','') if l:line =~ '^[])}]' - return indent(num) + return !!num * indent(num) endif call cursor(v:lnum,1) - if l:line =~# '^while\>' && s:GetPair(s:line_pre . '\C\\%>'.(num-!!num).'l','\C\','bW',s:skip_expr,100) > 0 + if l:line =~# '^while\>' && s:GetPair(s:line_pre . '\C\','\C\','bW',s:skip_expr,100,num) > 0 return indent(line('.')) endif + let s:W = s:sw() let pline = substitute(substitute(getline(l:lnum),s:expr_case,'\=repeat(" ",strlen(submatch(0)))',''), ':\@ 0 && search('\C\ Date: Fri, 23 Sep 2016 20:03:19 -0700 Subject: [PATCH 14/42] normalize header in vim and current, date (#642) Any issues with this? It doesn't rlly mean anything, just something to satisfy vim/dev --- indent/javascript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index fb500d7d..ff4851ab 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -1,8 +1,8 @@ " Vim indent file " Language: Javascript -" Maintainer: vim-javascript community +" Maintainer: Chris Paul ( https://github.com/bounceme ) " URL: https://github.com/pangloss/vim-javascript -" Last Change: September 18, 2016 +" Last Change: September 23, 2016 " Only load this indent file when no other was loaded. if exists('b:did_indent') From fcdc1dcdb5256932330eb7bae16febbd43fb88d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Pr=C3=A9vost?= Date: Sat, 24 Sep 2016 19:29:46 -0400 Subject: [PATCH 15/42] Fix jsFlowTypeCustom regex to allow dots --- extras/flow.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras/flow.vim b/extras/flow.vim index a1848830..028ea3fc 100644 --- a/extras/flow.vim +++ b/extras/flow.vim @@ -6,7 +6,7 @@ syntax region jsFlowParens contained matchgroup=jsFlowNoise start=/(/ syntax match jsFlowNoise contained /[:;,<>]/ syntax keyword jsFlowType contained boolean number string null void any mixed JSON array function object array bool class syntax keyword jsFlowTypeof contained typeof skipempty skipempty nextgroup=jsFlowTypeCustom,jsFlowType -syntax match jsFlowTypeCustom contained /\k*/ skipwhite skipempty nextgroup=jsFlowGroup +syntax match jsFlowTypeCustom contained /[0-9a-zA-Z_.]*/ skipwhite skipempty nextgroup=jsFlowGroup syntax region jsFlowGroup contained matchgroup=jsFlowNoise start=// contains=@jsFlowCluster syntax region jsFlowArrowArguments contained matchgroup=jsFlowNoise start=/(/ end=/)\%(\s*=>\)\@=/ oneline skipwhite skipempty nextgroup=jsFlowArrow contains=@jsFlowCluster syntax match jsFlowArrow contained /=>/ skipwhite skipempty nextgroup=jsFlowType,jsFlowTypeCustom,jsFlowParens From ce7c06c390a1ec6b8b770d2813232b3fe41c02dd Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 25 Sep 2016 00:04:30 -0700 Subject: [PATCH 16/42] simplify comments --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index ff4851ab..d649c087 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -163,7 +163,7 @@ function GetJavascriptIndent() \ l:line !~ '^\s*[/*]' && syns =~? s:syng_comment return -1 endif - if l:line !~ '^\%(\/\*\|\s*\/\/\)' && syns =~? s:syng_comment + if l:line =~ '^\s*\*' && syns =~? s:syng_comment return cindent(v:lnum) endif let l:lnum = s:PrevCodeLine(v:lnum - 1) From 5453eb09dc7f79ca1aa49fd8dc9451d068a7e345 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 25 Sep 2016 00:27:20 -0700 Subject: [PATCH 17/42] more string/comment cleaning --- indent/javascript.vim | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index d649c087..a092d9cf 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -159,13 +159,15 @@ function GetJavascriptIndent() let syns = synIDattr(synID(v:lnum, 1, 0), 'name') " start with strings,comments,etc. - if l:line !~ '^[''"]' && syns =~? '\%(string\|template\)' || - \ l:line !~ '^\s*[/*]' && syns =~? s:syng_comment + if syns =~? s:syng_comment + if l:line =~ '^\s*\*' + return cindent(v:lnum) + elseif l:line !~ '^\s*\/' + return -1 + endif + elseif syns =~? '\%(string\|template\)' && l:line !~ '^[''"]' return -1 endif - if l:line =~ '^\s*\*' && syns =~? s:syng_comment - return cindent(v:lnum) - endif let l:lnum = s:PrevCodeLine(v:lnum - 1) if l:lnum == 0 return 0 From 02c8c644c306eb3675fdf9d0b556babd39e84d65 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 25 Sep 2016 00:50:34 -0700 Subject: [PATCH 18/42] remove rar --- indent/javascript.vim | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index a092d9cf..665a558b 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -42,9 +42,6 @@ let s:expr_case = s:line_pre . '\%(\%(case\>.\+\)\|default\)\s*:\C' " Regex of syntax group names that are or delimit string or are comments. 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\)' - " Expression used to check whether we should skip a match with searchpair(). let s:skip_expr = "synIDattr(synID(line('.'),col('.'),0),'name') =~? '".s:syng_strcom."'" function s:skip_func(lnum) @@ -159,7 +156,7 @@ function GetJavascriptIndent() let syns = synIDattr(synID(v:lnum, 1, 0), 'name') " start with strings,comments,etc. - if syns =~? s:syng_comment + if syns =~? '\%(comment\|doc\)' if l:line =~ '^\s*\*' return cindent(v:lnum) elseif l:line !~ '^\s*\/' From dc678406de4352fd03c49dfb2b0dc32733bd1ce9 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 25 Sep 2016 13:37:41 -0700 Subject: [PATCH 19/42] more optimization (#646) --- indent/javascript.vim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 665a558b..c6d5e110 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -178,6 +178,8 @@ function GetJavascriptIndent() return ind endif + let l:line = substitute(l:line,s:line_pre,'','') + " 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) @@ -186,7 +188,10 @@ function GetJavascriptIndent() if b:js_cache[0] < v:lnum && b:js_cache[0] >= l:lnum && \ (b:js_cache[0] > l:lnum || s:Balanced(l:lnum)) let num = b:js_cache[1] - elseif syns != '' && l:line[0] =~ '\s' + elseif l:line =~ '^[])}]' + let id = stridx('])}',l:line[0]) + let num = s:GetPair(escape('[({'[id],'['), escape('])}'[id],']'),'bW','s:skip_func(s:looksyn)',2000) + elseif syns != '' && getline(v:lnum)[0] =~ '\s' let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : \ syns =~? 'jsbracket'? ['\[','\]'] : ['[({[]','[])}]'] let num = s:GetPair(pattern[0],pattern[1],'bW','s:skip_func(s:looksyn)',2000) @@ -200,7 +205,6 @@ function GetJavascriptIndent() let num = (num > 0) * num let b:js_cache = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] - let l:line = substitute(l:line,s:line_pre,'','') if l:line =~ '^[])}]' return !!num * indent(num) endif From 92f1d98dbe740bdbb26b9595dab32b16320c641a Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 25 Sep 2016 20:09:43 -0700 Subject: [PATCH 20/42] switch accuracy and performance (#647) --- indent/javascript.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index c6d5e110..e89e493d 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*:\C' +let s:expr_case = '\<\%(\%(case\>.\+\)\|default\)\s*:\C' " Regex of syntax group names that are or delimit string or are comments. let s:syng_strcom = '\%(s\%(tring\|pecial\)\|comment\|regex\|doc\|template\)' @@ -170,7 +170,9 @@ function GetJavascriptIndent() return 0 endif - if l:line =~# s:expr_case + let l:line = substitute(l:line,s:line_pre,'','') + + if l:line =~# '^' . s:expr_case let cpo_switch = &cpo set cpo+=% let ind = cindent(v:lnum) @@ -178,8 +180,6 @@ function GetJavascriptIndent() return ind endif - let l:line = substitute(l:line,s:line_pre,'','') - " 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) From 6ecbda3b318f1e7178a4a59f4702af1fa9ce05e4 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Mon, 26 Sep 2016 18:46:05 -0700 Subject: [PATCH 21/42] clean isBlock (#648) --- indent/javascript.vim | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index e89e493d..f38b7183 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -109,9 +109,10 @@ 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\%(\\|\*\@') !~# + \ '\<\%(var\|const\|let\|import\|export\|yield\|de\%(fault\|lete\)\|void\|t\%(ypeof\|hrow\)\|new\|in\%(stanceof\)\=\)\>' + \ : !search('\C\%([-=~!<*+,./?^%|&\[(]\|=\@\)\_s*\%#','nbW') && + \ (search(s:expr_case . '\_s*\%#','nbW') || !search('[{:]\_s*\%#','bW') || s:IsBlock())) endfunction " Find line above 'lnum' that isn't empty, in a comment, or in a string. From d6b2fd599fd7e03952e854acfc1c4cee0c0b1da3 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Mon, 26 Sep 2016 19:20:31 -0700 Subject: [PATCH 22/42] change regex case --- indent/javascript.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index f38b7183..d3e17d10 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -2,7 +2,7 @@ " Language: Javascript " Maintainer: Chris Paul ( https://github.com/bounceme ) " URL: https://github.com/pangloss/vim-javascript -" Last Change: September 23, 2016 +" Last Change: September 26, 2016 " Only load this indent file when no other was loaded. if exists('b:did_indent') @@ -109,9 +109,9 @@ endfunction " https://github.com/sweet-js/sweet.js/wiki/design#give-lookbehind-to-the-reader function s:IsBlock() - return getline(line('.'))[col('.')-1] == '{' && !search('\') !~# + return getline(line('.'))[col('.')-1] == '{' && !search('\C\') !~# \ '\<\%(var\|const\|let\|import\|export\|yield\|de\%(fault\|lete\)\|void\|t\%(ypeof\|hrow\)\|new\|in\%(stanceof\)\=\)\>' - \ : !search('\C\%([-=~!<*+,./?^%|&\[(]\|=\@\)\_s*\%#','nbW') && + \ : !search('\%([-=~!<*+,./?^%|&\[(]\|=\@\)\_s*\%#','nbW') && \ (search(s:expr_case . '\_s*\%#','nbW') || !search('[{:]\_s*\%#','bW') || s:IsBlock())) endfunction From 77c4ae620420a3e9f88667b7df334ebdde2485ea Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Tue, 27 Sep 2016 16:28:14 -0700 Subject: [PATCH 23/42] better line cleaning (#649) --- indent/javascript.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index d3e17d10..b8679f68 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -75,7 +75,7 @@ if !exists('g:javascript_continuation') endif let g:javascript_opfirst = '^' . g:javascript_opfirst -let g:javascript_continuation .= s:line_term +let g:javascript_continuation .= '$' function s:OneScope(lnum,text) return cursor(a:lnum, match(' ' . a:text, '\%(\\)' . s:line_term)) > -1 || @@ -215,7 +215,7 @@ function GetJavascriptIndent() endif let s:W = s:sw() - let pline = substitute(substitute(getline(l:lnum),s:expr_case,'\=repeat(" ",strlen(submatch(0)))',''), ':\@ 0 && search('\C\ Date: Tue, 27 Sep 2016 17:20:38 -0700 Subject: [PATCH 24/42] more regex line endings --- indent/javascript.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index b8679f68..cc084535 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -78,8 +78,8 @@ let g:javascript_opfirst = '^' . g:javascript_opfirst let g:javascript_continuation .= '$' function s:OneScope(lnum,text) - return cursor(a:lnum, match(' ' . a:text, '\%(\\)' . s:line_term)) > -1 || - \ cursor(a:lnum, match(' ' . a:text, ')' . s:line_term)) > -1 && + return cursor(a:lnum, match(' ' . a:text, '\%(\\)' . '$')) > -1 || + \ cursor(a:lnum, match(' ' . a:text, ')' . '$')) > -1 && \ s:GetPair('(', ')', 'bW', s:skip_expr, 100) > 0 && \ search('\C\<\%(for\%(\_s\+each\)\=\|if\|let\|w\%(hile\|ith\)\)\_s*\%#','bW') endfunction @@ -91,7 +91,7 @@ function s:iscontOne(i,num,cont) let bL = 0 while l:i >= l:num && (!l:cont || ind > pind + s:W) if indent(l:i) < ind " first line always true for !cont, false for !!cont - if s:OneScope(l:i,substitute(getline(l:i),':\@') ==# 'while' && s:GetPair(s:line_pre . '\C\','\C\','bW',s:skip_expr,100,l:num) > 0 return 0 endif From 88111be6a7c50c63b36e3dbe8c110df0951ec473 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Tue, 27 Sep 2016 17:30:28 -0700 Subject: [PATCH 25/42] factor out --- indent/javascript.vim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index cc084535..e9373299 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -66,6 +66,10 @@ endif let s:line_term = '\s*\%(\%(\/\%(\%(\*.\{-}\*\/\)\|\%(\*\+\)\)\)\s*\)\=$' +function s:Trimline(ln) + return substitute(substitute(getline(a:ln),':\@,?^%|*&]\|\/[^/*]\|\([-.:+]\)\1\@!\|=>\@!\|in\%(stanceof\)\=\>\)' @@ -91,7 +95,7 @@ function s:iscontOne(i,num,cont) let bL = 0 while l:i >= l:num && (!l:cont || ind > pind + s:W) if indent(l:i) < ind " first line always true for !cont, false for !!cont - if s:OneScope(l:i,substitute(substitute(getline(l:i),':\@') ==# 'while' && s:GetPair(s:line_pre . '\C\','\C\','bW',s:skip_expr,100,l:num) > 0 return 0 endif @@ -215,7 +219,7 @@ function GetJavascriptIndent() endif let s:W = s:sw() - let pline = substitute(substitute(getline(l:lnum),':\@ 0 && search('\C\ Date: Tue, 27 Sep 2016 19:29:41 -0700 Subject: [PATCH 26/42] small regex changes --- indent/javascript.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index e9373299..acecc6c6 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -82,8 +82,8 @@ let g:javascript_opfirst = '^' . g:javascript_opfirst let g:javascript_continuation .= '$' function s:OneScope(lnum,text) - return cursor(a:lnum, match(' ' . a:text, '\%(\\)' . '$')) > -1 || - \ cursor(a:lnum, match(' ' . a:text, ')' . '$')) > -1 && + return cursor(a:lnum, match(' ' . a:text, '\%(\\)$')) > -1 || + \ cursor(a:lnum, match(' ' . a:text, ')$')) > -1 && \ s:GetPair('(', ')', 'bW', s:skip_expr, 100) > 0 && \ search('\C\<\%(for\%(\_s\+each\)\=\|if\|let\|w\%(hile\|ith\)\)\_s*\%#','bW') endfunction @@ -114,7 +114,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\') !~# - \ '\<\%(var\|const\|let\|import\|export\|yield\|de\%(fault\|lete\)\|void\|t\%(ypeof\|hrow\)\|new\|in\%(stanceof\)\=\)\>' + \ '\<\%(var\|const\|let\|\%(im\|ex\)port\|yield\|de\%(fault\|lete\)\|void\|t\%(ypeof\|hrow\)\|new\|in\%(stanceof\)\=\)\>' \ : !search('\%([-=~!<*+,./?^%|&\[(]\|=\@\)\_s*\%#','nbW') && \ (search(s:expr_case . '\_s*\%#','nbW') || !search('[{:]\_s*\%#','bW') || s:IsBlock())) endfunction From 833d6ec12724633c323d5d1dab0a4a8fc2e25393 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Tue, 27 Sep 2016 21:42:04 -0700 Subject: [PATCH 27/42] short circuit cache check --- indent/javascript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index acecc6c6..60f89efa 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -208,11 +208,11 @@ function GetJavascriptIndent() endif let num = (num > 0) * num - let b:js_cache = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] - if l:line =~ '^[])}]' return !!num * indent(num) endif + let b:js_cache = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] + call cursor(v:lnum,1) if l:line =~# '^while\>' && s:GetPair(s:line_pre . '\C\','\C\','bW',s:skip_expr,100,num) > 0 return indent(line('.')) From c76d65bd50907fe76a0008371792b821408c1bff Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Tue, 27 Sep 2016 22:41:07 -0700 Subject: [PATCH 28/42] fail earlier --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 60f89efa..8da6c6a1 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -190,7 +190,7 @@ function GetJavascriptIndent() call cursor(v:lnum,1) if getline(l:lnum) !~ '^\S' let [s:looksyn,s:free] = [v:lnum - 1,1] - if b:js_cache[0] < v:lnum && b:js_cache[0] >= l:lnum && + if b:js_cache[0] >= l:lnum && b:js_cache[0] < v:lnum && \ (b:js_cache[0] > l:lnum || s:Balanced(l:lnum)) let num = b:js_cache[1] elseif l:line =~ '^[])}]' From cd4ace412688995e6c6eddc95c3ee3ed5b7dd495 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Wed, 28 Sep 2016 08:10:30 -0700 Subject: [PATCH 29/42] wrap for magic (#651) --- indent/javascript.vim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/indent/javascript.vim b/indent/javascript.vim index 8da6c6a1..7bbee713 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -153,6 +153,9 @@ function s:Balanced(lnum) endfunction function GetJavascriptIndent() + try + let save_magic = &magic + set magic if !exists('b:js_cache') let b:js_cache = [0,0,0] endif @@ -236,6 +239,9 @@ function GetJavascriptIndent() return indent(num) + s:W + switch_offset + bL endif return bL + finally + let &magic = save_magic + endtry endfunction From 572b98d12b97b126a739bac539f4ba4be3365578 Mon Sep 17 00:00:00 2001 From: Amadeus Demarzi Date: Wed, 28 Sep 2016 11:11:41 -0700 Subject: [PATCH 30/42] Fixing another funky comment situation --- syntax/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index 20b131b2..b4ce555b 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -171,7 +171,7 @@ syntax match jsArrowFuncArgs /\k\+\s*\%(=>\)\@=/ skipwhite contains=jsFuncArg syntax match jsArrowFuncArgs /([^()]*)\s*\(=>\)\@=/ contains=jsFuncArgs skipempty skipwhite nextgroup=jsArrowFunction extend exe 'syntax match jsFunction /\/ skipwhite skipempty nextgroup=jsGenerator,jsFuncName,jsFuncArgs skipwhite '.(exists('g:javascript_conceal_function') ? 'conceal cchar='.g:javascript_conceal_function : '') -exe 'syntax match jsArrowFunction /=>/ skipwhite skipempty nextgroup=jsFuncBlock contains=jsFuncBraces '.(exists('g:javascript_conceal_arrow_function') ? 'conceal cchar='.g:javascript_conceal_arrow_function : '') +exe 'syntax match jsArrowFunction /=>/ skipwhite skipempty nextgroup=jsFuncBlock,jsCommentFunction '.(exists('g:javascript_conceal_arrow_function') ? 'conceal cchar='.g:javascript_conceal_arrow_function : '') " Classes syntax keyword jsClassKeywords contained extends class From ecc674fc517e1286b023e2dad1112f37b0fcfb99 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Fri, 30 Sep 2016 21:59:19 -0700 Subject: [PATCH 31/42] flow generic classes (#652) --- indent/javascript.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 7bbee713..e64b454e 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -115,8 +115,9 @@ endfunction function s:IsBlock() return getline(line('.'))[col('.')-1] == '{' && !search('\C\') !~# \ '\<\%(var\|const\|let\|\%(im\|ex\)port\|yield\|de\%(fault\|lete\)\|void\|t\%(ypeof\|hrow\)\|new\|in\%(stanceof\)\=\)\>' - \ : !search('\%([-=~!<*+,./?^%|&\[(]\|=\@\)\_s*\%#','nbW') && - \ (search(s:expr_case . '\_s*\%#','nbW') || !search('[{:]\_s*\%#','bW') || s:IsBlock())) + \ : !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())) endfunction " Find line above 'lnum' that isn't empty, in a comment, or in a string. From b0d7c153a83f796465aeba6fc430be6e0c39a9f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Zugmeyer?= Date: Sun, 2 Oct 2016 16:41:22 +0200 Subject: [PATCH 32/42] add support for "for await" (asynchronous iteration) --- syntax/javascript.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index b4ce555b..74b619b1 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -101,7 +101,7 @@ syntax keyword jsStatement contained break continue with yield debugger syntax keyword jsConditional if skipwhite skipempty nextgroup=jsParenIfElse syntax keyword jsConditional else skipwhite skipempty nextgroup=jsCommentMisc,jsIfElseBlock syntax keyword jsConditional switch skipwhite skipempty nextgroup=jsParenSwitch -syntax keyword jsRepeat while for skipwhite skipempty nextgroup=jsParenRepeat +syntax keyword jsRepeat while for skipwhite skipempty nextgroup=jsParenRepeat,jsForAwait syntax keyword jsDo do skipwhite skipempty nextgroup=jsRepeatBlock syntax keyword jsLabel contained case default syntax keyword jsTry try skipwhite skipempty nextgroup=jsTryCatchBlock @@ -164,6 +164,7 @@ syntax match jsFuncName contained /\<[a-zA-Z_$][0-9a-zA-Z_$]*\>/ s syntax region jsFuncArgExpression contained matchgroup=jsFuncArgOperator start=/=/ end=/[,)]\@=/ contains=@jsExpression extend syntax match jsFuncArgCommas contained ',' syntax keyword jsArguments contained arguments +syntax keyword jsForAwait contained await skipwhite skipempty nextgroup=jsParenRepeat " Matches a single keyword argument with no parens syntax match jsArrowFuncArgs /\k\+\s*\%(=>\)\@=/ skipwhite contains=jsFuncArgs skipwhite skipempty nextgroup=jsArrowFunction extend @@ -275,6 +276,7 @@ if version >= 508 || !exists("did_javascript_syn_inits") HiLink jsFinally Exception HiLink jsCatch Exception HiLink jsAsyncKeyword Keyword + HiLink jsForAwait Keyword HiLink jsArrowFunction Type HiLink jsFunction Type HiLink jsGenerator jsFunction From f64dae7106df808f4654c5f88ea019d274197b0e Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Mon, 3 Oct 2016 13:57:35 -0700 Subject: [PATCH 33/42] for await indent (#656) #654 --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index e64b454e..984e8957 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -85,7 +85,7 @@ function s:OneScope(lnum,text) return cursor(a:lnum, match(' ' . a:text, '\%(\\)$')) > -1 || \ cursor(a:lnum, match(' ' . a:text, ')$')) > -1 && \ s:GetPair('(', ')', 'bW', s:skip_expr, 100) > 0 && - \ search('\C\<\%(for\%(\_s\+each\)\=\|if\|let\|w\%(hile\|ith\)\)\_s*\%#','bW') + \ search('\C\<\%(for\%(\_s\+\%(await\|each\)\)\=\|if\|let\|w\%(hile\|ith\)\)\_s*\%#','bW') endfunction function s:iscontOne(i,num,cont) From f674cbab548f1f8a05c1654f441b13fefc282d80 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Tue, 4 Oct 2016 21:04:00 -0700 Subject: [PATCH 34/42] case label needs non whitespace- (#658) can otherwise be a object key --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 984e8957..1f1786c3 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 = '\<\%(\%(case\>.\+\)\|default\)\s*:\C' +let s:expr_case = '\<\%(\%(case\>\s*\S.\{-}\)\|default\)\s*:\C' " Regex of syntax group names that are or delimit string or are comments. let s:syng_strcom = '\%(s\%(tring\|pecial\)\|comment\|regex\|doc\|template\)' From ba2245fbe7384a4dc9de6f0d1c120dad977d0406 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Thu, 6 Oct 2016 21:17:20 -0700 Subject: [PATCH 35/42] Misc improvements (#661) --- indent/javascript.vim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 1f1786c3..e5c57496 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -72,7 +72,7 @@ endfunction " 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 = '\%([<=,.?/*^%|&:]\|+\@\|\= l:num && (!l:cont || ind > pind + s:W) - if indent(l:i) < ind " first line always true for !cont, false for !!cont + if indent(l:i) < ind " first line always true for !a:cont, false for !!a:cont if s:OneScope(l:i,s:Trimline(l:i)) - if expand('') ==# 'while' && s:GetPair(s:line_pre . '\C\','\C\','bW',s:skip_expr,100,l:num) > 0 + if expand('') ==# 'while' && s:GetPair(s:line_pre . '\C\','\C\','bW',s:skip_expr,100,l:num + !!a:num) > 0 return 0 endif let bL += 1 @@ -155,8 +155,8 @@ endfunction function GetJavascriptIndent() try - let save_magic = &magic - set magic + let save_magic = &magic + set magic if !exists('b:js_cache') let b:js_cache = [0,0,0] endif @@ -218,7 +218,7 @@ function GetJavascriptIndent() let b:js_cache = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] call cursor(v:lnum,1) - if l:line =~# '^while\>' && s:GetPair(s:line_pre . '\C\','\C\','bW',s:skip_expr,100,num) > 0 + if l:line =~# '^while\>' && s:GetPair(s:line_pre . '\C\','\C\','bW',s:skip_expr,100,num + 1) > 0 return indent(line('.')) endif From 8d904f65f575e5d081ae740d19a2409b69118576 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sat, 8 Oct 2016 12:28:01 -0700 Subject: [PATCH 36/42] improve end of line trim (#662) * improve end of line trim * Date --- indent/javascript.vim | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index e5c57496..a6eefba0 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -2,7 +2,7 @@ " Language: Javascript " Maintainer: Chris Paul ( https://github.com/bounceme ) " URL: https://github.com/pangloss/vim-javascript -" Last Change: September 26, 2016 +" Last Change: October 8, 2016 " Only load this indent file when no other was loaded. if exists('b:did_indent') @@ -38,6 +38,8 @@ else endif let s:line_pre = '^\s*\%(\%(\%(\/\*.\{-}\)\=\*\+\/\s*\)\=\)\@>' +let s:line_term = '\s*\%(\%(\/\%(\%(\*.\{-}\*\/\)\|\%(\*\+\)\)\)\s*\)\=$' + let s:expr_case = '\<\%(\%(case\>\s*\S.\{-}\)\|default\)\s*:\C' " Regex of syntax group names that are or delimit string or are comments. let s:syng_strcom = '\%(s\%(tring\|pecial\)\|comment\|regex\|doc\|template\)' @@ -64,10 +66,23 @@ else endfunction endif -let s:line_term = '\s*\%(\%(\/\%(\%(\*.\{-}\*\/\)\|\%(\*\+\)\)\)\s*\)\=$' - +" indent/python.vim function s:Trimline(ln) - return substitute(substitute(getline(a:ln),':\@ Date: Sun, 9 Oct 2016 18:31:13 -0700 Subject: [PATCH 37/42] skip comment (#665) * skip comment https://github.com/pangloss/vim-javascript/issues/664#issuecomment-252492671 --- indent/javascript.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index a6eefba0..0a527b2e 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -128,7 +128,9 @@ 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 getline(line('.'))[col('.')-1] == '{' && !search('\C\') !~# \ '\<\%(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' : From 214450913faa965be8579910bcd64390c3c59bcd Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 9 Oct 2016 19:58:54 -0700 Subject: [PATCH 38/42] shorten long line,date --- indent/javascript.vim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 0a527b2e..f883d241 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -2,7 +2,7 @@ " Language: Javascript " Maintainer: Chris Paul ( https://github.com/bounceme ) " URL: https://github.com/pangloss/vim-javascript -" Last Change: October 8, 2016 +" Last Change: October 9, 2016 " Only load this indent file when no other was loaded. if exists('b:did_indent') @@ -111,7 +111,9 @@ function s:iscontOne(i,num,cont) while l:i >= l:num && (!l:cont || ind > pind + s:W) if indent(l:i) < ind " first line always true for !a:cont, false for !!a:cont if s:OneScope(l:i,s:Trimline(l:i)) - if expand('') ==# 'while' && s:GetPair(s:line_pre . '\C\','\C\','bW',s:skip_expr,100,l:num + !!a:num) > 0 + if expand('') ==# 'while' && + \ s:GetPair(s:line_pre . '\C\','\C\','bW',s:skip_expr,100,l:num + !!a:num) > 0 + return 0 endif let bL += 1 From ba0ae275cb95f8c4b2363d923a5fa42cec6019fc Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 9 Oct 2016 19:59:38 -0700 Subject: [PATCH 39/42] remove random nl --- indent/javascript.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index f883d241..e6af48a8 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -113,7 +113,6 @@ function s:iscontOne(i,num,cont) if s:OneScope(l:i,s:Trimline(l:i)) if expand('') ==# 'while' && \ s:GetPair(s:line_pre . '\C\','\C\','bW',s:skip_expr,100,l:num + !!a:num) > 0 - return 0 endif let bL += 1 From da65c0cdd3cb8b0aa6c5676ef38c0ec6ac0e3744 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Mon, 10 Oct 2016 17:09:36 -0700 Subject: [PATCH 40/42] massive expression to if chain (#667) --- indent/javascript.vim | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index e6af48a8..4f0301da 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -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\') !~# - \ '\<\%(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\') !~# + \ '\<\%(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. From 7e9aeb30fe657bb15dc9653b9b15858235f957ab Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Tue, 11 Oct 2016 00:41:31 -0700 Subject: [PATCH 41/42] word boundary to start/end --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 4f0301da..9720c7f8 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -140,7 +140,7 @@ function s:IsBlock() let char = getline(line('.'))[col('.')-1] if char =~# '\l' return expand('') !~# - \ '\<\%(var\|const\|let\|\%(im\|ex\)port\|yield\|de\%(fault\|lete\)\|void\|t\%(ypeof\|hrow\)\|new\|in\%(stanceof\)\=\)\>' + \ '^\%(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 == ':' From 7d30463e18181302d1134899b635ef84a9c7d84a Mon Sep 17 00:00:00 2001 From: bounceme Date: Tue, 11 Oct 2016 11:57:46 -0700 Subject: [PATCH 42/42] Revert "Merge branch 'master' into develop" This reverts commit 822dfe5f919a938682b4a0ad386f9d2909627e17, reversing changes made to da65c0cdd3cb8b0aa6c5676ef38c0ec6ac0e3744. --- syntax/javascript.vim | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index 4a37bb7f..74b619b1 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -84,7 +84,7 @@ syntax match jsObjectSeparator contained /,/ syntax region jsObjectValue contained start=/:/ end=/\%(,\|}\)\@=/ contains=jsObjectColon,@jsExpression extend syntax match jsObjectFuncName contained /\<[a-zA-Z_$][0-9a-zA-Z_$]*\>[\r\n\t ]*(\@=/ skipwhite skipempty nextgroup=jsFuncArgs syntax match jsFunctionKey contained /\<[a-zA-Z_$][0-9a-zA-Z_$]*\>\(\s*:\s*function\s*\)\@=/ -syntax match jsObjectMethodType contained /\%(get\|set\|static\|async\)\%( \k\+\)\@=/ contains=jsAsyncKeyword skipwhite skipempty nextgroup=jsObjectFuncName +syntax match jsObjectMethodType contained /\%(get\|set\|static\|async\)\%( \k\+\)\@=/ skipwhite skipempty nextgroup=jsObjectFuncName syntax region jsObjectStringKey contained start=+"+ skip=+\\\("\|$\)+ end=+"\|$+ contains=jsSpecial,@Spell extend skipwhite skipempty nextgroup=jsFuncArgs,jsObjectValue syntax region jsObjectStringKey contained start=+'+ skip=+\\\('\|$\)+ end=+'\|$+ contains=jsSpecial,@Spell extend skipwhite skipempty nextgroup=jsFuncArgs,jsObjectValue @@ -108,8 +108,7 @@ syntax keyword jsTry try skipwhite skipempty nextgro syntax keyword jsFinally contained finally skipwhite skipempty nextgroup=jsFinallyBlock syntax keyword jsCatch contained catch skipwhite skipempty nextgroup=jsParenCatch syntax keyword jsException throw -syntax keyword jsAsyncKeyword async skipwhite skipempty nextgroup=jsFunction,jsFuncName -syntax keyword jsAwaitKeyword await +syntax keyword jsAsyncKeyword async await syntax match jsSwitchColon contained /:/ skipwhite skipempty nextgroup=jsSwitchBlock " Keywords @@ -178,7 +177,7 @@ exe 'syntax match jsArrowFunction /=>/ skipwhite skipempty nextgroup=jsFunc " Classes syntax keyword jsClassKeywords contained extends class syntax match jsClassNoise contained /\./ -syntax match jsClassMethodType contained /\%(get\|set\|static\|async\)\%( \k\+\)\@=/ contains=jsAsyncKeyword skipwhite skipempty nextgroup=jsFuncName,jsClassProperty +syntax match jsClassMethodType contained /\%(get\|set\|static\|async\)\%( \k\+\)\@=/ skipwhite skipempty nextgroup=jsFuncName,jsClassProperty syntax match jsClassDefinition /\\%( [a-zA-Z_$][0-9a-zA-Z_$ \n.]*\)*/ contains=jsClassKeywords,jsClassNoise skipwhite skipempty nextgroup=jsCommentClass,jsClassBlock,jsFlowClassGroup syntax match jsClassProperty contained /\<[0-9a-zA-Z_$]*\>\(\s*=\)\@=/ skipwhite skipempty nextgroup=jsClassValue syntax region jsClassValue contained start=/=/ end=/\%(;\|}\|\n\)\@=/ contains=@jsExpression @@ -228,8 +227,8 @@ if exists("javascript_plugin_flow") runtime extras/flow.vim endif -syntax cluster jsExpression contains=jsBracket,jsParen,jsObject,jsBlock,jsTernaryIf,jsTaggedTemplate,jsTemplateString,jsString,jsRegexpString,jsNumber,jsFloat,jsOperator,jsBooleanTrue,jsBooleanFalse,jsNull,jsFunction,jsArrowFunction,jsGlobalObjects,jsExceptions,jsFutureKeys,jsDomErrNo,jsDomNodeConsts,jsHtmlEvents,jsFuncCall,jsUndefined,jsNan,jsPrototype,jsBuiltins,jsNoise,jsClassDefinition,jsArrowFunction,jsArrowFuncArgs,jsParensError,jsComment,jsArguments,jsThis,jsSuper,jsDo,jsAsyncKeyword,jsAwaitKeyword -syntax cluster jsAll contains=@jsExpression,jsExportContainer,jsImportContainer,jsStorageClass,jsConditional,jsRepeat,jsReturn,jsStatement,jsException,jsTry +syntax cluster jsExpression contains=jsBracket,jsParen,jsObject,jsBlock,jsTernaryIf,jsTaggedTemplate,jsTemplateString,jsString,jsRegexpString,jsNumber,jsFloat,jsOperator,jsBooleanTrue,jsBooleanFalse,jsNull,jsFunction,jsArrowFunction,jsGlobalObjects,jsExceptions,jsFutureKeys,jsDomErrNo,jsDomNodeConsts,jsHtmlEvents,jsFuncCall,jsUndefined,jsNan,jsPrototype,jsBuiltins,jsNoise,jsClassDefinition,jsArrowFunction,jsArrowFuncArgs,jsParensError,jsComment,jsArguments,jsThis,jsSuper,jsDo +syntax cluster jsAll contains=@jsExpression,jsExportContainer,jsImportContainer,jsStorageClass,jsConditional,jsRepeat,jsReturn,jsStatement,jsException,jsTry,jsAsyncKeyword " Define the default highlighting. " For version 5.7 and earlier: only when not done already @@ -277,7 +276,7 @@ if version >= 508 || !exists("did_javascript_syn_inits") HiLink jsFinally Exception HiLink jsCatch Exception HiLink jsAsyncKeyword Keyword - HiLink jsAwaitKeyword Keyword + HiLink jsForAwait Keyword HiLink jsArrowFunction Type HiLink jsFunction Type HiLink jsGenerator jsFunction