Skip to content

Commit 3a20412

Browse files
authored
cleaning (#601)
cleaning and improving readability
1 parent 28b5a87 commit 3a20412

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

indent/javascript.vim

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
" Language: Javascript
33
" Maintainer: vim-javascript community
44
" URL: https://github.com/pangloss/vim-javascript
5-
" Last Change: August 15, 2016
5+
" Last Change: August 16, 2016
66

77
" Only load this indent file when no other was loaded.
88
if exists('b:did_indent')
@@ -46,27 +46,29 @@ let s:syng_strcom = '\%(s\%(tring\|pecial\)\|comment\|regex\|doc\|template\)'
4646
let s:syng_comment = '\%(comment\|doc\)'
4747

4848
" Expression used to check whether we should skip a match with searchpair().
49-
let s:skip_expr = "line('.') < (prevnonblank(v:lnum) - 2000) ? dummy : synIDattr(synID(line('.'),col('.'),0),'name') =~? '".s:syng_strcom."'"
49+
let s:skip_expr = "synIDattr(synID(line('.'),col('.'),0),'name') =~? '".s:syng_strcom."'"
5050

51-
function s:lookForParens(start,end,flags,time)
52-
if has('reltime')
53-
return searchpair(a:start,'',a:end,a:flags,s:skip_expr,0,a:time)
54-
else
55-
return searchpair(a:start,'',a:end,a:flags,0,0)
56-
endif
57-
endfunction
51+
if has('reltime')
52+
function s:lookForParens(start,end,flags,time)
53+
return searchpair(a:start,'',a:end,a:flags,s:skip_expr,max([prevnonblank(v:lnum) - 2000,0]),a:time)
54+
endfunction
55+
else
56+
function s:lookForParens(start,end,flags,n)
57+
return searchpair(a:start,'',a:end,a:flags,0,max([prevnonblank(v:lnum) - 2000,0]))
58+
endfunction
59+
endif
5860

5961
let s:line_term = '\%(\s*\%(\/\*.\{-}\*\/\s*\)\=\)\@>$'
6062

6163
" configurable regexes that define continuation lines, not including (, {, or [.
6264
if !exists('g:javascript_opfirst')
6365
let g:javascript_opfirst = '\%([<>,:?^%|&]\|\([-/.+]\)\%(\1\|\*\|\/\)\@!\|\*\/\@!\|=>\@!\|in\%(stanceof\)\=\>\)'
6466
endif
65-
let g:javascript_opfirst = s:line_pre . g:javascript_opfirst
66-
6767
if !exists('g:javascript_continuation')
6868
let g:javascript_continuation = '\%([<=*,.?:^%|&]\|+\@<!+\|-\@<!-\|=\@<!>\|\*\@<!\/\|\<in\%(stanceof\)\=\)'
6969
endif
70+
71+
let g:javascript_opfirst = s:line_pre . g:javascript_opfirst
7072
let g:javascript_continuation .= s:line_term
7173

7274
function s:Onescope(lnum,text,add)
@@ -95,13 +97,12 @@ endfunction
9597
" Find line above 'lnum' that isn't empty, in a comment, or in a string.
9698
function s:PrevCodeLine(lnum)
9799
let l:lnum = prevnonblank(a:lnum)
98-
while l:lnum > 0
100+
while l:lnum
99101
if synIDattr(synID(l:lnum,matchend(getline(l:lnum), '^\s*[^''"]'),0),'name') !~? s:syng_strcom
100-
break
102+
return l:lnum
101103
endif
102104
let l:lnum = prevnonblank(l:lnum - 1)
103105
endwhile
104-
return l:lnum
105106
endfunction
106107

107108
" Check if line 'lnum' has a balanced amount of parentheses.
@@ -176,7 +177,7 @@ function GetJavascriptIndent()
176177
endif
177178

178179
let pline = s:StripLine(getline(l:lnum))
179-
call cursor(b:js_cache[1:])
180+
call cursor(b:js_cache[1],b:js_cache[2])
180181
let inb = num == 0 || num < l:lnum && ((l:line !~ s:line_pre . ',' && pline !~ ',' . s:line_term) || s:isBlock())
181182
let switch_offset = num == 0 || s:Onescope(num, s:StripLine(strpart(getline(num),0,b:js_cache[2] - 1)),1) !=# 'switch' ? 0 :
182183
\ &cino !~ ':' || !has('float') ? s:sw() :

0 commit comments

Comments
 (0)