Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e28cfe6

Browse files
committedApr 19, 2016
Operator first support,including ternary,dot etc.
generally this will give us fairly accurate indents without having specific code for each operator.Thanks to pangloss#139 (comment) which this is based on I think this needs a few things before it's ready
1 parent c8ac1c8 commit e28cfe6

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed
 

‎indent/javascript.vim

+23-4
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,31 @@ function GetJavascriptIndent()
378378
return indent(prevline) + s:case_indent_after
379379
endif
380380

381-
if (line =~ s:ternary)
382-
if (getline(prevline) =~ s:ternary_q)
381+
" If line starts with operator...
382+
if (line =~ s:operator_first)
383+
if (getline(prevline) =~ s:operator_first)
384+
" and so does previous line, don't indent
383385
return indent(prevline)
386+
end
387+
let counts = s:LineHasOpeningBrackets(prevline)
388+
if counts[0] == '2'
389+
call cursor(prevline, 1)
390+
" Search for the opening tag
391+
let mnum = searchpair('(', '', ')', 'bW', s:skip_expr)
392+
if mnum > 0
393+
if getline(mnum) =~ s:operator_first
394+
return indent(mnum)
395+
end
396+
end
384397
else
385-
return indent(prevline) + s:sw()
386-
endif
398+
" otherwise, indent 1 level
399+
return indent(prevline) + &sw
400+
end
401+
end
402+
" If previous line starts with a dot...
403+
if (getline(prevline) =~ s:operator_first)
404+
" dedent 1 level
405+
return indent(prevline) - &sw
387406
endif
388407

389408
" If we are in a multi-line comment, cindent does the right thing.

0 commit comments

Comments
 (0)
Please sign in to comment.