From ebaf495a51e01b1deb0da7363814b9e380a7f348 Mon Sep 17 00:00:00 2001 From: bounceme Date: Fri, 3 Jun 2016 20:17:08 -0700 Subject: [PATCH 01/23] dollar sign as property name https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors#Dot_notation --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 53cd0acd..82d0c082 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -383,7 +383,7 @@ function GetJavascriptIndent() if parlnum > 0 return !s:Match(parlnum, s:operator_first) ? indent(lnum) + s:sw() : indent(parlnum) end - elseif line !~ s:line_pre . ',\s*\%(\%(\([''"]\).*\1\)\|\%(\h\w*\)\)\s*:.*' . s:line_term && + elseif line !~ s:line_pre . ',\s*\%(\%(\([''"]\).*\1\)\|\%(\h\|\$\w*\)\)\s*:.*' . s:line_term && \ synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsbracket\|jsparen' " otherwise, indent 1 level return indent(lnum) + s:sw() From 7d519fada3b678479dc3f62e43cbcb6902f93b07 Mon Sep 17 00:00:00 2001 From: bounceme Date: Fri, 3 Jun 2016 20:20:06 -0700 Subject: [PATCH 02/23] 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 82d0c082..a792a411 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -383,7 +383,7 @@ function GetJavascriptIndent() if parlnum > 0 return !s:Match(parlnum, s:operator_first) ? indent(lnum) + s:sw() : indent(parlnum) end - elseif line !~ s:line_pre . ',\s*\%(\%(\([''"]\).*\1\)\|\%(\h\|\$\w*\)\)\s*:.*' . s:line_term && + elseif line !~ s:line_pre . ',\s*\%(\%(\([''"]\).*\1\)\|\%(\h\|\$\%(\$\|\w\)*\)\)\s*:.*' . s:line_term && \ synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsbracket\|jsparen' " otherwise, indent 1 level return indent(lnum) + s:sw() From 27d2b06713e6bd9a989b88d6b7f5739bd7df62ab Mon Sep 17 00:00:00 2001 From: bounceme Date: Fri, 3 Jun 2016 20:25:23 -0700 Subject: [PATCH 03/23] 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 a792a411..891d37d5 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -383,7 +383,7 @@ function GetJavascriptIndent() if parlnum > 0 return !s:Match(parlnum, s:operator_first) ? indent(lnum) + s:sw() : indent(parlnum) end - elseif line !~ s:line_pre . ',\s*\%(\%(\([''"]\).*\1\)\|\%(\h\|\$\%(\$\|\w\)*\)\)\s*:.*' . s:line_term && + elseif line !~ s:line_pre . ',\s*\%(\%(\([''"]\).*\1\)\|\%(\%(\h\|\$\)\%(\$\|\w\)*\)\)\s*:.*' . s:line_term && \ synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsbracket\|jsparen' " otherwise, indent 1 level return indent(lnum) + s:sw() From 1f0cb8bac3764219c2851c40da0e89de29505901 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sat, 4 Jun 2016 01:10:00 -0700 Subject: [PATCH 04/23] 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 891d37d5..29b95e64 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -383,7 +383,7 @@ function GetJavascriptIndent() if parlnum > 0 return !s:Match(parlnum, s:operator_first) ? indent(lnum) + s:sw() : indent(parlnum) end - elseif line !~ s:line_pre . ',\s*\%(\%(\([''"]\).*\1\)\|\%(\%(\h\|\$\)\%(\$\|\w\)*\)\)\s*:.*' . s:line_term && + elseif line !~ s:line_pre . ',\s*\%(\%(\([''"]\)\%(\%(\\\\\)*\%(\\[''"rbvtn]\)*\|[^\\]\)*\1\)\|\%(\%(\h\|\$\)\%(\$\|\w\)*\)\)\s*:.*' . s:line_term && \ synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsbracket\|jsparen' " otherwise, indent 1 level return indent(lnum) + s:sw() From 297de15fa4a449f2b1b47bcef53acb066d6040e7 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sat, 4 Jun 2016 11:01:16 -0700 Subject: [PATCH 05/23] Update javascript.vim --- indent/javascript.vim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 29b95e64..6d9440b4 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -383,9 +383,11 @@ function GetJavascriptIndent() if parlnum > 0 return !s:Match(parlnum, s:operator_first) ? indent(lnum) + s:sw() : indent(parlnum) end - elseif line !~ s:line_pre . ',\s*\%(\%(\([''"]\)\%(\%(\\\\\)*\%(\\[''"rbvtn]\)*\|[^\\]\)*\1\)\|\%(\%(\h\|\$\)\%(\$\|\w\)*\)\)\s*:.*' . s:line_term && + elseif line !~ s:line_pre . + \ ',\s*\%(\%(\([''"]\)\%(\%(\\\\\)*\%(\\[''"rbvtn]\)*\|[^\\]\)*\1\)\|\%(\%(\h\|\$\)\%(\$\|\w\)*\)\)\s*:.*' . + \ s:line_term && \ synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsbracket\|jsparen' - " otherwise, indent 1 level + " otherwise, if not in an key/val;array item;param, indent 1 level return indent(lnum) + s:sw() end From e701298fc99164d787b683c95aec6a9de27841da Mon Sep 17 00:00:00 2001 From: bounceme Date: Sat, 4 Jun 2016 12:06:00 -0700 Subject: [PATCH 06/23] 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 6d9440b4..21ebeea3 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -384,7 +384,7 @@ function GetJavascriptIndent() return !s:Match(parlnum, s:operator_first) ? indent(lnum) + s:sw() : indent(parlnum) end elseif line !~ s:line_pre . - \ ',\s*\%(\%(\([''"]\)\%(\%(\\\\\)*\%(\\[''"rbvtn]\)*\|[^\\]\)*\1\)\|\%(\%(\h\|\$\)\%(\$\|\w\)*\)\)\s*:.*' . + \ ',\s*\%(\%(\([''"]\)\%(\%(\\\\\)*\%(\\[''"rbvtnxu\o]\)*\|[^\\]\)*\1\)\|\%(\%(\h\|\$\)\%(\$\|\w\)*\)\)\s*:.*' . \ s:line_term && \ synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsbracket\|jsparen' " otherwise, if not in an key/val;array item;param, indent 1 level From 4b6d0f627bcba79acb5313d8825d3f0b16b24b68 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sat, 4 Jun 2016 20:19:35 -0700 Subject: [PATCH 07/23] basic computed property support and getter/setter --- indent/javascript.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 21ebeea3..2c69196f 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -384,7 +384,8 @@ function GetJavascriptIndent() return !s:Match(parlnum, s:operator_first) ? indent(lnum) + s:sw() : indent(parlnum) end elseif line !~ s:line_pre . - \ ',\s*\%(\%(\([''"]\)\%(\%(\\\\\)*\%(\\[''"rbvtnxu\o]\)*\|[^\\]\)*\1\)\|\%(\%(\h\|\$\)\%(\$\|\w\)*\)\)\s*:.*' . + \ ',\s*\%(\%(\%(\%(\([''"]\)\%(\%(\\\\\)*\%(\\[''"rbvtnxu\o]\)*\|[^\\]\)*\1\)\|\%(\[.*\]\)\|\%(\%(\h\|\$\)\%(\$\|\w\)*\)\)\s*:.*\)' . + \ '\|\%([gs]et\>\)\s*\%(\%(\[.*\]\)\|\%(\%(\h\|\$\)\%(\$\|\w\)*\)\)\s*(.*\)' . \ s:line_term && \ synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsbracket\|jsparen' " otherwise, if not in an key/val;array item;param, indent 1 level From a54babb58af6ef81bb5b2e936598e5d7e9481eb0 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sun, 5 Jun 2016 01:20:51 -0700 Subject: [PATCH 08/23] 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 2c69196f..efee83f8 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -384,7 +384,7 @@ function GetJavascriptIndent() return !s:Match(parlnum, s:operator_first) ? indent(lnum) + s:sw() : indent(parlnum) end elseif line !~ s:line_pre . - \ ',\s*\%(\%(\%(\%(\([''"]\)\%(\%(\\\\\)*\%(\\[''"rbvtnxu\o]\)*\|[^\\]\)*\1\)\|\%(\[.*\]\)\|\%(\%(\h\|\$\)\%(\$\|\w\)*\)\)\s*:.*\)' . + \ ',\s*\%(\%(\%(\%(\([''"]\)\%(\%(\\\\\)*\%(\\[''"rbvtnxu0-7]\)*\|[^\\]\)*\1\)\|\%(\[.*\]\)\|\%(\%(\h\|\$\)\%(\$\|\w\)*\)\)\s*:.*\)' . \ '\|\%([gs]et\>\)\s*\%(\%(\[.*\]\)\|\%(\%(\h\|\$\)\%(\$\|\w\)*\)\)\s*(.*\)' . \ s:line_term && \ synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsbracket\|jsparen' From b8a50f06b81e3fc17371d9a73145547c3da7a126 Mon Sep 17 00:00:00 2001 From: bounceme Date: Mon, 6 Jun 2016 22:27:19 -0700 Subject: [PATCH 09/23] final touches --- indent/javascript.vim | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index efee83f8..3888c475 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -51,10 +51,7 @@ let s:syng_strcom = '\%(string\|regex\|comment\|template\)\c' let s:syng_string = 'regex\c' " Regex of syntax group names that are strings or documentation. -let s:syng_multiline = '\%(comment\|doc\)\c' - -" Regex of syntax group names that are line comment. -let s:syng_linecom = 'linecomment\c' +let s:syng_comment = '\%(comment\|doc\)\c' " Expression used to check whether we should skip a match with searchpair(). let s:skip_expr = "synIDattr(synID(line('.'),col('.'),1),'name') =~ '".s:syng_strcom."'" @@ -114,13 +111,8 @@ function s:IsInString(lnum, col) endfunction " Check if the character at lnum:col is inside a multi-line comment. -function s:IsInMultilineComment(lnum, col) - return !s:IsLineComment(a:lnum, a:col) && synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_multiline -endfunction - -" Check if the character at lnum:col is a line comment. -function s:IsLineComment(lnum, col) - return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_linecom +function s:IsInComment(lnum, col) + return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_comment endfunction " Find line above 'lnum' that isn't empty, in a comment, or in a string. @@ -129,9 +121,9 @@ function s:PrevNonBlankNonString(lnum) while lnum > 0 let line = getline(lnum) let com = match(line, '\*\/') + 1 - if s:IsInMultilineComment(lnum, com) + if s:IsInComment(lnum, com) call cursor(lnum, com) - let parlnum = search('\/\*', 'nbW') + let parlnum = search('\%(\/\/.*\)\@ 0 let lnum = parlnum end @@ -338,7 +330,7 @@ function GetJavascriptIndent() endif " If we are in a multi-line comment, cindent does the right thing. - if s:IsInMultilineComment(v:lnum, 1) && line !~ '^\/\*' + if line !~ '^\%(\/\*\|\s*\/\/\)' && s:IsInComment(v:lnum, 1) return cindent(v:lnum) endif @@ -376,18 +368,14 @@ function GetJavascriptIndent() return indent(lnum) end let counts = s:LineHasOpeningBrackets(lnum) - if counts[0] == '2' || counts[1] == '2' || counts[2] == '2' + if counts =~ '2' call cursor(lnum, 1) " Search for the opening tag let parlnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0) if parlnum > 0 return !s:Match(parlnum, s:operator_first) ? indent(lnum) + s:sw() : indent(parlnum) end - elseif line !~ s:line_pre . - \ ',\s*\%(\%(\%(\%(\([''"]\)\%(\%(\\\\\)*\%(\\[''"rbvtnxu0-7]\)*\|[^\\]\)*\1\)\|\%(\[.*\]\)\|\%(\%(\h\|\$\)\%(\$\|\w\)*\)\)\s*:.*\)' . - \ '\|\%([gs]et\>\)\s*\%(\%(\[.*\]\)\|\%(\%(\h\|\$\)\%(\$\|\w\)*\)\)\s*(.*\)' . - \ s:line_term && - \ synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsbracket\|jsparen' + elseif synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsarray\|jsparen\|jsobject' " otherwise, if not in an key/val;array item;param, indent 1 level return indent(lnum) + s:sw() end @@ -403,7 +391,7 @@ function GetJavascriptIndent() return indent(mnum) - s:sw() end elseif s:Match(lnum, s:operator_first) - if counts[0] != '1' && counts[1] != '1' && counts[2] != '1' + if counts !~ '1' return indent(lnum) - s:sw() end end @@ -415,7 +403,8 @@ function GetJavascriptIndent() " If the line is empty and the previous nonblank line was a multi-line " comment, use that comment's indent. Deduct one char to account for the " space in ' */'. - if line =~ '^\s*$' && s:IsInMultilineComment(prevline, 1) + if line =~ '^\s*$' && getline(prevline) !~ '\%(\%(^\s*\/\/\|\/\*\).*\)\@ 0 return indent(s:GetMSL(parlnum, 0)) end - elseif counts[1] == '1' || counts[2] == '1' || counts[0] == '1' || s:Onescope(lnum) + elseif counts =~ '1' || s:Onescope(lnum) return ind + s:sw() else call cursor(v:lnum, vcol) @@ -505,7 +494,7 @@ function! Fixedgq(lnum, count) endif " This gq is only meant to do code with strings, not comments - if s:IsLineComment(a:lnum, l:first_char) || s:IsInMultilineComment(a:lnum, l:first_char) + if s:IsLineComment(a:lnum, l:first_char) || s:IsInComment(a:lnum, l:first_char) return 1 endif From 0350c76e668ebddcaf27e109d7f43859eda9769e Mon Sep 17 00:00:00 2001 From: bounceme Date: Mon, 6 Jun 2016 22:30:13 -0700 Subject: [PATCH 10/23] 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 3888c475..fa952b18 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -494,7 +494,7 @@ function! Fixedgq(lnum, count) endif " This gq is only meant to do code with strings, not comments - if s:IsLineComment(a:lnum, l:first_char) || s:IsInComment(a:lnum, l:first_char) + if s:IsInComment(a:lnum, l:first_char) return 1 endif From 287927a793986ac76482439fdda55478d358c802 Mon Sep 17 00:00:00 2001 From: bounceme Date: Tue, 7 Jun 2016 00:20:04 -0700 Subject: [PATCH 11/23] 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 fa952b18..0025a3cb 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -120,7 +120,7 @@ function s:PrevNonBlankNonString(lnum) let lnum = prevnonblank(a:lnum) while lnum > 0 let line = getline(lnum) - let com = match(line, '\*\/') + 1 + let com = match(line, '\%(\/\*.*\)\@ Date: Tue, 7 Jun 2016 10:51:46 -0700 Subject: [PATCH 12/23] 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 0025a3cb..8e2dc3d1 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -45,7 +45,7 @@ let s:line_pre = '^\s*\%(\/\*.*\*\/\s*\)*' let s:js_keywords = s:line_pre . '\%(break\|import\|export\|catch\|const\|continue\|debugger\|delete\|do\|else\|finally\|for\|function\|if\|in\|instanceof\|let\|new\|return\|switch\|this\|throw\|try\|typeof\|var\|void\|while\|with\)\>\C' let s:expr_case = s:line_pre . '\%(case\s\+[^\:]*\|default\)\s*:\s*\C' " Regex of syntax group names that are or delimit string or are comments. -let s:syng_strcom = '\%(string\|regex\|comment\|template\)\c' +let s:syng_strcom = '\%(string\|regex\|special\|comment\|template\)\c' " Regex of syntax group names that are strings. let s:syng_string = 'regex\c' From e638cb2717f74ac2a342995b04455458775dd62e Mon Sep 17 00:00:00 2001 From: bounceme Date: Wed, 8 Jun 2016 22:38:28 -0700 Subject: [PATCH 13/23] other updates --- indent/javascript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 8e2dc3d1..18dfdd5a 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -16,7 +16,7 @@ setlocal nosmartindent " Now, set up our indentation expression and keys that trigger it. setlocal indentexpr=GetJavascriptIndent() setlocal formatexpr=Fixedgq(v:lnum,v:count) -setlocal indentkeys=0{,0},0),0],0\,:,!^F,o,O,e +setlocal indentkeys=0{,0},0),0],0\,*,:,!^F,o,O,e setlocal cinoptions+=j1,J1 " Only define the function once. @@ -127,7 +127,7 @@ function s:PrevNonBlankNonString(lnum) if parlnum > 0 let lnum = parlnum end - elseif line !~ '^' . s:line_term + elseif line !~ '^' . s:line_term && !s:IsInStringOrComment(lnum,1) break endif let lnum = prevnonblank(lnum - 1) From 640f420e17109e4375d0db834e91f2410d9c5bf4 Mon Sep 17 00:00:00 2001 From: bounceme Date: Thu, 9 Jun 2016 14:55:54 -0700 Subject: [PATCH 14/23] Update javascript.vim --- indent/javascript.vim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 18dfdd5a..23a299b0 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -330,7 +330,7 @@ function GetJavascriptIndent() endif " If we are in a multi-line comment, cindent does the right thing. - if line !~ '^\%(\/\*\|\s*\/\/\)' && s:IsInComment(v:lnum, 1) + if (line !~ '^\%(\/\*\|\s*\/\/\)' && s:IsInComment(v:lnum, 1)) || line =~ '\*\/\s*$' return cindent(v:lnum) endif @@ -375,7 +375,7 @@ function GetJavascriptIndent() if parlnum > 0 return !s:Match(parlnum, s:operator_first) ? indent(lnum) + s:sw() : indent(parlnum) end - elseif synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsarray\|jsparen\|jsobject' + elseif synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsbracket\|jsparen\|jsobject' " otherwise, if not in an key/val;array item;param, indent 1 level return indent(lnum) + s:sw() end @@ -433,12 +433,12 @@ function GetJavascriptIndent() " add indent depending on the bracket type. if s:Match(lnum, '[[({})\]]') let counts = s:LineHasOpeningBrackets(lnum) - if counts[0] == '2' || (counts[1] == '2' && !s:Match(lnum, s:line_pre . '}')) || - \ (counts[2] == '2' && !s:Match(lnum, s:line_pre . ']')) + if counts[0] == '2' || (counts[1] == '2') || + \ (counts[2] == '2') call cursor(lnum, 1) " Search for the opening tag let parlnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0) - if parlnum > 0 + if parlnum > 0 && !s:InMultiVarStatement(parlnum,0,0) return indent(s:GetMSL(parlnum, 0)) end elseif counts =~ '1' || s:Onescope(lnum) From b40329f90f61d5cb7279e7b072d153eaf53557b1 Mon Sep 17 00:00:00 2001 From: bounceme Date: Thu, 9 Jun 2016 15:22:11 -0700 Subject: [PATCH 15/23] 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 23a299b0..c3afe591 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -423,7 +423,7 @@ function GetJavascriptIndent() " If the previous line ended with a block opening, add a level of indent. if s:Match(lnum, s:block_regex) - return s:InMultiVarStatement(lnum, 0, 0) ? indent(lnum) + s:sw() : indent(s:GetMSL(lnum, 0)) + s:sw() + return indent(lnum) + s:sw() endif " Set up variables for current line. From f492dc6f19c3b259c5a4bf0c743ba324587c0090 Mon Sep 17 00:00:00 2001 From: bounceme Date: Thu, 9 Jun 2016 15:30:23 -0700 Subject: [PATCH 16/23] 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 c3afe591..ee2b1752 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -330,7 +330,7 @@ function GetJavascriptIndent() endif " If we are in a multi-line comment, cindent does the right thing. - if (line !~ '^\%(\/\*\|\s*\/\/\)' && s:IsInComment(v:lnum, 1)) || line =~ '\*\/\s*$' + if line !~ '^\%(\/\*\|\s*\/\/\)' && s:IsInComment(v:lnum, 1) return cindent(v:lnum) endif From 0e5a745ad122cbeaab2baa4b4fd5ac8fcf16164f Mon Sep 17 00:00:00 2001 From: bounceme Date: Thu, 9 Jun 2016 19:27:18 -0700 Subject: [PATCH 17/23] Update javascript.vim --- indent/javascript.vim | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index ee2b1752..96ecf40e 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -347,19 +347,17 @@ function GetJavascriptIndent() " If we got a closing bracket on an empty line, find its match and indent " according to it. For parentheses we indent to its column - 1, for the " others we indent to the containing line's MSL's level. Return -1 if fail. + let lnum = s:PrevNonBlankNonString(v:lnum - 1) let col = matchend(line, s:line_pre . '[]})]') if col > 0 && !s:IsInStringOrComment(v:lnum, col) call cursor(v:lnum, col) - - let parlnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0) if parlnum > 0 - let ind = s:InMultiVarStatement(parlnum, 0, 0) ? indent(parlnum) : indent(s:GetMSL(parlnum, 0)) + let ind = indent(parlnum) endif return ind endif - let lnum = s:PrevNonBlankNonString(v:lnum - 1) " If line starts with an operator... if (line =~ s:operator_first) @@ -433,8 +431,7 @@ function GetJavascriptIndent() " add indent depending on the bracket type. if s:Match(lnum, '[[({})\]]') let counts = s:LineHasOpeningBrackets(lnum) - if counts[0] == '2' || (counts[1] == '2') || - \ (counts[2] == '2') + if counts =~ '2' call cursor(lnum, 1) " Search for the opening tag let parlnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0) From 601957c4ba7b525bd8fb02792f579c1ba9f3291a Mon Sep 17 00:00:00 2001 From: bounceme Date: Fri, 10 Jun 2016 00:01:57 -0700 Subject: [PATCH 18/23] 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 96ecf40e..c72b8b3c 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -353,7 +353,7 @@ function GetJavascriptIndent() call cursor(v:lnum, col) let parlnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0) if parlnum > 0 - let ind = indent(parlnum) + let ind = s:InMultiVarStatement(parlnum, 0, 0) ? indent(parlnum) : indent(s:GetMSL(parlnum, 0)) endif return ind endif From b49a639ca7d5d68317044abf48ce5a76e7ddd639 Mon Sep 17 00:00:00 2001 From: bounceme Date: Fri, 10 Jun 2016 00:21:01 -0700 Subject: [PATCH 19/23] 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 c72b8b3c..e54381b1 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -347,7 +347,6 @@ function GetJavascriptIndent() " If we got a closing bracket on an empty line, find its match and indent " according to it. For parentheses we indent to its column - 1, for the " others we indent to the containing line's MSL's level. Return -1 if fail. - let lnum = s:PrevNonBlankNonString(v:lnum - 1) let col = matchend(line, s:line_pre . '[]})]') if col > 0 && !s:IsInStringOrComment(v:lnum, col) call cursor(v:lnum, col) @@ -358,6 +357,7 @@ function GetJavascriptIndent() return ind endif + let lnum = s:PrevNonBlankNonString(v:lnum - 1) " If line starts with an operator... if (line =~ s:operator_first) From 4ea6b2b7e7904f67c01f6d091c3f2bf779b4dae5 Mon Sep 17 00:00:00 2001 From: bounceme Date: Fri, 10 Jun 2016 16:09:46 -0700 Subject: [PATCH 20/23] Update javascript.vim --- indent/javascript.vim | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index e54381b1..98e76d09 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -145,18 +145,17 @@ function s:GetMSL(lnum, in_one_line_scope) " Otherwise, terminate search as we have found our MSL already. let line = getline(lnum) let line2 = getline(msl) - let col2 = matchend(line2, ')') if ((s:Match(lnum,s:continuation_regex) || s:Match(lnum, s:comma_last)) && \ !s:Match(lnum, s:expr_case)) || s:IsInString(lnum, strlen(line)) let msl = lnum - - " if there are more closing brackets, continue from the line which has the matching opening bracket - elseif col2 > 0 && !s:IsInStringOrComment(msl, col2) && s:LineHasOpeningBrackets(msl)[0] == '2' && !a:in_one_line_scope - call cursor(msl, 1) - if s:lookForParens('(', ')', 'bW', 0) > 0 - let lnum = line('.') - let msl = lnum - endif + if s:Match(lnum,'^\s*[]})]') && !a:in_one_line_scope + call cursor(lnum,1) + let parlnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0) + if parlnum > 0 + let lnum = parlnum + continue + end + end else @@ -421,7 +420,7 @@ function GetJavascriptIndent() " If the previous line ended with a block opening, add a level of indent. if s:Match(lnum, s:block_regex) - return indent(lnum) + s:sw() + return s:InMultiVarStatement(lnum, 0, 0) ? indent(lnum) + s:sw() : indent(s:GetMSL(lnum, 0)) + s:sw() endif " Set up variables for current line. From 5d5a208b8f85812ad54850478c7324ab1aa63a63 Mon Sep 17 00:00:00 2001 From: bounceme Date: Fri, 10 Jun 2016 20:18:15 -0700 Subject: [PATCH 21/23] only use a c style when not in a block --- indent/javascript.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 98e76d09..a8be6b50 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -322,6 +322,8 @@ function GetJavascriptIndent() let line = getline(v:lnum) " previous nonblank line number let prevline = prevnonblank(v:lnum - 1) + " previous line of code + let lnum = s:PrevNonBlankNonString(v:lnum - 1) " to not change multiline string values if line !~ '^[''"`]' && synIDattr(synID(v:lnum, 1, 1), 'name') =~? 'string\|template' @@ -334,7 +336,7 @@ function GetJavascriptIndent() endif " single opening bracket will assume you want a c style of indenting - if s:Match(v:lnum, s:line_pre . '{' . s:line_term) + if s:Match(v:lnum, s:line_pre . '{' . s:line_term) && !s:Match(lnum,s:block_regex) return cindent(v:lnum) endif @@ -356,7 +358,6 @@ function GetJavascriptIndent() return ind endif - let lnum = s:PrevNonBlankNonString(v:lnum - 1) " If line starts with an operator... if (line =~ s:operator_first) From 6ffad04c87441874211a948cc37230eb09b55781 Mon Sep 17 00:00:00 2001 From: bounceme Date: Fri, 10 Jun 2016 22:23:05 -0700 Subject: [PATCH 22/23] additional fixes to last commit --- indent/javascript.vim | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index a8be6b50..47d903b2 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -336,7 +336,8 @@ function GetJavascriptIndent() endif " single opening bracket will assume you want a c style of indenting - if s:Match(v:lnum, s:line_pre . '{' . s:line_term) && !s:Match(lnum,s:block_regex) + if s:Match(v:lnum, s:line_pre . '{' . s:line_term) && !s:Match(lnum,s:block_regex) && + \ !s:Match(lnum,s:comma_last) return cindent(v:lnum) endif @@ -371,7 +372,9 @@ function GetJavascriptIndent() " Search for the opening tag let parlnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0) if parlnum > 0 - return !s:Match(parlnum, s:operator_first) ? indent(lnum) + s:sw() : indent(parlnum) + return !s:Match(parlnum, s:operator_first) && + \ synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsbracket\|jsparen\|jsobject' ? + \ indent(lnum) + s:sw() : indent(parlnum) end elseif synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsbracket\|jsparen\|jsobject' " otherwise, if not in an key/val;array item;param, indent 1 level From 219cdd4a6a065fcced01883fcefa07a68e1c492e Mon Sep 17 00:00:00 2001 From: bounceme Date: Sat, 11 Jun 2016 14:28:40 -0700 Subject: [PATCH 23/23] 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 47d903b2..84d69690 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -148,7 +148,7 @@ function s:GetMSL(lnum, in_one_line_scope) if ((s:Match(lnum,s:continuation_regex) || s:Match(lnum, s:comma_last)) && \ !s:Match(lnum, s:expr_case)) || s:IsInString(lnum, strlen(line)) let msl = lnum - if s:Match(lnum,'^\s*[]})]') && !a:in_one_line_scope + if s:Match(lnum, s:line_pre . '[]})]') && !a:in_one_line_scope call cursor(lnum,1) let parlnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0) if parlnum > 0