From 48c0a5498ebd8d639dad13afc8a92feeac7383c6 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sat, 30 Jul 2016 19:31:54 -0700 Subject: [PATCH 1/4] remove line comment appended to code --- indent/javascript.vim | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 618105f4..1b63a313 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -1,9 +1,9 @@ " Vim indent file " Language: Javascript -" Maintainer: vim-javascript community -" URL: https://github.com/pangloss/vim-javascript +" Maintainer: vim-javascript community +" URL: https://github.com/pangloss/vim-javascript " Acknowledgement: Based off of vim-ruby maintained by Nikolai Weibull http://vim-ruby.rubyforge.org -" Last Change: July 29, 2016 +" Last Change: July 30, 2016 " Only load this indent file when no other was loaded. if exists("b:did_indent") @@ -57,7 +57,7 @@ func s:lookForParens(start,end,flags,time) endtry endfunc -let s:line_term = '\s*\%(\/\*.*\*\/\s*\)*\%(:\@' . (a:add ? '\|\ -1 && + \ cursor(line('.'),match(s:Stripline(getline(line('.'))), ')' . s:line_term))>-1) || \ cursor(a:lnum, match(a:text, ')' . s:line_term)) > -1) && \ s:lookForParens('(', ')', 'cbW', 100) > 0 && \ search((a:add ? '\%(function\*\|[A-Za-z_$][0-9A-Za-z_$]*\)\C' : @@ -82,6 +83,11 @@ endfunction " Auxiliary Functions {{{2 +" strip line of comment +func s:StripLine(c) + return substitute(a:c, '\%(:\@ 0 ? lnum : -1 endfunction " Check if line 'lnum' has more opening brackets than closing ones. @@ -142,7 +148,9 @@ function GetJavascriptIndent() return cindent(v:lnum) endif let lnum = s:PrevCodeLine(v:lnum - 1) - if lnum == 0 + let pline = s:StripLine(getline(lnum)) + let line = s:StripLine(line) + if lnum <= 0 return 0 endif @@ -181,12 +189,12 @@ function GetJavascriptIndent() if line =~ s:line_pre . '[])}]' return indent(num) end - let inb = num == 0 ? 1 : s:Onescope(num, strpart(getline(num),0,b:js_cache[2] - 1),1) + let inb = num == 0 ? 1 : s:Onescope(num, s:StripLine(strpart(getline(num),0,b:js_cache[2] - 1)),1) let switch_offset = (!inb || num == 0) || expand("") != 'switch' ? 0 : &cino !~ ':' || !has('float') ? s:sw() : \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (match(&cino,'.*:\zs[^,]*s') ? s:sw() : 1)) if ((line =~ g:javascript_opfirst || - \ (getline(lnum) =~ g:javascript_continuation && getline(lnum) !~ s:expr_case)) && - \ inb) || (s:Onescope(lnum,getline(lnum),0) && line !~ s:line_pre . '{') + \ (pline =~ g:javascript_continuation && pline !~ s:expr_case)) && + \ inb) || (s:Onescope(lnum,pline,0) && line !~ s:line_pre . '{') return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset elseif num > 0 return indent(num) + s:sw() + switch_offset From 2ee75d0d90b56d94a1f617e9646798f47956f420 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sat, 30 Jul 2016 21:20:40 -0700 Subject: [PATCH 2/4] Update javascript.vim --- indent/javascript.vim | 44 +++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 1b63a313..a133435d 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -8,7 +8,7 @@ " Only load this indent file when no other was loaded. if exists("b:did_indent") finish -endif +end let b:did_indent = 1 " Now, set up our indentation expression and keys that trigger it. @@ -22,7 +22,7 @@ let b:undo_indent = 'setlocal indentexpr< indentkeys< cinoptions<' " Only define the function once. if exists("*GetJavascriptIndent") finish -endif +end let s:cpo_save = &cpo set cpo&vim @@ -36,7 +36,7 @@ else func s:sw() return &sw endfunc -endif +end let s:line_pre = '^\s*\%(\/\*.*\*\/\s*\)*' let s:expr_case = s:line_pre . '\%(\%(case\>.*\)\|default\)\s*:\C' @@ -62,15 +62,15 @@ let s:line_term = '\s*\%(\/\*.*\*\/\s*\)*$' " configurable regexes that define continuation lines, not including (, {, or [. if !exists('g:javascript_opfirst') let g:javascript_opfirst = '\%([<>,:?^%]\|\([-/.+]\)\%(\1\|\*\|\/\)\@!\|\*\/\@!\|=>\@!\||\|&\|in\%(stanceof\)\=\>\)\C' -endif +end let g:javascript_opfirst = s:line_pre . g:javascript_opfirst if !exists('g:javascript_continuation') let g:javascript_continuation = '\%([<*,.?:^%]\|+\@\|\*\@' . (a:add ? '\|\ -1 && \ cursor(line('.'),match(s:Stripline(getline(line('.'))), ')' . s:line_term))>-1) || @@ -79,7 +79,7 @@ function s:Onescope(lnum,text,add) \ search((a:add ? '\%(function\*\|[A-Za-z_$][0-9A-Za-z_$]*\)\C' : \ '\<\%(for\%(\s+each\)\=\|if\|let\|while\|with\)\C') . '\_s*\%#','bW') && \ (a:add || (expand("") == 'while' ? !s:lookForParens('\\C', '\\C','bW',100) : 1)) -endfunction +endfunc " Auxiliary Functions {{{2 @@ -89,24 +89,24 @@ func s:StripLine(c) endfunc " Check if the character at lnum:col is inside a string, comment, or is ascii. -function s:IsSyn(lnum, col, reg) +func s:IsSyn(lnum, col, reg) return synIDattr(synID(a:lnum, a:col, 1), 'name') =~? (a:reg != '' ? a:reg : s:syng_strcom) -endfunction +endfunc " Find line above 'lnum' that isn't empty, in a comment, or in a string. -function s:PrevCodeLine(lnum) +func s:PrevCodeLine(lnum) let lnum = prevnonblank(a:lnum) while lnum > 0 if !s:IsSyn(lnum, matchend(getline(lnum), '^\s*[^''"]'),'') break - endif + end let lnum = prevnonblank(lnum - 1) endwhile return lnum > 0 ? lnum : -1 -endfunction +endfunc " Check if line 'lnum' has more opening brackets than closing ones. -function s:LineHasOpeningBrackets(lnum) +func s:LineHasOpeningBrackets(lnum) let open_0 = 0 let open_2 = 0 let open_4 = 0 @@ -121,16 +121,16 @@ function s:LineHasOpeningBrackets(lnum) let last = pos else let open_{idx - 1} = open_{idx - 1} - 1 - endif - endif + end + end let pos = match(line, '[][(){}]', pos + 1) endwhile return [(open_0 > 0 ? 1 : (open_0 == 0 ? 0 : 2)) . (open_2 > 0 ? 1 : (open_2 == 0 ? 0 : 2)) . \ (open_4 > 0 ? 1 : (open_4 == 0 ? 0 : 2)), last] -endfunction +endfunc " }}} -function GetJavascriptIndent() +func GetJavascriptIndent() if !exists('b:js_cache') let b:js_cache = [0,0,0] end @@ -143,16 +143,16 @@ function GetJavascriptIndent() if (line !~ '^[''"`]' && s:IsSyn(v:lnum,1,'string\|template')) || \ (line !~ '^\s*[/*]' && s:IsSyn(v:lnum,1,s:syng_comment)) return -1 - endif + end if line !~ '^\%(\/\*\|\s*\/\/\)' && s:IsSyn(v:lnum,1,s:syng_comment) return cindent(v:lnum) - endif + end let lnum = s:PrevCodeLine(v:lnum - 1) let pline = s:StripLine(getline(lnum)) let line = s:StripLine(line) if lnum <= 0 return 0 - endif + end if (line =~ s:expr_case) let cpo_switch = &cpo @@ -160,7 +160,7 @@ function GetJavascriptIndent() let ind = cindent(v:lnum) let &cpo = cpo_switch return ind - endif + end "}}} " the containing paren, bracket, curly. Memoize, last lineNr either has the @@ -200,7 +200,7 @@ function GetJavascriptIndent() return indent(num) + s:sw() + switch_offset end -endfunction +endfunc let &cpo = s:cpo_save From 8c8c815284814385f718e778f2cb67abb9d65b7d Mon Sep 17 00:00:00 2001 From: bounceme Date: Sat, 30 Jul 2016 21:29:52 -0700 Subject: [PATCH 3/4] Update javascript.vim --- indent/javascript.vim | 54 +++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index a133435d..46692554 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -8,7 +8,7 @@ " Only load this indent file when no other was loaded. if exists("b:did_indent") finish -end +endif let b:did_indent = 1 " Now, set up our indentation expression and keys that trigger it. @@ -22,7 +22,7 @@ let b:undo_indent = 'setlocal indentexpr< indentkeys< cinoptions<' " Only define the function once. if exists("*GetJavascriptIndent") finish -end +endif let s:cpo_save = &cpo set cpo&vim @@ -31,12 +31,12 @@ set cpo&vim if exists('*shiftwidth') func s:sw() return shiftwidth() - endfunc + endfunction else func s:sw() return &sw - endfunc -end + endfunction +endif let s:line_pre = '^\s*\%(\/\*.*\*\/\s*\)*' let s:expr_case = s:line_pre . '\%(\%(case\>.*\)\|default\)\s*:\C' @@ -55,19 +55,19 @@ func s:lookForParens(start,end,flags,time) catch /E118/ return searchpair(a:start,'',a:end,a:flags,0,0) endtry -endfunc +endfunction let s:line_term = '\s*\%(\/\*.*\*\/\s*\)*$' " configurable regexes that define continuation lines, not including (, {, or [. if !exists('g:javascript_opfirst') let g:javascript_opfirst = '\%([<>,:?^%]\|\([-/.+]\)\%(\1\|\*\|\/\)\@!\|\*\/\@!\|=>\@!\||\|&\|in\%(stanceof\)\=\>\)\C' -end +endif let g:javascript_opfirst = s:line_pre . g:javascript_opfirst if !exists('g:javascript_continuation') let g:javascript_continuation = '\%([<*,.?:^%]\|+\@\|\*\@") == 'while' ? !s:lookForParens('\\C', '\\C','bW',100) : 1)) -endfunc +endfunction " Auxiliary Functions {{{2 " strip line of comment func s:StripLine(c) return substitute(a:c, '\%(:\@ 0 if !s:IsSyn(lnum, matchend(getline(lnum), '^\s*[^''"]'),'') break - end + endif let lnum = prevnonblank(lnum - 1) endwhile return lnum > 0 ? lnum : -1 -endfunc +endfunction " Check if line 'lnum' has more opening brackets than closing ones. func s:LineHasOpeningBrackets(lnum) @@ -121,19 +121,19 @@ func s:LineHasOpeningBrackets(lnum) let last = pos else let open_{idx - 1} = open_{idx - 1} - 1 - end - end + endif + endif let pos = match(line, '[][(){}]', pos + 1) endwhile return [(open_0 > 0 ? 1 : (open_0 == 0 ? 0 : 2)) . (open_2 > 0 ? 1 : (open_2 == 0 ? 0 : 2)) . \ (open_4 > 0 ? 1 : (open_4 == 0 ? 0 : 2)), last] -endfunc +endfunction " }}} func GetJavascriptIndent() if !exists('b:js_cache') let b:js_cache = [0,0,0] - end + endif " Get the current line. let line = getline(v:lnum) " previous nonblank line number @@ -143,16 +143,16 @@ func GetJavascriptIndent() if (line !~ '^[''"`]' && s:IsSyn(v:lnum,1,'string\|template')) || \ (line !~ '^\s*[/*]' && s:IsSyn(v:lnum,1,s:syng_comment)) return -1 - end + endif if line !~ '^\%(\/\*\|\s*\/\/\)' && s:IsSyn(v:lnum,1,s:syng_comment) return cindent(v:lnum) - end + endif let lnum = s:PrevCodeLine(v:lnum - 1) let pline = s:StripLine(getline(lnum)) let line = s:StripLine(line) if lnum <= 0 return 0 - end + endif if (line =~ s:expr_case) let cpo_switch = &cpo @@ -160,7 +160,7 @@ func GetJavascriptIndent() let ind = cindent(v:lnum) let &cpo = cpo_switch return ind - end + endif "}}} " the containing paren, bracket, curly. Memoize, last lineNr either has the @@ -171,7 +171,7 @@ func GetJavascriptIndent() let num = pcounts[0][0] =~ '1' ? lnum : b:js_cache[1] if pcounts[0][0] =~'1' call cursor(lnum,pcounts[0][1]) - end + endif else call cursor(v:lnum,1) let syns = synIDattr(synID(v:lnum, 1, 1), 'name') @@ -181,14 +181,14 @@ func GetJavascriptIndent() let num = s:lookForParens(pattern[0],pattern[1],'bW',2000) else let num = s:lookForParens('(\|{\|\[',')\|}\|\]','bW',2000) - end - end + endif + endif let b:js_cache = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] " most significant part if line =~ s:line_pre . '[])}]' return indent(num) - end + endif let inb = num == 0 ? 1 : s:Onescope(num, s:StripLine(strpart(getline(num),0,b:js_cache[2] - 1)),1) let switch_offset = (!inb || num == 0) || expand("") != 'switch' ? 0 : &cino !~ ':' || !has('float') ? s:sw() : \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (match(&cino,'.*:\zs[^,]*s') ? s:sw() : 1)) @@ -198,9 +198,9 @@ func GetJavascriptIndent() return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset elseif num > 0 return indent(num) + s:sw() + switch_offset - end + endif -endfunc +endfunction let &cpo = s:cpo_save From a4112a8571a0e5ea893992414c3013235db2965c Mon Sep 17 00:00:00 2001 From: bounceme Date: Sat, 30 Jul 2016 21:31:21 -0700 Subject: [PATCH 4/4] Update javascript.vim --- indent/javascript.vim | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 46692554..6d063669 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -29,11 +29,11 @@ set cpo&vim " Get shiftwidth value if exists('*shiftwidth') - func s:sw() + function s:sw() return shiftwidth() endfunction else - func s:sw() + function s:sw() return &sw endfunction endif @@ -49,7 +49,7 @@ let s:syng_comment = '\%(comment\|doc\)\c' " Expression used to check whether we should skip a match with searchpair(). let s:skip_expr = "line('.') < (prevnonblank(v:lnum) - 2000) ? dummy : s:IsSyn(line('.'),col('.'),'')" -func s:lookForParens(start,end,flags,time) +function s:lookForParens(start,end,flags,time) try return searchpair(a:start,'',a:end,a:flags,s:skip_expr,0,a:time) catch /E118/ @@ -70,7 +70,7 @@ if !exists('g:javascript_continuation') endif let g:javascript_continuation .= s:line_term -func s:Onescope(lnum,text,add) +function s:Onescope(lnum,text,add) return a:text =~ '\%(\' . (a:add ? '\|\ -1 && \ cursor(line('.'),match(s:Stripline(getline(line('.'))), ')' . s:line_term))>-1) || @@ -84,17 +84,17 @@ endfunction " Auxiliary Functions {{{2 " strip line of comment -func s:StripLine(c) +function s:StripLine(c) return substitute(a:c, '\%(:\@ 0 if !s:IsSyn(lnum, matchend(getline(lnum), '^\s*[^''"]'),'') @@ -106,7 +106,7 @@ func s:PrevCodeLine(lnum) endfunction " Check if line 'lnum' has more opening brackets than closing ones. -func s:LineHasOpeningBrackets(lnum) +function s:LineHasOpeningBrackets(lnum) let open_0 = 0 let open_2 = 0 let open_4 = 0 @@ -130,7 +130,7 @@ func s:LineHasOpeningBrackets(lnum) endfunction " }}} -func GetJavascriptIndent() +function GetJavascriptIndent() if !exists('b:js_cache') let b:js_cache = [0,0,0] endif