From faf8bda63459b9205c7973117dc6ca426172a2c3 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sun, 21 Aug 2016 15:03:06 -0700 Subject: [PATCH 01/57] containing braces which aren't blocks --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 51881d16..55065c6a 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -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: Mon, 22 Aug 2016 11:38:07 -0700 Subject: [PATCH 02/57] comment fix for multiline comments which were being considered operator first lines in some cases. may be getting some bug reports for this on master --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 55065c6a..e1601515 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -62,7 +62,7 @@ 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: Mon, 22 Aug 2016 12:11:57 -0700 Subject: [PATCH 03/57] improve regex --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index e1601515..b0588e13 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -62,7 +62,7 @@ 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: Wed, 24 Aug 2016 16:21:45 -0700 Subject: [PATCH 04/57] Fix export default style indents --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index b0588e13..dccf1b8d 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -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: Wed, 24 Aug 2016 21:42:34 -0700 Subject: [PATCH 05/57] regex update --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index dccf1b8d..af8e5d1c 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -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: Thu, 25 Aug 2016 00:21:44 -0700 Subject: [PATCH 06/57] allow nl in export default --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index af8e5d1c..524cada2 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -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, 26 Aug 2016 19:56:52 -0700 Subject: [PATCH 07/57] small bugfixes --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 524cada2..c9a89556 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -77,7 +77,7 @@ function s:OneScope(lnum,text,add) \ cursor(a:lnum, match(a:text, ')' . s:line_term)) > -1) && \ 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\') : '' + \ (expand('') !=# 'each' || search('\C\') : '' endfunction " https://github.com/sweet-js/sweet.js/wiki/design#give-lookbehind-to-the-reader From 51035b51a04d52156401baac5e8af6dc8b889a09 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Wed, 31 Aug 2016 19:30:32 -0700 Subject: [PATCH 08/57] react property expressions fixes #618 elegantly (hopefully) --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index c9a89556..694403af 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -84,7 +84,7 @@ endfunction function s:IsBlock() return getline(line('.'))[col('.')-1] == '{' && !search( \ '\C\%(\\|\*\@ Date: Fri, 2 Sep 2016 15:10:06 -0700 Subject: [PATCH 09/57] adjustable indent (experimental) https://github.com/mxw/vim-jsx/issues/116#issuecomment-244400990 thanks to @mxw for the suggestion --- indent/javascript.vim | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 694403af..c13f4f59 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -122,7 +122,7 @@ endfunction function GetJavascriptIndent() if !exists('b:js_cache') - let b:js_cache = [0,0,0] + let b:js_cache = [0,0,0,0] endif " Get the current line. let l:line = getline(v:lnum) @@ -152,9 +152,11 @@ 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 known = 0 call cursor(v:lnum,1) 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 known = 1 let num = b:js_cache[1] elseif syns != '' && l:line[0] =~ '\s' let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : @@ -163,7 +165,11 @@ function GetJavascriptIndent() else let num = s:GetPair('[({[]','[])}]','bW',2000) endif - let b:js_cache = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] + + if known && b:js_cache[3] + let known = indent(b:js_cache[0]) - b:js_cache[3] + endif + let b:js_cache[:3] = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] if l:line =~ s:line_pre . '[])}]' return indent(num) @@ -182,9 +188,13 @@ function GetJavascriptIndent() 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 + let ind = (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset + let b:js_cache[3] = ind + return ind + known elseif num > 0 - return indent(num) + s:sw() + switch_offset + let ind = indent(num) + s:sw() + switch_offset + let b:js_cache[3] = ind + return ind + known endif endfunction From d6616d5fd6f87633856d96abbbd7931f3a3db468 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Fri, 2 Sep 2016 15:28:28 -0700 Subject: [PATCH 10/57] Update javascript.vim --- indent/javascript.vim | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index c13f4f59..7190dc38 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -169,7 +169,7 @@ function GetJavascriptIndent() if known && b:js_cache[3] let known = indent(b:js_cache[0]) - b:js_cache[3] endif - let b:js_cache[:3] = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] + let b:js_cache[:2] = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] if l:line =~ s:line_pre . '[])}]' return indent(num) @@ -177,15 +177,14 @@ function GetJavascriptIndent() call cursor(b:js_cache[1],b:js_cache[2]) - let swcase = getline(l:lnum) =~# s:expr_case - let pline = swcase ? getline(l:lnum) : substitute(getline(l:lnum), '\%(:\@' && \ l:line !~ s:line_pre . '{') let ind = (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset From 0bba857641759969cca990c815ec7a830fcbee60 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Fri, 2 Sep 2016 19:38:52 -0700 Subject: [PATCH 11/57] bugfixes --- indent/javascript.vim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 7190dc38..ec08fb62 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -156,7 +156,9 @@ function GetJavascriptIndent() call cursor(v:lnum,1) 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 known = 1 + if b:js_cache[1] == num + let known = 1 + end let num = b:js_cache[1] elseif syns != '' && l:line[0] =~ '\s' let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : @@ -184,7 +186,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 || pline =~# g:javascript_continuation) || + if inb && ((l:line =~# g:javascript_opfirst || pline !~# s:expr_case . s:line_term && 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 . '{') let ind = (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset From f8a4a45f3d52bf42a28868c3f1b2d727522d7d8e Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Fri, 2 Sep 2016 19:50:44 -0700 Subject: [PATCH 12/57] fixes for the bugfixes --- indent/javascript.vim | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index ec08fb62..5cba356a 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -112,6 +112,9 @@ function s:Balanced(lnum) let open_{idx} = open_{idx} + 1 else let open_{idx - 1} = open_{idx - 1} - 1 + if open_{idx - 1} < 0 + return 0 + end endif endif let pos = match(l:line, '[][(){}]', pos + 1) @@ -150,15 +153,13 @@ function GetJavascriptIndent() endif "}}} + let known = 0 " 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 known = 0 call cursor(v:lnum,1) 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) - if b:js_cache[1] == num - let known = 1 - end + let known = 1 let num = b:js_cache[1] elseif syns != '' && l:line[0] =~ '\s' let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : @@ -171,6 +172,7 @@ function GetJavascriptIndent() if known && b:js_cache[3] let known = indent(b:js_cache[0]) - b:js_cache[3] endif + let b:js_cache[:2] = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] if l:line =~ s:line_pre . '[])}]' From 174d94e6f097851d495ba5cf0f8f537a9bcade62 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sat, 3 Sep 2016 00:04:25 -0700 Subject: [PATCH 13/57] produce cindent-like --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 5cba356a..100f8b9e 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -182,7 +182,7 @@ function GetJavascriptIndent() call cursor(b:js_cache[1],b:js_cache[2]) let pline = getline(l:lnum) =~# s:expr_case ? getline(l:lnum) : substitute(getline(l:lnum), '\%(:\@ Date: Sat, 3 Sep 2016 12:18:56 -0700 Subject: [PATCH 14/57] performance refactor --- indent/javascript.vim | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 100f8b9e..f3c37eca 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -179,25 +179,21 @@ function GetJavascriptIndent() return indent(num) endif - call cursor(b:js_cache[1],b:js_cache[2]) let pline = getline(l:lnum) =~# s:expr_case ? getline(l:lnum) : substitute(getline(l:lnum), '\%(:\@' && - \ l:line !~ s:line_pre . '{') - let ind = (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset - let b:js_cache[3] = ind - return ind + known + if ((l:line =~# g:javascript_opfirst || pline !~# s:expr_case . s:line_term && pline =~# g:javascript_continuation) || + \ s:OneScope(l:lnum,pline,0) =~# '\<\%(for\|each\|if\|let\|no\sb\|w\%(hile\|ith\)\)\>' && + \ l:line !~ s:line_pre . '{') && cursor(b:js_cache[1],b:js_cache[2]) + 2 && (num == 0 || s:IsBlock()) + let b:js_cache[3] = (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset + return b:js_cache[3] + known elseif num > 0 - let ind = indent(num) + s:sw() + switch_offset - let b:js_cache[3] = ind - return ind + known + let b:js_cache[3] = indent(num) + s:sw() + switch_offset + return b:js_cache[3] + known endif endfunction From 0a3bb524283eb4777cbd86322f03b5a2ee266e91 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sat, 3 Sep 2016 13:07:30 -0700 Subject: [PATCH 15/57] 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 f3c37eca..b5231e44 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -188,7 +188,7 @@ function GetJavascriptIndent() " most significant, find the indent amount if ((l:line =~# g:javascript_opfirst || pline !~# s:expr_case . s:line_term && pline =~# g:javascript_continuation) || \ s:OneScope(l:lnum,pline,0) =~# '\<\%(for\|each\|if\|let\|no\sb\|w\%(hile\|ith\)\)\>' && - \ l:line !~ s:line_pre . '{') && cursor(b:js_cache[1],b:js_cache[2]) + 2 && (num == 0 || s:IsBlock()) + \ l:line !~ s:line_pre . '{') && (num == 0 || cursor(b:js_cache[1],b:js_cache[2]) || s:IsBlock()) let b:js_cache[3] = (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset return b:js_cache[3] + known elseif num > 0 From cc9bd56e8f857fbc7a4e59c73dbeec7481182b51 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sat, 3 Sep 2016 13:29:16 -0700 Subject: [PATCH 16/57] Update javascript.vim --- indent/javascript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index b5231e44..07800524 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -62,10 +62,10 @@ 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: Sat, 3 Sep 2016 16:43:43 -0700 Subject: [PATCH 17/57] deprecate options --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 662a2006..d2a81dd5 100644 --- a/README.md +++ b/README.md @@ -100,8 +100,8 @@ variables: ## 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 ) +* End-of-line continuations : `g:javascript_continuation` ( deprecated ) +* Start-of-line continuations : `g:javascript_opfirst` ( deprecated ) ## Contributing From 8711b66df9014f6032f8f77a0b825ce669aa181c Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sat, 3 Sep 2016 17:16:28 -0700 Subject: [PATCH 18/57] remove variables from readme --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index d2a81dd5..1cd79f4c 100644 --- a/README.md +++ b/README.md @@ -100,8 +100,6 @@ variables: ## Indentation Specific * `:h cino-:` -* End-of-line continuations : `g:javascript_continuation` ( deprecated ) -* Start-of-line continuations : `g:javascript_opfirst` ( deprecated ) ## Contributing From bf74844aa2b3a79e9f86139363f267efd1a6fdb5 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sat, 3 Sep 2016 22:02:43 -0700 Subject: [PATCH 19/57] fix cached blank line problem --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 07800524..d74eed5b 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -170,7 +170,7 @@ function GetJavascriptIndent() endif if known && b:js_cache[3] - let known = indent(b:js_cache[0]) - b:js_cache[3] + let known = prevnonblank(b:js_cache[0]) == b:js_cache[0] ? indent(b:js_cache[0]) - b:js_cache[3] : 0 endif let b:js_cache[:2] = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] From 0586678395b756da7e554d62df872757fe3c1778 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sat, 3 Sep 2016 22:34:48 -0700 Subject: [PATCH 20/57] far better version of last commit --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index d74eed5b..6155c5cd 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -170,7 +170,7 @@ function GetJavascriptIndent() endif if known && b:js_cache[3] - let known = prevnonblank(b:js_cache[0]) == b:js_cache[0] ? indent(b:js_cache[0]) - b:js_cache[3] : 0 + let known = indent(lnum) - b:js_cache[3] endif let b:js_cache[:2] = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] From 22d0e64ee15c906685cab631309e83882d692e38 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 4 Sep 2016 00:04:33 -0700 Subject: [PATCH 21/57] more performance and bugfixes --- indent/javascript.vim | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 6155c5cd..ec6dda4e 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -154,12 +154,15 @@ function GetJavascriptIndent() "}}} let known = 0 + let pcounts = [0] " 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] && - \ (b:js_cache[0] > l:lnum || s:Balanced(l:lnum) > 0) - let known = 1 + if b:js_cache[0] && b:js_cache[0] < v:lnum && b:js_cache[0] >= l:lnum && + \ (b:js_cache[0] > l:lnum || map(pcounts,'s:Balanced(l:lnum)')[0] > 0) + if pcounts[0] > 0 + let known = 1 + end let num = b:js_cache[1] elseif syns != '' && l:line[0] =~ '\s' let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : @@ -170,12 +173,13 @@ function GetJavascriptIndent() endif if known && b:js_cache[3] - let known = indent(lnum) - b:js_cache[3] + let known = indent(l:lnum) - b:js_cache[3] endif let b:js_cache[:2] = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] if l:line =~ s:line_pre . '[])}]' + let b:js_cache[0] = 0 return indent(num) endif From 023e1d851e8eb4e94cb62a791660fd0b7ab59dd2 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 4 Sep 2016 00:20:37 -0700 Subject: [PATCH 22/57] other fixes with cache --- indent/javascript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index ec6dda4e..ba41a99a 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -159,10 +159,10 @@ function GetJavascriptIndent() " same scope or starts a new one, unless if it closed a scope. call cursor(v:lnum,1) if b:js_cache[0] && b:js_cache[0] < v:lnum && b:js_cache[0] >= l:lnum && - \ (b:js_cache[0] > l:lnum || map(pcounts,'s:Balanced(l:lnum)')[0] > 0) + \ (map(pcounts,'s:Balanced(l:lnum)')[0] > 0 || b:js_cache[0] > l:lnum) if pcounts[0] > 0 let known = 1 - end + endif let num = b:js_cache[1] elseif syns != '' && l:line[0] =~ '\s' let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : From 5f7e36a4a69723aee7824e051c8a4e2b166b180d Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 4 Sep 2016 00:34:57 -0700 Subject: [PATCH 23/57] formatting,date --- indent/javascript.vim | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index ba41a99a..71ba0dea 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 20, 2016 +" Last Change: September 4, 2016 " Only load this indent file when no other was loaded. if exists('b:did_indent') @@ -114,7 +114,7 @@ function s:Balanced(lnum) let open_{idx - 1} = open_{idx - 1} - 1 if open_{idx - 1} < 0 return 0 - end + endif endif endif let pos = match(l:line, '[][(){}]', pos + 1) @@ -160,9 +160,7 @@ function GetJavascriptIndent() call cursor(v:lnum,1) if b:js_cache[0] && b:js_cache[0] < v:lnum && b:js_cache[0] >= l:lnum && \ (map(pcounts,'s:Balanced(l:lnum)')[0] > 0 || b:js_cache[0] > l:lnum) - if pcounts[0] > 0 - let known = 1 - endif + let known = pcounts[0] > 0 let num = b:js_cache[1] elseif syns != '' && l:line[0] =~ '\s' let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : @@ -183,7 +181,6 @@ function GetJavascriptIndent() return indent(num) endif - let pline = getline(l:lnum) =~# s:expr_case ? getline(l:lnum) : substitute(getline(l:lnum), '\%(:\@ Date: Sun, 4 Sep 2016 09:47:48 -0700 Subject: [PATCH 24/57] small changes --- indent/javascript.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 71ba0dea..58b06c53 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -143,6 +143,7 @@ function GetJavascriptIndent() if l:lnum == 0 return 0 endif + let pline = getline(l:lnum) if (l:line =~# s:expr_case) let cpo_switch = &cpo @@ -158,7 +159,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] && 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] && pline !~ '}' \ (map(pcounts,'s:Balanced(l:lnum)')[0] > 0 || b:js_cache[0] > l:lnum) let known = pcounts[0] > 0 let num = b:js_cache[1] @@ -177,11 +178,10 @@ function GetJavascriptIndent() let b:js_cache[:2] = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] if l:line =~ s:line_pre . '[])}]' - let b:js_cache[0] = 0 return indent(num) endif - let pline = getline(l:lnum) =~# s:expr_case ? getline(l:lnum) : substitute(getline(l:lnum), '\%(:\@ Date: Sun, 4 Sep 2016 10:02:44 -0700 Subject: [PATCH 25/57] fix --- indent/javascript.vim | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 58b06c53..409a02f3 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -143,7 +143,6 @@ function GetJavascriptIndent() if l:lnum == 0 return 0 endif - let pline = getline(l:lnum) if (l:line =~# s:expr_case) let cpo_switch = &cpo @@ -159,8 +158,8 @@ 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] && pline !~ '}' - \ (map(pcounts,'s:Balanced(l:lnum)')[0] > 0 || b:js_cache[0] > l:lnum) + if b:js_cache[0] && b:js_cache[0] < v:lnum && b:js_cache[0] >= l:lnum && + \ (getline(l:lnum) !~ s:line_pre . '}' && map(pcounts,'s:Balanced(l:lnum)')[0] > 0 || b:js_cache[0] > l:lnum) let known = pcounts[0] > 0 let num = b:js_cache[1] elseif syns != '' && l:line[0] =~ '\s' @@ -181,7 +180,7 @@ function GetJavascriptIndent() return indent(num) endif - let pline = pline =~# s:expr_case ? pline : substitute(pline, '\%(:\@ Date: Sun, 4 Sep 2016 10:10:33 -0700 Subject: [PATCH 26/57] cleaning --- indent/javascript.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 409a02f3..fe4f6766 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -143,6 +143,7 @@ function GetJavascriptIndent() if l:lnum == 0 return 0 endif + let pline = getline(l:lnum) if (l:line =~# s:expr_case) let cpo_switch = &cpo @@ -159,7 +160,7 @@ function GetJavascriptIndent() " same scope or starts a new one, unless if it closed a scope. call cursor(v:lnum,1) if b:js_cache[0] && b:js_cache[0] < v:lnum && b:js_cache[0] >= l:lnum && - \ (getline(l:lnum) !~ s:line_pre . '}' && map(pcounts,'s:Balanced(l:lnum)')[0] > 0 || b:js_cache[0] > l:lnum) + \ (pline !~ s:line_pre . '}' && map(pcounts,'s:Balanced(l:lnum)')[0] > 0 || b:js_cache[0] > l:lnum) let known = pcounts[0] > 0 let num = b:js_cache[1] elseif syns != '' && l:line[0] =~ '\s' @@ -180,7 +181,7 @@ function GetJavascriptIndent() return indent(num) endif - let pline = getline(l:lnum) =~# s:expr_case ? getline(l:lnum) : substitute(getline(l:lnum), '\%(:\@ Date: Sun, 4 Sep 2016 10:47:56 -0700 Subject: [PATCH 27/57] cleaning --- indent/javascript.vim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index fe4f6766..abcb2f3d 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -143,7 +143,6 @@ function GetJavascriptIndent() if l:lnum == 0 return 0 endif - let pline = getline(l:lnum) if (l:line =~# s:expr_case) let cpo_switch = &cpo @@ -160,7 +159,7 @@ function GetJavascriptIndent() " same scope or starts a new one, unless if it closed a scope. call cursor(v:lnum,1) if b:js_cache[0] && b:js_cache[0] < v:lnum && b:js_cache[0] >= l:lnum && - \ (pline !~ s:line_pre . '}' && map(pcounts,'s:Balanced(l:lnum)')[0] > 0 || b:js_cache[0] > l:lnum) + \ (map(pcounts,'s:Balanced(l:lnum)')[0] > 0 || b:js_cache[0] > l:lnum) let known = pcounts[0] > 0 let num = b:js_cache[1] elseif syns != '' && l:line[0] =~ '\s' @@ -181,7 +180,7 @@ function GetJavascriptIndent() return indent(num) endif - let pline = pline =~# s:expr_case ? pline : substitute(pline, '\%(:\@ Date: Sun, 4 Sep 2016 13:15:48 -0700 Subject: [PATCH 28/57] small change --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index abcb2f3d..b603af8f 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -160,7 +160,7 @@ function GetJavascriptIndent() call cursor(v:lnum,1) if b:js_cache[0] && b:js_cache[0] < v:lnum && b:js_cache[0] >= l:lnum && \ (map(pcounts,'s:Balanced(l:lnum)')[0] > 0 || b:js_cache[0] > l:lnum) - let known = pcounts[0] > 0 + let known = l:lnum == b:js_cache[0] && pcounts[0] > 0 let num = b:js_cache[1] elseif syns != '' && l:line[0] =~ '\s' let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : From 46b6dd514bc8092225dcb43d3807b5ccab28a462 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 4 Sep 2016 13:24:07 -0700 Subject: [PATCH 29/57] allow blank line in adjustment calc --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index b603af8f..ebd218cd 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -160,7 +160,7 @@ function GetJavascriptIndent() call cursor(v:lnum,1) if b:js_cache[0] && b:js_cache[0] < v:lnum && b:js_cache[0] >= l:lnum && \ (map(pcounts,'s:Balanced(l:lnum)')[0] > 0 || b:js_cache[0] > l:lnum) - let known = l:lnum == b:js_cache[0] && pcounts[0] > 0 + let known = l:lnum == prevnonblank(b:js_cache[0]) && pcounts[0] > 0 let num = b:js_cache[1] elseif syns != '' && l:line[0] =~ '\s' let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : From 4d7a4227e874af6d6ff738dbcc38acc6141e9e6b Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 4 Sep 2016 16:50:47 -0700 Subject: [PATCH 30/57] superfluous condition --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index ebd218cd..eb8db924 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -158,7 +158,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] && b:js_cache[0] < v:lnum && b:js_cache[0] >= l:lnum && + if b:js_cache[0] < v:lnum && b:js_cache[0] >= l:lnum && \ (map(pcounts,'s:Balanced(l:lnum)')[0] > 0 || b:js_cache[0] > l:lnum) let known = l:lnum == prevnonblank(b:js_cache[0]) && pcounts[0] > 0 let num = b:js_cache[1] From 39f09ee50941f6373fa66a06de42751411d4c2a7 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 4 Sep 2016 17:07:00 -0700 Subject: [PATCH 31/57] simplify assignment --- indent/javascript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index eb8db924..f0cca94d 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -109,9 +109,9 @@ function s:Balanced(lnum) if synIDattr(synID(a:lnum,pos + 1,0),'name') !~? s:syng_strcom let idx = stridx('(){}[]', l:line[pos]) if idx % 2 == 0 - let open_{idx} = open_{idx} + 1 + let open_{idx} += 1 else - let open_{idx - 1} = open_{idx - 1} - 1 + let open_{idx - 1} -= 1 if open_{idx - 1} < 0 return 0 endif From 0134b36de5dc7f8154f64a38647951e3f9e68cc2 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Wed, 7 Sep 2016 19:06:00 -0700 Subject: [PATCH 32/57] little optimizations (#627) * little optimizations * extra parens --- indent/javascript.vim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index f0cca94d..d214f29b 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*:\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\)' @@ -180,15 +180,16 @@ function GetJavascriptIndent() return indent(num) endif - let pline = getline(l:lnum) =~# s:expr_case ? getline(l:lnum) : substitute(getline(l:lnum), '\%(:\@' && - \ l:line !~ s:line_pre . '{') && (num == 0 || cursor(b:js_cache[1],b:js_cache[2]) || s:IsBlock()) + \ l:line !~ s:line_pre . '{' let b:js_cache[3] = (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset return b:js_cache[3] + known elseif num > 0 From e69cc169119e0779b6edaf03e0f0dd4faa9fa074 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Wed, 7 Sep 2016 21:43:48 -0700 Subject: [PATCH 33/57] no adjustment in block statements This wasn't working due to the fluctuating indent possible in blocks. --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index d214f29b..ae211c7a 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -191,7 +191,7 @@ function GetJavascriptIndent() \ s:OneScope(l:lnum,pline,0) =~# '\<\%(for\|each\|if\|let\|no\sb\|w\%(hile\|ith\)\)\>' && \ l:line !~ s:line_pre . '{' let b:js_cache[3] = (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset - return b:js_cache[3] + known + return b:js_cache[3] elseif num > 0 let b:js_cache[3] = indent(num) + s:sw() + switch_offset return b:js_cache[3] + known From a7e64a92ad196e09f03722fab942e0a13273df2a Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Wed, 7 Sep 2016 22:00:58 -0700 Subject: [PATCH 34/57] don't let variable in block --- indent/javascript.vim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index ae211c7a..a6d84d1d 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -190,8 +190,7 @@ function GetJavascriptIndent() \ (num == 0 || cursor(b:js_cache[1],b:js_cache[2]) || s:IsBlock()) || \ s:OneScope(l:lnum,pline,0) =~# '\<\%(for\|each\|if\|let\|no\sb\|w\%(hile\|ith\)\)\>' && \ l:line !~ s:line_pre . '{' - let b:js_cache[3] = (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset - return b:js_cache[3] + return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset elseif num > 0 let b:js_cache[3] = indent(num) + s:sw() + switch_offset return b:js_cache[3] + known From 89b5505ab2485cd6c84b68af582a84b3d5825322 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Wed, 7 Sep 2016 22:10:00 -0700 Subject: [PATCH 35/57] Allow any comment or empty in adjustment --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index a6d84d1d..6bf22c8a 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -160,7 +160,7 @@ function GetJavascriptIndent() call cursor(v:lnum,1) if b:js_cache[0] < v:lnum && b:js_cache[0] >= l:lnum && \ (map(pcounts,'s:Balanced(l:lnum)')[0] > 0 || b:js_cache[0] > l:lnum) - let known = l:lnum == prevnonblank(b:js_cache[0]) && pcounts[0] > 0 + let known = pcounts[0] > 0 let num = b:js_cache[1] elseif syns != '' && l:line[0] =~ '\s' let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : From 0ab4b1d1838badea13314c5919f2897706ae4e70 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Wed, 7 Sep 2016 22:27:14 -0700 Subject: [PATCH 36/57] small fix --- indent/javascript.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 6bf22c8a..da2e6733 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -186,14 +186,14 @@ function GetJavascriptIndent() \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (&cino =~# '.*:[^,]*s' ? s:sw() : 1)) " most significant, find the indent amount - if (l:line =~# g:javascript_opfirst || pline =~# g:javascript_continuation) && - \ (num == 0 || cursor(b:js_cache[1],b:js_cache[2]) || s:IsBlock()) || + let isOp = l:line =~# g:javascript_opfirst || pline =~# g:javascript_continuation + if isOp && (num == 0 || cursor(b:js_cache[1],b:js_cache[2]) || s:IsBlock()) || \ 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 let b:js_cache[3] = indent(num) + s:sw() + switch_offset - return b:js_cache[3] + known + return b:js_cache[3] + (isOp ? known : 0) endif endfunction From 81d85029ae43bf7cd831ae8d8d772f2be31206b8 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Thu, 8 Sep 2016 00:00:16 -0700 Subject: [PATCH 37/57] refactor adjustment and simplify since the adjustment wasn't working well in blocks with blanks or comments, and there is never a continuation in !blocks this is far more simple --- indent/javascript.vim | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index da2e6733..f64f80c0 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -125,7 +125,7 @@ endfunction function GetJavascriptIndent() if !exists('b:js_cache') - let b:js_cache = [0,0,0,0] + let b:js_cache = [0,0,0] endif " Get the current line. let l:line = getline(v:lnum) @@ -153,14 +153,11 @@ function GetJavascriptIndent() endif "}}} - let known = 0 - let pcounts = [0] " 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] < v:lnum && b:js_cache[0] >= l:lnum && - \ (map(pcounts,'s:Balanced(l:lnum)')[0] > 0 || b:js_cache[0] > l:lnum) - let known = pcounts[0] > 0 + \ (s:Balanced(l:lnum) > 0 || b:js_cache[0] > l:lnum) let num = b:js_cache[1] elseif syns != '' && l:line[0] =~ '\s' let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : @@ -170,11 +167,7 @@ function GetJavascriptIndent() let num = s:GetPair('[({[]','[])}]','bW',2000) endif - if known && b:js_cache[3] - let known = indent(l:lnum) - b:js_cache[3] - endif - - let b:js_cache[:2] = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] + let b:js_cache = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] if l:line =~ s:line_pre . '[])}]' return indent(num) @@ -192,8 +185,7 @@ function GetJavascriptIndent() \ l:line !~ s:line_pre . '{' return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset elseif num > 0 - let b:js_cache[3] = indent(num) + s:sw() + switch_offset - return b:js_cache[3] + (isOp ? known : 0) + return isOp && num < l:lnum ? indent(l:lnum) : indent(num) + s:sw() + switch_offset endif endfunction From b53274d98e7a16d492b07b23786279e390ec2376 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Thu, 8 Sep 2016 16:52:58 -0700 Subject: [PATCH 38/57] more small improvements --- indent/javascript.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index f64f80c0..b98d9f00 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -157,7 +157,7 @@ function GetJavascriptIndent() " same scope or starts a new one, unless if it closed a scope. call cursor(v:lnum,1) if b:js_cache[0] < v:lnum && b:js_cache[0] >= l:lnum && - \ (s:Balanced(l:lnum) > 0 || 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' ? ['(',')'] : @@ -174,13 +174,13 @@ function GetJavascriptIndent() endif let pline = substitute(substitute(getline(l:lnum),s:expr_case,'\=repeat(" ",strlen(submatch(0)))',''), '\%(:\@' && \ l:line !~ s:line_pre . '{' return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset From 91314f3f30a48618ca0ff5dd575cbc17c9199d40 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Thu, 8 Sep 2016 17:24:09 -0700 Subject: [PATCH 39/57] fix objects after ternary ':' this will not be an issue since nobody uses labels for simple blocks, and if they do it is adjustable --- indent/javascript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index b98d9f00..ea6cf2d7 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -83,8 +83,8 @@ 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: Thu, 8 Sep 2016 19:31:56 -0700 Subject: [PATCH 40/57] fix blocks after case statement --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index ea6cf2d7..0ec7c944 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -84,7 +84,7 @@ endfunction function s:IsBlock() return getline(line('.'))[col('.')-1] == '{' && !search( \ '\C\%(\\|\*\@ Date: Thu, 8 Sep 2016 19:33:33 -0700 Subject: [PATCH 41/57] remove 1 char --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 0ec7c944..f90e1217 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -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: Thu, 8 Sep 2016 22:51:18 -0700 Subject: [PATCH 42/57] allow bind op as line end continuation --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index f90e1217..4dbf5d88 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -65,7 +65,7 @@ if !exists('g:javascript_opfirst') let g:javascript_opfirst = '\%([<>,?^%|*&]\|\/[^/*]\|\([-.:+]\)\1\@!\|=>\@!\|in\%(stanceof\)\=\>\)' endif if !exists('g:javascript_continuation') - let g:javascript_continuation = '\%([<=,.?/*^%|&]\|:\@\|\ Date: Fri, 9 Sep 2016 21:11:19 -0700 Subject: [PATCH 43/57] small script function changes (#628) the code is now much less embarassing --- indent/javascript.vim | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 4dbf5d88..faf592b3 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -71,20 +71,19 @@ 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) 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:GetPair('(', ')', 'cbW', 100) > 0 && search('\C\l\+\_s*\%#','bW') && - \ (a:add || ((expand('') !=# 'while' || !s:GetPair('\C\', '\C\','nbW',100)) && - \ (expand('') !=# 'each' || search('\C\') : '' + \ cursor(a:lnum, match(' ' . a:text, ')' . s:line_term)) > -1 && + \ s:GetPair('(', ')', 'bW', 100) > 0 && search('\C\l\+\_s*\%#','bW') && + \ (expand('') !=# 'while' || s:GetPair('\C\', '\C\','nbW',100) <= 0) && + \ (expand('') !=# '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\%(\\|\*\@ 0 && search('\C\' && + \ s:OneScope(l:lnum,pline) =~# '\<\%(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 0b6aad4c4051a4a4a9c2efe6499cd3adbc6dc3ba Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 11 Sep 2016 13:43:32 -0700 Subject: [PATCH 44/57] speed increase attempt (#629) --- indent/javascript.vim | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index faf592b3..d7c5f208 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -47,13 +47,23 @@ 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('.')) =~ '[''/"\\]' + return eval(s:skip_expr) + endif + if search('`','nW',a:lnum) || search('\*\/','nW',a:lnum) + let s:free = !eval(s:skip_expr) + endif + let s:looksyn = s:free ? line('.') : s:looksyn + return !s:free +endfunction if has('reltime') - 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) + 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) endfunction else - function s:GetPair(start,end,flags,n) + function s:GetPair(start,end,flags,...) return searchpair(a:start,'',a:end,a:flags,0,max([prevnonblank(v:lnum) - 2000,0])) endfunction endif @@ -74,8 +84,8 @@ let g:javascript_continuation .= s:line_term function s:OneScope(lnum,text) return a:text =~# '\%(\\)' . s:line_term ? 'no b' : \ cursor(a:lnum, match(' ' . a:text, ')' . s:line_term)) > -1 && - \ s:GetPair('(', ')', 'bW', 100) > 0 && search('\C\l\+\_s*\%#','bW') && - \ (expand('') !=# 'while' || s:GetPair('\C\', '\C\','nbW',100) <= 0) && + \ 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\') : '' endfunction @@ -131,7 +141,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 @@ -154,6 +164,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. + 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) @@ -161,9 +172,9 @@ function GetJavascriptIndent() elseif syns != '' && l:line[0] =~ '\s' let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : \ syns =~? 'jsbracket'? ['\[','\]'] : ['[({[]','[])}]'] - let num = s:GetPair(pattern[0],pattern[1],'bW',2000) + let num = s:GetPair(pattern[0],pattern[1],'bW','s:skip_func(s:looksyn)',2000) else - let num = s:GetPair('[({[]','[])}]','bW',2000) + let num = s:GetPair('[({[]','[])}]','bW','s:skip_func(s:looksyn)',2000) endif let b:js_cache = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] @@ -175,7 +186,7 @@ function GetJavascriptIndent() let pline = substitute(substitute(getline(l:lnum),s:expr_case,'\=repeat(" ",strlen(submatch(0)))',''), '\%(:\@ 0 && search('\C\ 0 && search('\C\ Date: Tue, 13 Sep 2016 11:14:42 -0700 Subject: [PATCH 45/57] copy indent if in same scope only --- indent/javascript.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index d7c5f208..10ae987d 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -164,10 +164,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. - let [s:looksyn,s:free] = [v:lnum - 1,1] + let [s:looksyn,s:free,pcounts] = [v:lnum - 1,1,[0]] 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) + \ (b:js_cache[0] > l:lnum || map(pcounts,'s:Balanced(l:lnum)')[0] > 0) let num = b:js_cache[1] elseif syns != '' && l:line[0] =~ '\s' let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : @@ -197,7 +197,7 @@ function GetJavascriptIndent() \ l:line !~ s:line_pre . '{' return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset elseif num > 0 - return isOp && num < l:lnum ? indent(l:lnum) : indent(num) + s:sw() + switch_offset + return isOp && num < l:lnum && pcounts[0] > 0 ? indent(l:lnum) : indent(num) + s:sw() + switch_offset endif endfunction From faf6f67efe6eacc772c6d52617b48e7ac0d8523f Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Tue, 13 Sep 2016 12:05:38 -0700 Subject: [PATCH 46/57] remove indent copy I can improve it in the future, but it isn't that great now --- indent/javascript.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 10ae987d..04670498 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -164,10 +164,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. - let [s:looksyn,s:free,pcounts] = [v:lnum - 1,1,[0]] + 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 || map(pcounts,'s:Balanced(l:lnum)')[0] > 0) + \ (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' ? ['(',')'] : @@ -197,7 +197,7 @@ function GetJavascriptIndent() \ l:line !~ s:line_pre . '{' return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset elseif num > 0 - return isOp && num < l:lnum && pcounts[0] > 0 ? indent(l:lnum) : indent(num) + s:sw() + switch_offset + return indent(num) + s:sw() + switch_offset endif endfunction From 4e2e37755a0393fae9b7844056958eb969527d28 Mon Sep 17 00:00:00 2001 From: Jeff Felchner Date: Mon, 12 Sep 2016 15:09:22 -0500 Subject: [PATCH 47/57] Add highlight group specifically for object colons --- syntax/javascript.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index 8cf3e627..cbe8d339 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -75,11 +75,12 @@ endif syntax cluster jsRegexpSpecial contains=jsSpecial,jsRegexpBoundary,jsRegexpBackRef,jsRegexpQuantifier,jsRegexpOr,jsRegexpMod syntax match jsObjectKey contained /\<[0-9a-zA-Z_$]*\>\(\s*:\)\@=/ contains=jsFunctionKey skipwhite skipempty nextgroup=jsObjectValue +syntax match jsObjectColon contained /:/ skipwhite skipempty syntax region jsObjectKeyString contained start=+"+ skip=+\\\("\|$\)+ end=+"\|$+ contains=jsSpecial,@Spell skipwhite skipempty nextgroup=jsObjectValue syntax region jsObjectKeyString contained start=+'+ skip=+\\\('\|$\)+ end=+'\|$+ contains=jsSpecial,@Spell skipwhite skipempty nextgroup=jsObjectValue syntax region jsObjectKeyComputed contained matchgroup=jsBrackets start=/\[/ end=/]/ contains=@jsExpression skipwhite skipempty nextgroup=jsObjectValue,jsFuncArgs extend syntax match jsObjectSeparator contained /,/ -syntax region jsObjectValue contained start=/:/ end=/\%(,\|}\)\@=/ contains=@jsExpression extend +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\+\)\@=/ skipwhite skipempty nextgroup=jsObjectFuncName @@ -285,6 +286,7 @@ if version >= 508 || !exists("did_javascript_syn_inits") HiLink jsFloat Float HiLink jsBooleanTrue Boolean HiLink jsBooleanFalse Boolean + HiLink jsObjectColon jsNoise HiLink jsNoise Noise HiLink jsBrackets Noise HiLink jsParens Noise From 355d6650d825849a3d43b3a102c0d92b4fb0765d Mon Sep 17 00:00:00 2001 From: Jeff Felchner Date: Tue, 13 Sep 2016 02:14:43 -0500 Subject: [PATCH 48/57] Add individual syntax groups for various parenthesis Many of these are noise, but I don't consider function parenthesis to be so. Rather than creating a non-function parens group, I just created a group for each type and then linked them all to `jsParens` so that everything will behave as it currently does for users who are using `jsParens`. --- syntax/javascript.vim | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index cbe8d339..8070d488 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -136,10 +136,10 @@ syntax keyword jsHtmlEvents onblur onclick oncontextmenu ondblclick onfocus "" Code blocks syntax region jsBracket matchgroup=jsBrackets start=/\[/ end=/\]/ contains=@jsExpression extend fold syntax region jsParen matchgroup=jsParens start=/(/ end=/)/ contains=@jsAll extend fold -syntax region jsParenIfElse contained matchgroup=jsParens start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsCommentMisc,jsBlock extend fold -syntax region jsParenRepeat contained matchgroup=jsParens start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsCommentMisc,jsBlock extend fold -syntax region jsParenSwitch contained matchgroup=jsParens start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsSwitchBlock extend fold -syntax region jsParenCatch contained matchgroup=jsParens start=/(/ end=/)/ skipwhite skipempty nextgroup=jsTryCatchBlock extend fold +syntax region jsParenIfElse contained matchgroup=jsParensIfElse start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsCommentMisc,jsBlock extend fold +syntax region jsParenRepeat contained matchgroup=jsParensRepeat start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsCommentMisc,jsBlock extend fold +syntax region jsParenSwitch contained matchgroup=jsParensSwitch start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsSwitchBlock extend fold +syntax region jsParenCatch contained matchgroup=jsParensCatch start=/(/ end=/)/ skipwhite skipempty nextgroup=jsTryCatchBlock extend fold syntax region jsFuncArgs contained matchgroup=jsFuncParens start=/(/ end=/)/ contains=jsFuncArgCommas,jsComment,jsFuncArgExpression,jsDestructuringBlock,jsRestExpression,jsFlowArgumentDef skipwhite skipempty nextgroup=jsCommentFunction,jsFuncBlock,jsFlowReturn extend fold syntax region jsClassBlock contained matchgroup=jsClassBraces start=/{/ end=/}/ contains=jsClassFuncName,jsClassMethodType,jsArrowFunction,jsArrowFuncArgs,jsComment,jsGenerator,jsDecorator,jsClassProperty,jsClassPropertyComputed,jsClassStringKey,jsNoise extend fold syntax region jsFuncBlock contained matchgroup=jsFuncBraces start=/{/ end=/}/ contains=@jsAll extend fold @@ -233,6 +233,10 @@ if version >= 508 || !exists("did_javascript_syn_inits") endif HiLink jsComment Comment HiLink jsEnvComment PreProc + HiLink jsParensIfElse jsParens + HiLink jsParensRepeat jsParens + HiLink jsParensSwitch jsParens + HiLink jsParensCatch jsParens HiLink jsCommentTodo Todo HiLink jsString String HiLink jsObjectKeyString String From 615f83754490c72f93eeac29f86b31c3b77f4b01 Mon Sep 17 00:00:00 2001 From: Jeff Felchner Date: Tue, 13 Sep 2016 02:33:19 -0500 Subject: [PATCH 49/57] Add more specialized groups for the various braces Similar to the parens from the previous commit, this will allow users to customize the look of various types of braces rather than having to go all-in on non-function braces. ------------------------------------------------------------------------------ Actions: * Fix #589 --- syntax/javascript.vim | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index 8070d488..3f9cb9b5 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -41,12 +41,12 @@ syntax keyword jsModuleKeywords contained import syntax keyword jsModuleKeywords contained export skipwhite skipempty nextgroup=jsExportBlock,jsModuleDefault syntax keyword jsModuleOperators contained from syntax keyword jsModuleOperators contained as -syntax region jsModuleGroup contained matchgroup=jsBraces start=/{/ end=/}/ contains=jsModuleOperators,jsNoise,jsComment +syntax region jsModuleGroup contained matchgroup=jsModuleBraces start=/{/ end=/}/ contains=jsModuleOperators,jsNoise,jsComment syntax match jsModuleAsterisk contained /*/ syntax keyword jsModuleDefault contained default skipwhite skipempty nextgroup=@jsExpression syntax region jsImportContainer start=/\ / end="\%(;\|$\)" contains=jsModuleKeywords,jsModuleOperators,jsComment,jsString,jsTemplateString,jsNoise,jsModuleGroup,jsModuleAsterisk syntax region jsExportContainer start=/\ / end="\%(;\|$\)" contains=jsModuleKeywords,jsModuleOperators,jsStorageClass,jsModuleDefault,@jsExpression -syntax region jsExportBlock contained matchgroup=jsBraces start=/{/ end=/}/ contains=jsModuleOperators,jsNoise,jsComment +syntax region jsExportBlock contained matchgroup=jsExportBraces start=/{/ end=/}/ contains=jsModuleOperators,jsNoise,jsComment " Strings, Templates, Numbers syntax region jsString start=+"+ skip=+\\\("\|$\)+ end=+"\|$+ contains=jsSpecial,@Spell extend @@ -98,17 +98,17 @@ exe 'syntax keyword jsSuper super contained '.(exists('g:javascript_conceal " Statement Keywords 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,jsBlock +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 jsDo do skipwhite skipempty nextgroup=jsBlock +syntax keyword jsDo do skipwhite skipempty nextgroup=jsRepeatBlock syntax keyword jsLabel contained case default syntax keyword jsTry try skipwhite skipempty nextgroup=jsTryCatchBlock -syntax keyword jsFinally contained finally skipwhite skipempty nextgroup=jsBlock +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 await -syntax match jsSwitchColon contained /:/ skipwhite skipempty nextgroup=jsBlock +syntax match jsSwitchColon contained /:/ skipwhite skipempty nextgroup=jsSwitchBlock " 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 @@ -136,16 +136,19 @@ syntax keyword jsHtmlEvents onblur onclick oncontextmenu ondblclick onfocus "" Code blocks syntax region jsBracket matchgroup=jsBrackets start=/\[/ end=/\]/ contains=@jsExpression extend fold syntax region jsParen matchgroup=jsParens start=/(/ end=/)/ contains=@jsAll extend fold -syntax region jsParenIfElse contained matchgroup=jsParensIfElse start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsCommentMisc,jsBlock extend fold -syntax region jsParenRepeat contained matchgroup=jsParensRepeat start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsCommentMisc,jsBlock extend fold +syntax region jsParenIfElse contained matchgroup=jsParensIfElse start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsCommentMisc,jsIfElseBlock extend fold +syntax region jsParenRepeat contained matchgroup=jsParensRepeat start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsCommentMisc,jsRepeatBlock extend fold syntax region jsParenSwitch contained matchgroup=jsParensSwitch start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsSwitchBlock extend fold syntax region jsParenCatch contained matchgroup=jsParensCatch start=/(/ end=/)/ skipwhite skipempty nextgroup=jsTryCatchBlock extend fold syntax region jsFuncArgs contained matchgroup=jsFuncParens start=/(/ end=/)/ contains=jsFuncArgCommas,jsComment,jsFuncArgExpression,jsDestructuringBlock,jsRestExpression,jsFlowArgumentDef skipwhite skipempty nextgroup=jsCommentFunction,jsFuncBlock,jsFlowReturn extend fold syntax region jsClassBlock contained matchgroup=jsClassBraces start=/{/ end=/}/ contains=jsClassFuncName,jsClassMethodType,jsArrowFunction,jsArrowFuncArgs,jsComment,jsGenerator,jsDecorator,jsClassProperty,jsClassPropertyComputed,jsClassStringKey,jsNoise extend fold syntax region jsFuncBlock contained matchgroup=jsFuncBraces start=/{/ end=/}/ contains=@jsAll extend fold +syntax region jsIfElseBlock contained matchgroup=jsIfElseBraces start=/{/ end=/}/ contains=@jsAll extend fold syntax region jsBlock contained matchgroup=jsBraces start=/{/ end=/}/ contains=@jsAll extend fold -syntax region jsTryCatchBlock contained matchgroup=jsBraces start=/{/ end=/}/ contains=@jsAll skipwhite skipempty nextgroup=jsCatch,jsFinally extend fold -syntax region jsSwitchBlock contained matchgroup=jsBraces start=/{/ end=/}/ contains=@jsAll,jsLabel,jsSwitchColon extend fold +syntax region jsTryCatchBlock contained matchgroup=jsTryCatchBraces start=/{/ end=/}/ contains=@jsAll skipwhite skipempty nextgroup=jsCatch,jsFinally extend fold +syntax region jsFinallyBlock contained matchgroup=jsFinallyBraces start=/{/ end=/}/ contains=@jsAll extend fold +syntax region jsSwitchBlock contained matchgroup=jsSwitchBraces start=/{/ end=/}/ contains=@jsAll,jsLabel,jsSwitchColon extend fold +syntax region jsRepeatBlock contained matchgroup=jsRepeatBraces start=/{/ end=/}/ contains=@jsAll extend fold syntax region jsDestructuringBlock contained matchgroup=jsDestructuringBraces start=/{/ end=/}/ contains=jsDestructuringProperty,jsDestructuringAssignment,jsDestructuringNoise,jsDestructuringPropertyComputed,jsSpreadExpression extend fold syntax region jsDestructuringArray contained matchgroup=jsDestructuringBraces start=/\[/ end=/\]/ contains=jsDestructuringPropertyValue,jsNoise,jsDestructuringProperty,jsSpreadExpression extend fold syntax region jsObject matchgroup=jsObjectBraces start=/{/ end=/}/ contains=jsObjectKey,jsObjectKeyString,jsObjectKeyComputed,jsObjectSeparator,jsObjectFuncName,jsObjectMethodType,jsGenerator,jsComment,jsObjectStringKey,jsSpreadExpression extend fold @@ -299,8 +302,15 @@ if version >= 508 || !exists("did_javascript_syn_inits") HiLink jsFuncParens Noise HiLink jsClassBraces Noise HiLink jsClassNoise Noise + HiLink jsIfElseBraces jsBraces + HiLink jsTryCatchBraces jsBraces + HiLink jsModuleBraces jsBraces HiLink jsObjectBraces Noise HiLink jsObjectSeparator Noise + HiLink jsFinallyBraces jsBraces + HiLink jsRepeatBraces jsBraces + HiLink jsSwitchBraces jsBraces + HiLink jsExportBraces jsBraces HiLink jsSpecial Special HiLink jsTemplateVar Special HiLink jsTemplateBraces jsBraces From 430b5284ff69e07977ead013a3caf7b66ee0414c Mon Sep 17 00:00:00 2001 From: Jeff Felchner Date: Tue, 13 Sep 2016 02:58:24 -0500 Subject: [PATCH 50/57] Removed 'contained' constraint from 'this' keyword highlight `this` can be used outside of any other block and thus needs to be highlighted there. ------------------------------------------------------------------------------ Actions: * Fix #610 --- syntax/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index 3f9cb9b5..69311f69 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -92,7 +92,7 @@ exe 'syntax keyword jsReturn return contained '.(exists('g:javascript_conceal exe 'syntax keyword jsUndefined undefined '.(exists('g:javascript_conceal_undefined') ? 'conceal cchar='.g:javascript_conceal_undefined : '') exe 'syntax keyword jsNan NaN '.(exists('g:javascript_conceal_NaN') ? 'conceal cchar='.g:javascript_conceal_NaN : '') exe 'syntax keyword jsPrototype prototype '.(exists('g:javascript_conceal_prototype') ? 'conceal cchar='.g:javascript_conceal_prototype : '') -exe 'syntax keyword jsThis this contained '.(exists('g:javascript_conceal_this') ? 'conceal cchar='.g:javascript_conceal_this : '') +exe 'syntax keyword jsThis this '.(exists('g:javascript_conceal_this') ? 'conceal cchar='.g:javascript_conceal_this : '') exe 'syntax keyword jsSuper super contained '.(exists('g:javascript_conceal_super') ? 'conceal cchar='.g:javascript_conceal_super : '') " Statement Keywords From aa2fb9015918eae56e9a11b44e281ee016b12c63 Mon Sep 17 00:00:00 2001 From: Jeff Felchner Date: Tue, 13 Sep 2016 03:05:21 -0500 Subject: [PATCH 51/57] Add section comments --- syntax/javascript.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index 69311f69..6c58163b 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -74,6 +74,7 @@ else endif syntax cluster jsRegexpSpecial contains=jsSpecial,jsRegexpBoundary,jsRegexpBackRef,jsRegexpQuantifier,jsRegexpOr,jsRegexpMod +" Objects syntax match jsObjectKey contained /\<[0-9a-zA-Z_$]*\>\(\s*:\)\@=/ contains=jsFunctionKey skipwhite skipempty nextgroup=jsObjectValue syntax match jsObjectColon contained /:/ skipwhite skipempty syntax region jsObjectKeyString contained start=+"+ skip=+\\\("\|$\)+ end=+"\|$+ contains=jsSpecial,@Spell skipwhite skipempty nextgroup=jsObjectValue @@ -133,7 +134,7 @@ syntax keyword jsDomNodeConsts ELEMENT_NODE ATTRIBUTE_NODE TEXT_NODE CDATA_SECT " HTML events and internal variables syntax keyword jsHtmlEvents onblur onclick oncontextmenu ondblclick onfocus onkeydown onkeypress onkeyup onmousedown onmousemove onmouseout onmouseover onmouseup onresize -"" Code blocks +" Code blocks syntax region jsBracket matchgroup=jsBrackets start=/\[/ end=/\]/ contains=@jsExpression extend fold syntax region jsParen matchgroup=jsParens start=/(/ end=/)/ contains=@jsAll extend fold syntax region jsParenIfElse contained matchgroup=jsParensIfElse start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsCommentMisc,jsIfElseBlock extend fold @@ -171,6 +172,7 @@ syntax match jsArrowFuncArgs /([^()]*)\s*\(=>\)\@=/ contains=jsFuncArgs skipe 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 : '') +" Classes syntax keyword jsClassKeywords contained extends class syntax match jsClassNoise contained /\./ syntax match jsClassMethodType contained /\%(get\|set\|static\|async\)\%( \k\+\)\@=/ skipwhite skipempty nextgroup=jsFuncName,jsClassProperty From 20bb09ae6cdade7bb973539e9fa40e35280baff0 Mon Sep 17 00:00:00 2001 From: Jeff Felchner Date: Tue, 13 Sep 2016 03:19:04 -0500 Subject: [PATCH 52/57] Fix decorator syntax highlighting There were a few issues here: * Class decorators weren't being highlighted since they exist outside of any other group * Decorators which take a parameter didn't have their parameters property highlighted * Decorators which decorated a function within an object weren't being highlighted -------------------------------------------------------------------------------- Actions: * Fixes #590 * Fixes #572 --- syntax/javascript.vim | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index 6c58163b..d0f88abf 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -137,6 +137,7 @@ syntax keyword jsHtmlEvents onblur onclick oncontextmenu ondblclick onfocus " Code blocks syntax region jsBracket matchgroup=jsBrackets start=/\[/ end=/\]/ contains=@jsExpression extend fold syntax region jsParen matchgroup=jsParens start=/(/ end=/)/ contains=@jsAll extend fold +syntax region jsParenDecorator contained matchgroup=jsParensDecorator start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsCommentMisc extend fold syntax region jsParenIfElse contained matchgroup=jsParensIfElse start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsCommentMisc,jsIfElseBlock extend fold syntax region jsParenRepeat contained matchgroup=jsParensRepeat start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsCommentMisc,jsRepeatBlock extend fold syntax region jsParenSwitch contained matchgroup=jsParensSwitch start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsSwitchBlock extend fold @@ -152,7 +153,7 @@ syntax region jsSwitchBlock contained matchgroup=jsSwitchBraces s syntax region jsRepeatBlock contained matchgroup=jsRepeatBraces start=/{/ end=/}/ contains=@jsAll extend fold syntax region jsDestructuringBlock contained matchgroup=jsDestructuringBraces start=/{/ end=/}/ contains=jsDestructuringProperty,jsDestructuringAssignment,jsDestructuringNoise,jsDestructuringPropertyComputed,jsSpreadExpression extend fold syntax region jsDestructuringArray contained matchgroup=jsDestructuringBraces start=/\[/ end=/\]/ contains=jsDestructuringPropertyValue,jsNoise,jsDestructuringProperty,jsSpreadExpression extend fold -syntax region jsObject matchgroup=jsObjectBraces start=/{/ end=/}/ contains=jsObjectKey,jsObjectKeyString,jsObjectKeyComputed,jsObjectSeparator,jsObjectFuncName,jsObjectMethodType,jsGenerator,jsComment,jsObjectStringKey,jsSpreadExpression extend fold +syntax region jsObject matchgroup=jsObjectBraces start=/{/ end=/}/ contains=jsObjectKey,jsObjectKeyString,jsObjectKeyComputed,jsObjectSeparator,jsObjectFuncName,jsObjectMethodType,jsGenerator,jsComment,jsObjectStringKey,jsSpreadExpression,jsDecorator extend fold syntax region jsTernaryIf matchgroup=jsTernaryIfOperator start=/?/ end=/\%(:\|[\}]\@=\)/ contains=@jsExpression syntax region jsSpreadExpression contained matchgroup=jsSpreadOperator start=/\.\.\./ end=/[,}\]]\@=/ contains=@jsExpression syntax region jsRestExpression contained matchgroup=jsRestOperator start=/\.\.\./ end=/[,)]\@=/ @@ -177,8 +178,6 @@ syntax keyword jsClassKeywords contained extends class syntax match jsClassNoise contained /\./ 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 jsDecorator contained "@" nextgroup=jsDecoratorFunction -syntax match jsDecoratorFunction contained "[a-zA-Z_][a-zA-Z0-9_.]*" syntax match jsClassProperty contained /\<[0-9a-zA-Z_$]*\>\(\s*=\)\@=/ skipwhite skipempty nextgroup=jsClassValue syntax region jsClassValue contained start=/=/ end=/\%(;\|}\|\n\)\@=/ contains=@jsExpression syntax region jsClassPropertyComputed contained matchgroup=jsBrackets start=/\[/ end=/]/ contains=@jsExpression skipwhite skipempty nextgroup=jsFuncArgs,jsClassValue extend @@ -211,6 +210,10 @@ syntax region jsCommentClass contained start=/\/\*/ end=/\*\// contains=j syntax region jsCommentMisc contained start=/\/\// end=/$/ contains=jsCommentTodo,@Spell skipwhite skipempty nextgroup=jsBlock extend keepend syntax region jsCommentMisc contained start=/\/\*/ end=/\*\// contains=jsCommentTodo,@Spell skipwhite skipempty nextgroup=jsBlock fold extend keepend +" Decorators +syntax match jsDecorator /^\s*@/ nextgroup=jsDecoratorFunction +syntax match jsDecoratorFunction contained /[a-zA-Z_][a-zA-Z0-9_.]*/ nextgroup=jsParenDecorator + if exists("javascript_plugin_jsdoc") runtime extras/jsdoc.vim " NGDoc requires JSDoc From 801aad41bd9a52015fff99ebcc92c9db9c3baef8 Mon Sep 17 00:00:00 2001 From: Jeff Felchner Date: Tue, 13 Sep 2016 03:21:26 -0500 Subject: [PATCH 53/57] Change highlight link for decorators to 'Tag' This makes quite a bit more sense to me since decorators are a type of annotation to the function below. --- syntax/javascript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index d0f88abf..c4ee3394 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -326,8 +326,8 @@ if version >= 508 || !exists("did_javascript_syn_inits") HiLink jsModuleKeywords Include HiLink jsModuleOperators Include HiLink jsModuleDefault Include - HiLink jsDecorator Special - HiLink jsDecoratorFunction Special + HiLink jsDecorator Tag + HiLink jsDecoratorFunction Tag HiLink jsFuncArgOperator jsFuncArgs HiLink jsModuleAsterisk Noise HiLink jsClassProperty jsObjectKey From 6c78b77ad48b76b10d9054c7b65aba79acec58f4 Mon Sep 17 00:00:00 2001 From: Jeff Felchner Date: Tue, 13 Sep 2016 03:28:59 -0500 Subject: [PATCH 54/57] Whitespace --- syntax/javascript.vim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index c4ee3394..e3e2373d 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -112,13 +112,13 @@ syntax keyword jsAsyncKeyword async await syntax match jsSwitchColon contained /:/ skipwhite skipempty nextgroup=jsSwitchBlock " 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 keyword jsExceptions Error EvalError InternalError RangeError ReferenceError StopIteration SyntaxError TypeError URIError -syntax keyword jsBuiltins decodeURI decodeURIComponent encodeURI encodeURIComponent eval isFinite isNaN parseFloat parseInt uneval +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 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? -syntax keyword jsFutureKeys abstract enum int short boolean interface byte long char final native synchronized float package throws goto private transient implements protected volatile double public +syntax keyword jsFutureKeys abstract enum int short boolean interface byte long char final native synchronized float package throws goto private transient implements protected volatile double public " DISCUSS: Should we really be matching stuff like this? " DOM2 Objects From 0cb2e1134d397b9a06d57ef8a1bae4f666630a25 Mon Sep 17 00:00:00 2001 From: Jeff Felchner Date: Tue, 13 Sep 2016 03:52:14 -0500 Subject: [PATCH 55/57] Change ClassKeywords to Keywords instead of Define It's right there in the name: "Keyword" and should be highlighted as such. --- syntax/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index e3e2373d..b6b1ba51 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -288,7 +288,7 @@ if version >= 508 || !exists("did_javascript_syn_inits") HiLink jsOperator Operator HiLink jsOf Operator HiLink jsStorageClass StorageClass - HiLink jsClassKeywords Structure + HiLink jsClassKeywords Keyword HiLink jsThis Special HiLink jsSuper Constant HiLink jsNan Number From 5c4de0c43d23a98cf382f045aff270977c3bb12c Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Tue, 13 Sep 2016 16:05:06 -0700 Subject: [PATCH 56/57] slight changes to the skip_func (#632) This is what I was initially intending to do. this version works mostly the same --- indent/javascript.vim | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 04670498..1591dac0 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -48,10 +48,7 @@ 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('.')) =~ '[''/"\\]' - return eval(s:skip_expr) - endif - if search('`','nW',a:lnum) || search('\*\/','nW',a:lnum) + if !s:free || getline(line('.')) =~ '[''/"\\]' || search('`','nW',a:lnum) || search('\*\/','nW',a:lnum) let s:free = !eval(s:skip_expr) endif let s:looksyn = s:free ? line('.') : s:looksyn From d5dbecb6e9084052573c9eb7d6de9536b9f2034e Mon Sep 17 00:00:00 2001 From: Amadeus Demarzi Date: Wed, 14 Sep 2016 15:21:10 -0700 Subject: [PATCH 57/57] Group link fixes --- syntax/javascript.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index b6b1ba51..56e7c6d3 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -326,8 +326,9 @@ if version >= 508 || !exists("did_javascript_syn_inits") HiLink jsModuleKeywords Include HiLink jsModuleOperators Include HiLink jsModuleDefault Include - HiLink jsDecorator Tag - HiLink jsDecoratorFunction Tag + HiLink jsDecorator Special + HiLink jsDecoratorFunction Function + HiLink jsParensDecorator jsParens HiLink jsFuncArgOperator jsFuncArgs HiLink jsModuleAsterisk Noise HiLink jsClassProperty jsObjectKey