Skip to content

Commit

Permalink
Merge commit '9a807fb54' into comma_start
Browse files Browse the repository at this point in the history
Conflicts:
	test.js
  • Loading branch information
guileen committed Nov 11, 2011
2 parents 6cf7deb + 9a807fb commit 3b489f6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
34 changes: 31 additions & 3 deletions indent/javascript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let b:indented = 0
let b:in_comment = 0

setlocal indentexpr=GetJsIndent()
setlocal indentkeys+==},=),=],0=*/,0=/*,*<Return>
setlocal indentkeys+==},=),=],0=*/,0=/*,0=\,,*<Return>
if exists("*GetJsIndent")
finish
endif
Expand All @@ -43,6 +43,11 @@ let s:expr_case = '\s\+\(case\s\+[^\:]*\|default\)\s*:\s*'
let s:expr_comment_start = '/\*c'
let s:expr_comment_end = 'c\*/'

let s:expr_comma_start = '^\s*,'
let s:expr_var = '^\s*var\s'
let s:expr_var_stop = ';'
let s:expr_semic_start = '^\s*;'

" Check prev line
function! DoIndentPrev(ind,str)
let ind = a:ind
Expand Down Expand Up @@ -97,15 +102,27 @@ function! DoIndentPrev(ind,str)
let ind = ind - 1
endif

if match(pline, s:expr_comma_start) != -1
let ind = ind + 2
if match(pline, s:expr_var_stop) != -1
let ind = ind - 4
endif
endif

" buggy
if match(pline, s:expr_semic_start) != -1
let ind = ind - 2
endif

return ind
endfunction


" Check current line
function! DoIndent(ind, str)
function! DoIndent(ind, str, pline)
let ind = a:ind
let line = a:str
let pline = a:pline
let last = 0
let first = 1
let mstr = matchstr(line, '^'.s:expr_right.'*')
Expand Down Expand Up @@ -133,6 +150,17 @@ function! DoIndent(ind, str)
let ind = float2nr(ind + &sw * g:SimpleJsIndenter_CaseIndentLevel)
endif

if (match(line, s:expr_comma_start) != -1)
let ind = ind - 2
if (match(pline, s:expr_var) != -1)
let ind = ind + 4
endif
endif

if (match(line, s:expr_semic_start) != -1 && match(pline, s:expr_comma_start) != -1)
let ind = ind - 2
endif

if ind<0
let ind=0
endif
Expand Down Expand Up @@ -371,7 +399,7 @@ function! GetJsIndent()
endif

let line = s:GetLine(v:lnum)
let ind = DoIndent(ind, line)
let ind = DoIndent(ind, line, pline)

return ind
endfunction
21 changes: 21 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,24 @@
}
}

var a = a
, b = b
, c = c;

var a = a
, b = b
;

foo({
a : a
, b : b
, c : c
, d : {
e : e
f : f
}
, g : {[
h : h
, i : i
]}
});

0 comments on commit 3b489f6

Please sign in to comment.