Skip to content

minor indentation cleaning #508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 23, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions indent/javascript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ endif

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'
let s:expr_case = s:line_pre . '\%(\%(case\>.*\)\|default\)\s*:\C'
" Regex of syntax group names that are or delimit string or are comments.
let s:syng_strcom = '\%(string\|regex\|special\|doc\|comment\|template\)\c'

Expand Down Expand Up @@ -337,7 +337,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) && !s:Match(lnum,s:block_regex) &&
if line =~ s:line_pre . '{' . s:line_term && !s:Match(lnum,s:block_regex) &&
\ !s:Match(lnum,s:comma_last)
return cindent(v:lnum)
endif
Expand All @@ -353,7 +353,7 @@ function GetJavascriptIndent()

" If we got a closing bracket on an empty line, find its match and indent
" according to it.
let col = s:Match(v:lnum, s:line_pre . '[]})]')
let col = line =~ s:line_pre . '[]})]'
if col > 0
let parlnum = v:lnum
while col
Expand Down Expand Up @@ -395,12 +395,12 @@ function GetJavascriptIndent()
end

" If previous line starts with an operator...
elseif (s:Match(lnum, s:operator_first) && !s:Match(lnum,s:continuation_regex))||getline(lnum) =~ ');\=' . s:line_term
elseif (s:Match(lnum, s:operator_first) && !s:Match(lnum,s:continuation_regex))||getline(lnum) =~ '[]})];\=' . s:line_term
let counts = s:LineHasOpeningBrackets(lnum)
if counts[0] == '2' && !s:Match(lnum, s:operator_first)
if counts =~ '2' && !s:Match(lnum, s:operator_first)
call cursor(lnum, 1)
" Search for the opening tag
let mnum = s:lookForParens('(', ')', 'nbW', 0)
let mnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0)
if mnum > 0 && s:Match(mnum, s:operator_first)
return indent(mnum) - s:sw()
end
Expand Down Expand Up @@ -434,16 +434,6 @@ function GetJavascriptIndent()
return 0
endif

" foo('foo',
" bar('bar', function() {
" hi();
" })
" );

" function (a, b, c, d,
" e, f, g) {
" console.log('inner');
" }
" 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) || s:LineHasOpeningBrackets(lnum) !~ '2' ?
Expand All @@ -463,7 +453,8 @@ function GetJavascriptIndent()
call cursor(lnum, matchend(s:RemoveTrailingComments(strpart(line,0,col('.'))), '.*\zs[])}]'))
endwhile
let cur = line('.')
if cur < lnum && !s:InMultiVarStatement(cur,0,0)
if cur < lnum && !s:InMultiVarStatement(cur,0,0) &&
\ !s:Onescope(s:PrevNonBlankNonString(cur - 1))
return indent(s:GetMSL(cur, 0))
end
elseif counts =~ '1' || s:Onescope(lnum)
Expand Down