Skip to content

Switch mechanics, indent #400

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 1 commit into from
Apr 26, 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
38 changes: 4 additions & 34 deletions indent/javascript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ let s:line_term = '\s*\%(\%(\/\/\).*\)\=$'
" Regex that defines continuation lines, not including (, {, or [.
let s:continuation_regex = '\%([\\*/.:]\|+\@<!+\|-\@<!-\|\%(<%\)\@<!=\|\W[|&?]\|||\|&&\|[^=]=[^=>].*,\)' . s:line_term

" Regex that defines continuation lines.
" TODO: this needs to deal with if ...: and so on
let s:msl_regex = s:continuation_regex.'\|'.s:expr_case

let s:one_line_scope_regex = '\%(\%(\<else\>\|\<\%(if\|for\|while\)\>\s*(\%([^()]*\|[^()]*(\%([^()]*\|[^()]*(\%([^()]*\|[^()]*([^()]*)[^()]*\))[^()]*\))[^()]*\))\)\|=>\)' . s:line_term

" Regex that defines blocks.
Expand All @@ -81,16 +77,6 @@ let s:var_stmt = '^\s*\%(const\|let\|var\)'
let s:comma_first = '^\s*,'
let s:comma_last = ',\s*$'

let s:case_indent = s:sw()
let s:case_indent_after = s:sw()
let s:m = matchlist(&cinoptions, ':\(.\)')
if (len(s:m) > 2)
let s:case_indent = s:m[1]
endif
let s:m = matchlist(&cinoptions, '=\(.\)')
if (len(s:m) > 2)
let s:case_indent_after = s:m[1]
endif
" 2. Auxiliary Functions {{{1
" ======================

Expand Down Expand Up @@ -152,10 +138,10 @@ function s:GetMSL(lnum, in_one_line_scope)
" If we have a continuation line, or we're in a string, use line as MSL.
" Otherwise, terminate search as we have found our MSL already.
let line = getline(lnum)
let col = match(line, s:msl_regex) + 1
let col = match(line, s:continuation_regex) + 1
let line2 = getline(msl)
let col2 = matchend(line2, ')')
if (col > 0 && !s:IsInStringOrComment(lnum, col)) || s:IsInString(lnum, strlen(line))
if (col > 0 && !s:IsInStringOrComment(lnum, col) && !s:Match(lnum, s:expr_case)) || s:IsInString(lnum, strlen(line))
let msl = lnum

" if there are more closing brackets, continue from the line which has the matching opening bracket
Expand Down Expand Up @@ -327,7 +313,6 @@ endfunction
function GetJavascriptIndent()
" 3.1. Setup {{{2
" ----------

" Set up variables for restoring position in file. Could use v:lnum here.
let vcol = col('.')

Expand All @@ -341,15 +326,7 @@ function GetJavascriptIndent()
let prevline = prevnonblank(v:lnum - 1)

if (line =~ s:expr_case)
if (getline(prevline) =~ s:expr_case)
return indent(prevline)
else
if (getline(prevline) =~ s:block_regex)
return indent(prevline) + s:case_indent
else
return indent(prevline) - s:case_indent_after
endif
endif
return cindent(v:lnum)
endif
" If we got a closing bracket on an empty line, find its match and indent
" according to it. For parentheses we indent to its column - 1, for the
Expand Down Expand Up @@ -393,9 +370,6 @@ function GetJavascriptIndent()
if (getline(prevline) =~ s:comma_first)
return indent(prevline) - s:sw()
endif
if (getline(prevline) =~ s:expr_case)
return indent(prevline) + s:case_indent_after
endif

" If line starts with an operator...
if (s:Match(v:lnum, s:operator_first))
Expand Down Expand Up @@ -475,11 +449,7 @@ function GetJavascriptIndent()

" If the previous line ended with a block opening, add a level of indent.
if s:Match(lnum, s:block_regex)
if (line =~ s:expr_case)
return indent(s:GetMSL(lnum, 0)) + s:sw()/2
else
return indent(s:GetMSL(lnum, 0)) + s:sw()
endif
return indent(s:GetMSL(lnum, 0)) + s:sw()
endif

" Set up variables for current line.
Expand Down