From 4456229dd73ce3672b35be60afeb9021033e0375 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Wed, 26 Oct 2016 15:15:23 -0700 Subject: [PATCH 01/35] non whitespace non : 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 5191a2c2..67f50b30 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -37,7 +37,7 @@ else endfunction endif -let s:expr_case = '\<\%(\%(case\>\s*\S.\{-}\)\|default\)\s*:\C' +let s:expr_case = '\<\%(\%(case\>\s*[^[:blank:]:].\{-}\)\|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 460598f32fda138d45960f5becfd627efcc2a074 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Thu, 27 Oct 2016 19:14:27 -0700 Subject: [PATCH 02/35] fix 'default' property identifier (#689) --- indent/javascript.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 67f50b30..0a448395 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -140,7 +140,8 @@ function s:IsBlock() elseif char == '>' return pchar == '=' || syn =~? '^jsflow' elseif char == ':' - return strpart(getline('.'),0,col('.')) =~# s:expr_case . '$' + return cursor(0,match(' ' . strpart(getline('.'),0,col('.')),s:expr_case . '$')) + 1 && + \ (expand('') !=# 'default' || !search('\S','bW') || getline('.')[col('.')-1] !~ '[,{]') else return stridx('-=~!<*+,/?^%|&([',char) < 0 endif From bf2a1b42f2724658b9d62dbe0dfb5acacd316ef0 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Thu, 27 Oct 2016 22:40:13 -0700 Subject: [PATCH 03/35] last case statement --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 0a448395..8551cce7 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -140,7 +140,7 @@ function s:IsBlock() elseif char == '>' return pchar == '=' || syn =~? '^jsflow' elseif char == ':' - return cursor(0,match(' ' . strpart(getline('.'),0,col('.')),s:expr_case . '$')) + 1 && + return cursor(0,match(' ' . strpart(getline('.'),0,col('.')),'.*\zs' . s:expr_case . '$')) + 1 && \ (expand('') !=# 'default' || !search('\S','bW') || getline('.')[col('.')-1] !~ '[,{]') else return stridx('-=~!<*+,/?^%|&([',char) < 0 From 2d33a9e11a1496c38aa4949caa240c3a1feefcee Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sat, 29 Oct 2016 11:46:32 -0700 Subject: [PATCH 04/35] code cleaning --- indent/javascript.vim | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 8551cce7..e4a380fb 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -132,11 +132,8 @@ function s:IsBlock() if syn =~? '\%(xml\|jsx\)' return char != '{' elseif char =~# '\l' - if line('.') == l:ln && expand('') ==# 'return' - return 0 - endif - return index(split('const let import export yield default delete var void typeof throw new in instanceof') - \ , expand('')) < 0 + return index(split('return const let import export yield default delete var void typeof throw new in instanceof') + \ , expand('')) < (0 + (line('.') != l:ln)) elseif char == '>' return pchar == '=' || syn =~? '^jsflow' elseif char == ':' From b4517ac35479dc07eb9c6a853835556b231c500a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Rodr=C3=ADguez?= Date: Sat, 29 Oct 2016 17:28:02 -0300 Subject: [PATCH 05/35] Add fetch keyword to list of globals Closes #688. --- syntax/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index 74b619b1..22733c78 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -112,7 +112,7 @@ 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 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 fetch syntax keyword jsGlobalNodeObjects module exports global process syntax match jsGlobalNodeObjects /require/ containedin=jsFuncCall syntax keyword jsExceptions Error EvalError InternalError RangeError ReferenceError StopIteration SyntaxError TypeError URIError From 579997a82c4e9009675bf295b69ed28b34cff541 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sat, 29 Oct 2016 14:16:34 -0700 Subject: [PATCH 06/35] isBlock cleaning --- indent/javascript.vim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index e4a380fb..c565af8c 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -142,9 +142,8 @@ function s:IsBlock() else return stridx('-=~!<*+,/?^%|&([',char) < 0 endif - else - return 1 endif + return 1 endfunction " Find line above 'lnum' that isn't empty, in a comment, or in a string. From 8996ec59311978869c254bbd614e1168a6152e78 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sat, 29 Oct 2016 14:21:18 -0700 Subject: [PATCH 07/35] date, cleaning --- indent/javascript.vim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index c565af8c..335eacde 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 24, 2016 +" Last Change: October 29, 2016 " Only load this indent file when no other was loaded. if exists('b:did_indent') @@ -139,9 +139,8 @@ function s:IsBlock() elseif char == ':' return cursor(0,match(' ' . strpart(getline('.'),0,col('.')),'.*\zs' . s:expr_case . '$')) + 1 && \ (expand('') !=# 'default' || !search('\S','bW') || getline('.')[col('.')-1] !~ '[,{]') - else - return stridx('-=~!<*+,/?^%|&([',char) < 0 endif + return stridx('-=~!<*+,/?^%|&([',char) < 0 endif return 1 endfunction From afb03f5eb638187cba6d175b3f60ff07188b4b81 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sat, 29 Oct 2016 17:28:51 -0700 Subject: [PATCH 08/35] cleaning,skip_func --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 335eacde..d945200a 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -50,7 +50,7 @@ function s:skip_func(lnum) return !s:free endif let s:looksyn = line('.') - return (strridx(getline('.'),'/',col('.')-1) + 1 || search('[''"\\]','nW',s:looksyn)) && eval(s:skip_expr) + return (search('\/','nbW',s:looksyn) || search('[''"\\]','nW',s:looksyn)) && eval(s:skip_expr) endfunction if has('reltime') From 187b1d6a0ee5513db105bdf34e07663d13923993 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 30 Oct 2016 16:58:11 -0700 Subject: [PATCH 09/35] recursion in isBlock: comment skip (#692) --- indent/javascript.vim | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index d945200a..c8195ac4 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -115,21 +115,15 @@ function s:iscontOne(i,num,cont) endfunction " https://github.com/sweet-js/sweet.js/wiki/design#give-lookbehind-to-the-reader -function s:IsBlock() - let l:ln = line('.') +function s:IsBlock(...) + let l:ln = get(a:000,0,line('.')) if search('\S','bW') let char = getline('.')[col('.')-1] let pchar = getline('.')[col('.')-2] let syn = synIDattr(synID(line('.'),col('.')-1,0),'name') - if pchar . char == '*/' && syn =~? 'comment' - if !search('\/\*','bW') || !search('\S','bW') - return 1 - endif - let char = getline('.')[col('.')-1] - let pchar = getline('.')[col('.')-2] - let syn = synIDattr(synID(line('.'),col('.')-1,0),'name') - endif - if syn =~? '\%(xml\|jsx\)' + if syn =~? 'comment' + return search('\/[/*]','bW') && s:IsBlock(l:ln) + elseif syn =~? '\%(xml\|jsx\)' return char != '{' elseif char =~# '\l' return index(split('return const let import export yield default delete var void typeof throw new in instanceof') From f8fc08c8d3e1726ee3e9eba61a965a294e584343 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 30 Oct 2016 20:01:47 -0700 Subject: [PATCH 10/35] small comment fix --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index c8195ac4..69f24107 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -120,7 +120,7 @@ function s:IsBlock(...) if search('\S','bW') let char = getline('.')[col('.')-1] let pchar = getline('.')[col('.')-2] - let syn = synIDattr(synID(line('.'),col('.')-1,0),'name') + let syn = synIDattr(synID(line('.'),col('.')-(char == '{'),0),'name') if syn =~? 'comment' return search('\/[/*]','bW') && s:IsBlock(l:ln) elseif syn =~? '\%(xml\|jsx\)' From dcf820b2a401bdbfff7d54feeef0e1ecceb1d581 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 30 Oct 2016 21:17:22 -0700 Subject: [PATCH 11/35] adjust precedence of comment/jsx --- indent/javascript.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 69f24107..1fe371ff 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -121,10 +121,10 @@ function s:IsBlock(...) let char = getline('.')[col('.')-1] let pchar = getline('.')[col('.')-2] let syn = synIDattr(synID(line('.'),col('.')-(char == '{'),0),'name') - if syn =~? 'comment' - return search('\/[/*]','bW') && s:IsBlock(l:ln) - elseif syn =~? '\%(xml\|jsx\)' + if syn =~? '\%(xml\|jsx\)' return char != '{' + elseif syn =~? 'comment' + return search('\/[/*]','bW') && s:IsBlock(l:ln) elseif char =~# '\l' return index(split('return const let import export yield default delete var void typeof throw new in instanceof') \ , expand('')) < (0 + (line('.') != l:ln)) From 1e52ed9bcd2d5f89c062d34afeeac4bcfbad831e Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Mon, 31 Oct 2016 00:11:43 -0700 Subject: [PATCH 12/35] remove var --- indent/javascript.vim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 1fe371ff..105d4862 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -119,7 +119,6 @@ function s:IsBlock(...) let l:ln = get(a:000,0,line('.')) if search('\S','bW') let char = getline('.')[col('.')-1] - let pchar = getline('.')[col('.')-2] let syn = synIDattr(synID(line('.'),col('.')-(char == '{'),0),'name') if syn =~? '\%(xml\|jsx\)' return char != '{' @@ -129,7 +128,7 @@ function s:IsBlock(...) return index(split('return const let import export yield default delete var void typeof throw new in instanceof') \ , expand('')) < (0 + (line('.') != l:ln)) elseif char == '>' - return pchar == '=' || syn =~? '^jsflow' + return getline('.')[col('.')-2] == '=' || syn =~? '^jsflow' elseif char == ':' return cursor(0,match(' ' . strpart(getline('.'),0,col('.')),'.*\zs' . s:expr_case . '$')) + 1 && \ (expand('') !=# 'default' || !search('\S','bW') || getline('.')[col('.')-1] !~ '[,{]') From 918202964ff67c1d242573e0146ff35fcf468495 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Mon, 31 Oct 2016 01:47:20 -0700 Subject: [PATCH 13/35] clearer char checking --- indent/javascript.vim | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 105d4862..4db372d4 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -118,22 +118,22 @@ endfunction function s:IsBlock(...) let l:ln = get(a:000,0,line('.')) if search('\S','bW') - let char = getline('.')[col('.')-1] - let syn = synIDattr(synID(line('.'),col('.')-(char == '{'),0),'name') + let char = strpart(getline('.'),col('.')-2,2) + let syn = synIDattr(synID(line('.'),col('.')-(char[1] == '{'),0),'name') if syn =~? '\%(xml\|jsx\)' - return char != '{' + return char[1] != '{' elseif syn =~? 'comment' return search('\/[/*]','bW') && s:IsBlock(l:ln) - elseif char =~# '\l' + elseif char[1] =~# '\l' return index(split('return const let import export yield default delete var void typeof throw new in instanceof') \ , expand('')) < (0 + (line('.') != l:ln)) - elseif char == '>' - return getline('.')[col('.')-2] == '=' || syn =~? '^jsflow' - elseif char == ':' + elseif char[1] == '>' + return char[0] == '=' || syn =~? '^jsflow' + elseif char[1] == ':' return cursor(0,match(' ' . strpart(getline('.'),0,col('.')),'.*\zs' . s:expr_case . '$')) + 1 && \ (expand('') !=# 'default' || !search('\S','bW') || getline('.')[col('.')-1] !~ '[,{]') endif - return stridx('-=~!<*+,/?^%|&([',char) < 0 + return stridx('-=~!<*+,/?^%|&([',char[1]) < 0 endif return 1 endfunction From cdb44a869cfebec30d5933d1a3b66bc7f5b0b936 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Mon, 31 Oct 2016 10:38:24 -0700 Subject: [PATCH 14/35] last index string --- indent/javascript.vim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 4db372d4..7ccc3d6e 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -119,17 +119,17 @@ function s:IsBlock(...) let l:ln = get(a:000,0,line('.')) if search('\S','bW') let char = strpart(getline('.'),col('.')-2,2) - let syn = synIDattr(synID(line('.'),col('.')-(char[1] == '{'),0),'name') + let syn = synIDattr(synID(line('.'),col('.')-(char[-1:] == '{'),0),'name') if syn =~? '\%(xml\|jsx\)' - return char[1] != '{' + return char[-1:] != '{' elseif syn =~? 'comment' return search('\/[/*]','bW') && s:IsBlock(l:ln) - elseif char[1] =~# '\l' + elseif char[-1:] =~# '\l' return index(split('return const let import export yield default delete var void typeof throw new in instanceof') \ , expand('')) < (0 + (line('.') != l:ln)) - elseif char[1] == '>' + elseif char[-1:] == '>' return char[0] == '=' || syn =~? '^jsflow' - elseif char[1] == ':' + elseif char[-1:] == ':' return cursor(0,match(' ' . strpart(getline('.'),0,col('.')),'.*\zs' . s:expr_case . '$')) + 1 && \ (expand('') !=# 'default' || !search('\S','bW') || getline('.')[col('.')-1] !~ '[,{]') endif From 01193be9e98f8a673adb6ed069b63b16303accdb Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Mon, 31 Oct 2016 10:41:20 -0700 Subject: [PATCH 15/35] date, str char --- indent/javascript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 7ccc3d6e..625720e8 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 29, 2016 +" Last Change: Octember 31, 2016 " Only load this indent file when no other was loaded. if exists('b:did_indent') @@ -133,7 +133,7 @@ function s:IsBlock(...) return cursor(0,match(' ' . strpart(getline('.'),0,col('.')),'.*\zs' . s:expr_case . '$')) + 1 && \ (expand('') !=# 'default' || !search('\S','bW') || getline('.')[col('.')-1] !~ '[,{]') endif - return stridx('-=~!<*+,/?^%|&([',char[1]) < 0 + return stridx('-=~!<*+,/?^%|&([',char[-1:]) < 0 endif return 1 endfunction From 65e68f563e154da2069b2aaa671560e4fef7a6a0 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Mon, 31 Oct 2016 14:31:49 -0700 Subject: [PATCH 16/35] revert char check --- indent/javascript.vim | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 625720e8..311ec08f 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -118,22 +118,22 @@ endfunction function s:IsBlock(...) let l:ln = get(a:000,0,line('.')) if search('\S','bW') - let char = strpart(getline('.'),col('.')-2,2) - let syn = synIDattr(synID(line('.'),col('.')-(char[-1:] == '{'),0),'name') + let char = getline('.')[col('.')-1] + let syn = synIDattr(synID(line('.'),col('.')-(char == '{'),0),'name') if syn =~? '\%(xml\|jsx\)' - return char[-1:] != '{' + return char != '{' elseif syn =~? 'comment' return search('\/[/*]','bW') && s:IsBlock(l:ln) - elseif char[-1:] =~# '\l' + elseif char =~# '\l' return index(split('return const let import export yield default delete var void typeof throw new in instanceof') \ , expand('')) < (0 + (line('.') != l:ln)) - elseif char[-1:] == '>' - return char[0] == '=' || syn =~? '^jsflow' - elseif char[-1:] == ':' + elseif char == '>' + return getline('.')[col('.')-2] == '=' || syn =~? '^jsflow' + elseif char == ':' return cursor(0,match(' ' . strpart(getline('.'),0,col('.')),'.*\zs' . s:expr_case . '$')) + 1 && \ (expand('') !=# 'default' || !search('\S','bW') || getline('.')[col('.')-1] !~ '[,{]') endif - return stridx('-=~!<*+,/?^%|&([',char[-1:]) < 0 + return stridx('-=~!<*+,/?^%|&([',char) < 0 endif return 1 endfunction From 12a6f46c4bb323e970252c9d4b5fb9c7aadcfa3a Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Mon, 31 Oct 2016 19:42:33 -0700 Subject: [PATCH 17/35] alpha short circuiting --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 311ec08f..42e13644 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -124,7 +124,7 @@ function s:IsBlock(...) return char != '{' elseif syn =~? 'comment' return search('\/[/*]','bW') && s:IsBlock(l:ln) - elseif char =~# '\l' + elseif char =~# '\a' return index(split('return const let import export yield default delete var void typeof throw new in instanceof') \ , expand('')) < (0 + (line('.') != l:ln)) elseif char == '>' From b5a21109be91d35e1dccc53ba8046c3d5e329d15 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Mon, 31 Oct 2016 23:53:17 -0700 Subject: [PATCH 18/35] code minify --- indent/javascript.vim | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 42e13644..bd679ee7 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -156,13 +156,9 @@ function s:Balanced(lnum) let pos = match(l:line, '[][(){}]', 0) while pos != -1 if synIDattr(synID(a:lnum,pos + 1,0),'name') !~? s:syng_strcom - if stridx('[({',l:line[pos]) + 1 - let l:open += 1 - else - let l:open -= 1 - if l:open < 0 - return 0 - endif + let l:open += match(' ' . l:line[pos],'[[({]') + if l:open < 0 + return 0 endif endif let pos = match(l:line, '[][(){}]', pos + 1) From 4d60216106f9c170e0e75325d8611931fc10e6c6 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Tue, 1 Nov 2016 15:18:28 -0700 Subject: [PATCH 19/35] prevline = 0 at html --- indent/javascript.vim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index bd679ee7..a1283a37 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -142,7 +142,10 @@ endfunction function s:PrevCodeLine(lnum) let l:lnum = prevnonblank(a:lnum) while l:lnum - if synIDattr(synID(l:lnum,matchend(getline(l:lnum), '^\s*[^''"`]'),0),'name') !~? s:syng_strcom + let syn = synIDattr(synID(l:lnum,matchend(getline(l:lnum), '^\s*[^''"`]'),0),'name') + if syn =~? 'html' + return + elseif syn !~? s:syng_strcom return l:lnum endif let l:lnum = prevnonblank(l:lnum - 1) From 396829c383395178db37871b432c0768806919e4 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Wed, 2 Nov 2016 00:48:35 -0700 Subject: [PATCH 20/35] comment handling --- indent/javascript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index a1283a37..875b7799 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -75,7 +75,7 @@ endfunction " configurable regexes that define continuation lines, not including (, {, or [. let s:opfirst = '^' . get(g:,'javascript_opfirst', - \ '\%([<>,?^%|*&]\|\/[/*]\@!\|\([-.:+]\)\1\@!\|=>\@!\|in\%(stanceof\)\=\>\)') + \ '\%([<>,?^%|*/&]\|\([-.:+]\)\1\@!\|=>\@!\|in\%(stanceof\)\=\>\)') let s:continuation = get(g:,'javascript_continuation', \ '\%([<=,.?/*^%|&:]\|+\@\|\ Date: Thu, 3 Nov 2016 11:27:43 -0700 Subject: [PATCH 21/35] Refactoring (#693) --- indent/javascript.vim | 46 +++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 875b7799..54869dbc 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -63,6 +63,19 @@ else endfunction endif +function s:current_char() + return getline('.')[col('.')-1] +endfunction + +function s:token() + return s:current_char() =~ '\w' ? expand('') : s:current_char() +endfunction + +" NOTE: moves the cursor +function s:previous_token() + return search('\<\|[^[:alnum:]_$[:space:]]','bW') ? s:token() : '' +endfunction + function s:Trim(ln) let pline = substitute(getline(a:ln),'\s*$','','') let l:max = max([strridx(pline,'//'),strridx(pline,'/*'),0]) @@ -80,10 +93,15 @@ let s:continuation = get(g:,'javascript_continuation', \ '\%([<=,.?/*^%|&:]\|+\@\|\\)$')) + 1 || - \ cursor(a:lnum, match(' ' . a:text, ')$')) + 1 && - \ s:GetPair('(', ')', 'bW', s:skip_expr, 100) > 0 && - \ search('\C\<\%(for\%(\_s\+\%(await\|each\)\)\=\|if\|let\|w\%(hile\|ith\)\)\_s*\%#','bW') + if cursor(a:lnum, match(' ' . a:text, ')$')) + 1 && + \ s:GetPair('(', ')', 'bW', s:skip_expr, 100) > 0 + let token = s:previous_token() + if index(split('await each'),token) + 1 + return s:previous_token() ==# 'for' + endif + return index(split('for if let while with'),token) + 1 + endif + return cursor(a:lnum, match(' ' . a:text, '\%(\\)$\C')) + 1 endfunction function s:iscontOne(i,num,cont) @@ -94,7 +112,7 @@ function s:iscontOne(i,num,cont) while l:i >= l:num && (!l:cont || ind > pind) if indent(l:i) < ind " first line always true for !a:cont, false for !!a:cont if s:OneScope(l:i,s:Trim(l:i)) - if expand('') ==# 'while' && + if s:token() ==# 'while' && \ s:GetPair('\C\','\C\','bW','line2byte(line(".")) + col(".") <' \ . (line2byte(l:num) + b:js_cache[2]) . '||' \ . s:skip_expr . '|| !s:IsBlock()',100,l:num) > 0 @@ -105,10 +123,10 @@ function s:iscontOne(i,num,cont) elseif !l:cont break endif - let ind = indent(l:i) elseif !a:cont break endif + let ind = min([ind, indent(l:i)]) let l:i = s:PrevCodeLine(l:i - 1) endwhile return bL @@ -118,22 +136,20 @@ endfunction function s:IsBlock(...) let l:ln = get(a:000,0,line('.')) if search('\S','bW') - let char = getline('.')[col('.')-1] + let char = s:token() let syn = synIDattr(synID(line('.'),col('.')-(char == '{'),0),'name') if syn =~? '\%(xml\|jsx\)' return char != '{' elseif syn =~? 'comment' return search('\/[/*]','bW') && s:IsBlock(l:ln) - elseif char =~# '\a' - return index(split('return const let import export yield default delete var void typeof throw new in instanceof') - \ , expand('')) < (0 + (line('.') != l:ln)) elseif char == '>' return getline('.')[col('.')-2] == '=' || syn =~? '^jsflow' elseif char == ':' return cursor(0,match(' ' . strpart(getline('.'),0,col('.')),'.*\zs' . s:expr_case . '$')) + 1 && - \ (expand('') !=# 'default' || !search('\S','bW') || getline('.')[col('.')-1] !~ '[,{]') + \ (expand('') !=# 'default' || s:previous_token() !~ '[,{]') endif - return stridx('-=~!<*+,/?^%|&([',char) < 0 + return index(split('return const let import export yield default delete var void typeof throw new in instanceof' + \ . ' - = ~ ! < * + , / ? ^ % | & ( ['), char) < (0 + (line('.') != l:ln)) endif return 1 endfunction @@ -215,7 +231,7 @@ function GetJavascriptIndent() endif if idx + 1 - if idx == 2 && search('\S','bW',line('.')) && getline('.')[col('.')-1] == ')' + if idx == 2 && search('\S','bW',line('.')) && s:current_char() == ')' call s:GetPair('(',')','bW',s:skip_expr,200) endif return indent(line('.')) @@ -226,10 +242,10 @@ function GetJavascriptIndent() let [s:W, pline, isOp, stmt, bL, switch_offset] = [s:sw(), s:Trim(l:lnum),0,0,0,0] if num - if getline('.')[col('.')-1] == '{' + if s:current_char() == '{' if search(')\_s*\%#','bW') let stmt = 1 - if s:GetPair('(', ')', 'bW', s:skip_expr, 100) > 0 && search('\C\ 0 && s:previous_token() ==# 'switch' let switch_offset = &cino !~ ':' || !has('float') ? s:W : \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (&cino =~# '.*:[^,]*s' ? s:W : 1)) if l:line =~# '^' . s:expr_case From 01f7804267feb134f3b884b7a4612b126e6b6bb3 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Fri, 4 Nov 2016 15:04:53 -0700 Subject: [PATCH 22/35] keyword atom This is used by `\<` and `expand('')` --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 54869dbc..f4df091c 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -68,7 +68,7 @@ function s:current_char() endfunction function s:token() - return s:current_char() =~ '\w' ? expand('') : s:current_char() + return s:current_char() =~ '\k' ? expand('') : s:current_char() endfunction " NOTE: moves the cursor From 2ef9a9ca375f37c233000972f0c9e926db828417 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sat, 5 Nov 2016 14:43:40 -0700 Subject: [PATCH 23/35] refactoring block conditions (#695) --- indent/javascript.vim | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index f4df091c..c2e4af60 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: Octember 31, 2016 +" Last Change: November 5, 2016 " Only load this indent file when no other was loaded. if exists('b:did_indent') @@ -137,7 +137,7 @@ function s:IsBlock(...) let l:ln = get(a:000,0,line('.')) if search('\S','bW') let char = s:token() - let syn = synIDattr(synID(line('.'),col('.')-(char == '{'),0),'name') + let syn = char =~ '[{>/]' || l:ln != line('.') ? synIDattr(synID(line('.'),col('.')-(char == '{'),0),'name') : '' if syn =~? '\%(xml\|jsx\)' return char != '{' elseif syn =~? 'comment' @@ -241,20 +241,16 @@ function GetJavascriptIndent() let num = b:js_cache[1] let [s:W, pline, isOp, stmt, bL, switch_offset] = [s:sw(), s:Trim(l:lnum),0,0,0,0] - if num - if s:current_char() == '{' - if search(')\_s*\%#','bW') - let stmt = 1 - if s:GetPair('(', ')', 'bW', s:skip_expr, 100) > 0 && s:previous_token() ==# 'switch' - let switch_offset = &cino !~ ':' || !has('float') ? s:W : - \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (&cino =~# '.*:[^,]*s' ? s:W : 1)) - if l:line =~# '^' . s:expr_case - return indent(num) + switch_offset - endif - let stmt = pline !~# s:expr_case . '$' + if num + if s:current_char() == '{' && s:IsBlock() + let stmt = 1 + if s:current_char() == ')' && s:GetPair('(', ')', 'bW', s:skip_expr, 100) > 0 && s:previous_token() ==# 'switch' + let switch_offset = &cino !~ ':' || !has('float') ? s:W : + \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (&cino =~# '.*:[^,]*s' ? s:W : 1)) + if l:line =~# '^' . s:expr_case + return indent(num) + switch_offset endif - elseif s:IsBlock() - let stmt = 1 + let stmt = pline !~# s:expr_case . '$' endif endif else From 817215be5cdec9bee35ed1f1089bab32c46c4664 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 6 Nov 2016 13:51:08 -0800 Subject: [PATCH 24/35] more code cleaning --- indent/javascript.vim | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index c2e4af60..67c1df6b 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -241,23 +241,19 @@ function GetJavascriptIndent() let num = b:js_cache[1] let [s:W, pline, isOp, stmt, bL, switch_offset] = [s:sw(), s:Trim(l:lnum),0,0,0,0] - if num - if s:current_char() == '{' && s:IsBlock() - let stmt = 1 - if s:current_char() == ')' && s:GetPair('(', ')', 'bW', s:skip_expr, 100) > 0 && s:previous_token() ==# 'switch' - let switch_offset = &cino !~ ':' || !has('float') ? s:W : - \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (&cino =~# '.*:[^,]*s' ? s:W : 1)) - if l:line =~# '^' . s:expr_case - return indent(num) + switch_offset - endif - let stmt = pline !~# s:expr_case . '$' + if num && s:current_char() == '{' && s:IsBlock() + let stmt = 1 + if s:current_char() == ')' && s:GetPair('(', ')', 'bW', s:skip_expr, 100) > 0 && s:previous_token() ==# 'switch' + let switch_offset = &cino !~ ':' || !has('float') ? s:W : + \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (&cino =~# '.*:[^,]*s' ? s:W : 1)) + if l:line =~# '^' . s:expr_case + return indent(num) + switch_offset endif + let stmt = pline !~# s:expr_case . '$' endif - else - let stmt = 1 endif - if stmt + if stmt || !num call cursor(v:lnum,1) if l:line =~# '^while\>' && s:GetPair('\C\','\C\','bW',s:skip_expr . '|| !s:IsBlock()',100,num + 1) > 0 return indent(line('.')) From d23050e3061ecd1836165c38027245d0d17cb8a9 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 6 Nov 2016 14:08:08 -0800 Subject: [PATCH 25/35] return redundancies --- indent/javascript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 67c1df6b..bf1e7fbb 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -177,7 +177,7 @@ function s:Balanced(lnum) if synIDattr(synID(a:lnum,pos + 1,0),'name') !~? s:syng_strcom let l:open += match(' ' . l:line[pos],'[[({]') if l:open < 0 - return 0 + return endif endif let pos = match(l:line, '[][(){}]', pos + 1) @@ -206,7 +206,7 @@ function GetJavascriptIndent() endif let l:lnum = s:PrevCodeLine(v:lnum - 1) if !l:lnum - return 0 + return endif let l:line = substitute(substitute(l:line,'^\s*\%(\/\*.\{-}\*\/\s*\)*','',''),'^\/[/*].*','','') From eac13000f5998dc90d10452718fda18ab8aa9133 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 6 Nov 2016 14:11:20 -0800 Subject: [PATCH 26/35] another return --- indent/javascript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index bf1e7fbb..bdb1e159 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: November 5, 2016 +" Last Change: November 6, 2016 " Only load this indent file when no other was loaded. if exists('b:did_indent') @@ -116,7 +116,7 @@ function s:iscontOne(i,num,cont) \ s:GetPair('\C\','\C\','bW','line2byte(line(".")) + col(".") <' \ . (line2byte(l:num) + b:js_cache[2]) . '||' \ . s:skip_expr . '|| !s:IsBlock()',100,l:num) > 0 - return 0 + return endif let bL += s:W let [l:cont, l:i] = [0, line('.')] From 15905f20882b9ed2cddf6aeb9bdc1ebbaa3cabfa Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 6 Nov 2016 14:28:13 -0800 Subject: [PATCH 27/35] refactor,cleaning isblock --- indent/javascript.vim | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index bdb1e159..a2a1645b 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -135,23 +135,22 @@ endfunction " https://github.com/sweet-js/sweet.js/wiki/design#give-lookbehind-to-the-reader function s:IsBlock(...) let l:ln = get(a:000,0,line('.')) - if search('\S','bW') - let char = s:token() - let syn = char =~ '[{>/]' || l:ln != line('.') ? synIDattr(synID(line('.'),col('.')-(char == '{'),0),'name') : '' - if syn =~? '\%(xml\|jsx\)' - return char != '{' - elseif syn =~? 'comment' - return search('\/[/*]','bW') && s:IsBlock(l:ln) - elseif char == '>' - return getline('.')[col('.')-2] == '=' || syn =~? '^jsflow' - elseif char == ':' - return cursor(0,match(' ' . strpart(getline('.'),0,col('.')),'.*\zs' . s:expr_case . '$')) + 1 && - \ (expand('') !=# 'default' || s:previous_token() !~ '[,{]') - endif - return index(split('return const let import export yield default delete var void typeof throw new in instanceof' - \ . ' - = ~ ! < * + , / ? ^ % | & ( ['), char) < (0 + (line('.') != l:ln)) + let char = s:previous_token() + let syn = char =~ '[{>/]' || l:ln != line('.') ? synIDattr(synID(line('.'),col('.')-(char == '{'),0),'name') : '' + if char is '' + return 1 + elseif syn =~? '\%(xml\|jsx\)' + return char != '{' + elseif syn =~? 'comment' + return search('\/[/*]','bW') && s:IsBlock(l:ln) + elseif char == '>' + return getline('.')[col('.')-2] == '=' || syn =~? '^jsflow' + elseif char == ':' + return cursor(0,match(' ' . strpart(getline('.'),0,col('.')),'.*\zs' . s:expr_case . '$')) + 1 && + \ (expand('') !=# 'default' || s:previous_token() !~ '[,{]') endif - return 1 + return index(split('return const let import export yield default delete var void typeof throw new in instanceof' + \ . ' - = ~ ! < * + , / ? ^ % | & ( ['), char) < (0 + (line('.') != l:ln)) endfunction " Find line above 'lnum' that isn't empty, in a comment, or in a string. From 8a40889ba41741a07566d9320e6bd60bd73f9405 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 6 Nov 2016 20:38:25 -0800 Subject: [PATCH 28/35] skip any html --- indent/javascript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index a2a1645b..af2244b1 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -45,12 +45,12 @@ let s:syng_strcom = '\%(s\%(tring\|pecial\)\|comment\|regex\|doc\|template\)' let s:skip_expr = "synIDattr(synID(line('.'),col('.'),0),'name') =~? '".s:syng_strcom."'" function s:skip_func(lnum) if !s:free || search('`','nW',a:lnum) || search('\*\/','nW',a:lnum) - let s:free = !eval(s:skip_expr) + let s:free = !eval(s:skip_expr . '. "\\|html"') let s:looksyn = s:free ? line('.') : s:looksyn return !s:free endif let s:looksyn = line('.') - return (search('\/','nbW',s:looksyn) || search('[''"\\]','nW',s:looksyn)) && eval(s:skip_expr) + return (search('\/','nbW',s:looksyn) || search('[''"\\]','nW',s:looksyn)) && eval(s:skip_expr . '. "\\|html"') endfunction if has('reltime') From 6f3e6e9748675a04efd01a7be93b775e8f051ea0 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 6 Nov 2016 20:44:11 -0800 Subject: [PATCH 29/35] keep string type --- indent/javascript.vim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index af2244b1..8bfaeb98 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -40,17 +40,16 @@ endif let s:expr_case = '\<\%(\%(case\>\s*[^[:blank:]:].\{-}\)\|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\)' - " 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 || search('`','nW',a:lnum) || search('\*\/','nW',a:lnum) - let s:free = !eval(s:skip_expr . '. "\\|html"') + let s:free = !eval(s:skip_expr . " . '\\|html'") let s:looksyn = s:free ? line('.') : s:looksyn return !s:free endif let s:looksyn = line('.') - return (search('\/','nbW',s:looksyn) || search('[''"\\]','nW',s:looksyn)) && eval(s:skip_expr . '. "\\|html"') + return (search('\/','nbW',s:looksyn) || search('[''"\\]','nW',s:looksyn)) && eval(s:skip_expr . " . '\\|html'") endfunction if has('reltime') From bedb8cb2e67f42c0dffb92a3f32d81f5faa9679e Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Sun, 6 Nov 2016 22:15:22 -0800 Subject: [PATCH 30/35] cleaning --- indent/javascript.vim | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 8bfaeb98..be4203f0 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -37,13 +37,14 @@ else endfunction endif -let s:expr_case = '\<\%(\%(case\>\s*[^[:blank:]:].\{-}\)\|default\)\s*:\C' +let s:case_stmt = '\<\%(\%(case\>\s*[^[:blank:]:].\{-}\)\|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\)' " 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 || search('`','nW',a:lnum) || search('\*\/','nW',a:lnum) + if !s:free || search('`\|\%(\*\/\)','nW',a:lnum) let s:free = !eval(s:skip_expr . " . '\\|html'") let s:looksyn = s:free ? line('.') : s:looksyn return !s:free @@ -145,7 +146,7 @@ function s:IsBlock(...) elseif char == '>' return getline('.')[col('.')-2] == '=' || syn =~? '^jsflow' elseif char == ':' - return cursor(0,match(' ' . strpart(getline('.'),0,col('.')),'.*\zs' . s:expr_case . '$')) + 1 && + return cursor(0,match(' ' . strpart(getline('.'),0,col('.')),'.*\zs' . s:case_stmt . '$')) + 1 && \ (expand('') !=# 'default' || s:previous_token() !~ '[,{]') endif return index(split('return const let import export yield default delete var void typeof throw new in instanceof' @@ -244,10 +245,10 @@ function GetJavascriptIndent() if s:current_char() == ')' && s:GetPair('(', ')', 'bW', s:skip_expr, 100) > 0 && s:previous_token() ==# 'switch' let switch_offset = &cino !~ ':' || !has('float') ? s:W : \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (&cino =~# '.*:[^,]*s' ? s:W : 1)) - if l:line =~# '^' . s:expr_case + if l:line =~# '^' . s:case_stmt return indent(num) + switch_offset endif - let stmt = pline !~# s:expr_case . '$' + let stmt = pline !~# s:case_stmt . '$' endif endif From 8ac7badb3c8d38dd5b3a01b320cac2887a8e9902 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Mon, 7 Nov 2016 10:23:25 -0800 Subject: [PATCH 31/35] Remove all extra grouping (#697) --- indent/javascript.vim | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index be4203f0..a5f8cf0f 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -37,14 +37,14 @@ else endfunction endif -let s:case_stmt = '\<\%(\%(case\>\s*[^[:blank:]:].\{-}\)\|default\)\s*:\C' +let s:case_stmt = '\<\%(case\>\s*[^[:blank:]:].\{-}\|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\)' +let s:syng_strcom = 'string\|comment\|regex\|special\|doc\|template' " 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 || search('`\|\%(\*\/\)','nW',a:lnum) + if !s:free || search('`\|\*\/','nW',a:lnum) let s:free = !eval(s:skip_expr . " . '\\|html'") let s:looksyn = s:free ? line('.') : s:looksyn return !s:free @@ -79,7 +79,7 @@ endfunction function s:Trim(ln) let pline = substitute(getline(a:ln),'\s*$','','') let l:max = max([strridx(pline,'//'),strridx(pline,'/*'),0]) - while l:max && synIDattr(synID(a:ln, strlen(pline), 0), 'name') =~? '\%(comment\|doc\)' + while l:max && synIDattr(synID(a:ln, strlen(pline), 0), 'name') =~? 'comment\|doc' let pline = substitute(strpart(pline, 0, l:max),'\s*$','','') let l:max = max([strridx(pline,'//'),strridx(pline,'/*'),0]) endwhile @@ -139,7 +139,7 @@ function s:IsBlock(...) let syn = char =~ '[{>/]' || l:ln != line('.') ? synIDattr(synID(line('.'),col('.')-(char == '{'),0),'name') : '' if char is '' return 1 - elseif syn =~? '\%(xml\|jsx\)' + elseif syn =~? 'xml\|jsx' return char != '{' elseif syn =~? 'comment' return search('\/[/*]','bW') && s:IsBlock(l:ln) @@ -194,13 +194,13 @@ function GetJavascriptIndent() let syns = synIDattr(synID(v:lnum, 1, 0), 'name') " start with strings,comments,etc. - if syns =~? '\%(comment\|doc\)' + if syns =~? 'comment\|doc' if l:line =~ '^\s*\*' return cindent(v:lnum) elseif l:line !~ '^\s*\/' return -1 endif - elseif syns =~? '\%(string\|template\)' && l:line !~ '^[''"]' + elseif syns =~? 'string\|template' && l:line !~ '^[''"]' return -1 endif let l:lnum = s:PrevCodeLine(v:lnum - 1) From 74f6d46f7bfa0613cf9bc5799781ac41289e856c Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Mon, 7 Nov 2016 21:04:14 -0800 Subject: [PATCH 32/35] remove es6 semi-less do-while handling (#698) --- indent/javascript.vim | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index a5f8cf0f..83bc204e 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -112,12 +112,6 @@ function s:iscontOne(i,num,cont) while l:i >= l:num && (!l:cont || ind > pind) if indent(l:i) < ind " first line always true for !a:cont, false for !!a:cont if s:OneScope(l:i,s:Trim(l:i)) - if s:token() ==# 'while' && - \ s:GetPair('\C\','\C\','bW','line2byte(line(".")) + col(".") <' - \ . (line2byte(l:num) + b:js_cache[2]) . '||' - \ . s:skip_expr . '|| !s:IsBlock()',100,l:num) > 0 - return - endif let bL += s:W let [l:cont, l:i] = [0, line('.')] elseif !l:cont @@ -253,10 +247,6 @@ function GetJavascriptIndent() endif if stmt || !num - call cursor(v:lnum,1) - if l:line =~# '^while\>' && s:GetPair('\C\','\C\','bW',s:skip_expr . '|| !s:IsBlock()',100,num + 1) > 0 - return indent(line('.')) - endif let isOp = l:line =~# s:opfirst || pline =~# s:continuation let bL = s:iscontOne(l:lnum,num,isOp) let bL -= (bL && l:line[0] == '{') * s:W From d47868cad502ac31b681b29ae454f8815f76d9ce Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Mon, 7 Nov 2016 22:49:52 -0800 Subject: [PATCH 33/35] remove magic try anyone changing the magic setting will have a non-operable program anyway --- indent/javascript.vim | 7 ------- 1 file changed, 7 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 83bc204e..1ccc55fb 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -179,9 +179,6 @@ function s:Balanced(lnum) endfunction function GetJavascriptIndent() - try - let save_magic = &magic - set magic let b:js_cache = get(b:,'js_cache',[0,0,0]) " Get the current line. let l:line = getline(v:lnum) @@ -259,10 +256,6 @@ function GetJavascriptIndent() return indent(num) + s:W + switch_offset + bL endif return bL - - finally - let &magic = save_magic - endtry endfunction let &cpo = s:cpo_save From b0f562956984e70bfd09d30200da6a2340286bc5 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Tue, 8 Nov 2016 00:09:21 -0800 Subject: [PATCH 34/35] de-noising --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 1ccc55fb..a71a9b0d 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -37,7 +37,7 @@ else endfunction endif -let s:case_stmt = '\<\%(case\>\s*[^[:blank:]:].\{-}\|default\s*\):\C' +let s:case_stmt = '\<\%(case\>\s*[^ \t:].*\|default\s*\):\C' " Regex of syntax group names that are or delimit string or are comments. let s:syng_strcom = 'string\|comment\|regex\|special\|doc\|template' From 419f0d6a84fda49378257eb6464222ed7a9ea150 Mon Sep 17 00:00:00 2001 From: Chris Paul Date: Tue, 8 Nov 2016 09:26:33 -0800 Subject: [PATCH 35/35] accurate collection (#699) --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index a71a9b0d..f68bdd85 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -73,7 +73,7 @@ endfunction " NOTE: moves the cursor function s:previous_token() - return search('\<\|[^[:alnum:]_$[:space:]]','bW') ? s:token() : '' + return search('\<\|[][`^!"%-/:-?{-~]','bW') ? s:token() : '' endfunction function s:Trim(ln)