Skip to content

Commit 105a4aa

Browse files
bouncemebounceme
authored and
bounceme
committed
Switch mechanics, indent
also now that I know about cindent i'm curious if there are other places like this to remove code and increase performance
1 parent 4b6f9c5 commit 105a4aa

File tree

1 file changed

+4
-34
lines changed

1 file changed

+4
-34
lines changed

indent/javascript.vim

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ let s:line_term = '\s*\%(\%(\/\/\).*\)\=$'
6565
" Regex that defines continuation lines, not including (, {, or [.
6666
let s:continuation_regex = '\%([\\*/.:]\|+\@<!+\|-\@<!-\|\%(<%\)\@<!=\|\W[|&?]\|||\|&&\|[^=]=[^=>].*,\)' . s:line_term
6767

68-
" Regex that defines continuation lines.
69-
" TODO: this needs to deal with if ...: and so on
70-
let s:msl_regex = s:continuation_regex.'\|'.s:expr_case
71-
7268
let s:one_line_scope_regex = '\%(\%(\<else\>\|\<\%(if\|for\|while\)\>\s*(\%([^()]*\|[^()]*(\%([^()]*\|[^()]*(\%([^()]*\|[^()]*([^()]*)[^()]*\))[^()]*\))[^()]*\))\)\|=>\)' . s:line_term
7369

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

84-
let s:case_indent = s:sw()
85-
let s:case_indent_after = s:sw()
86-
let s:m = matchlist(&cinoptions, ':\(.\)')
87-
if (len(s:m) > 2)
88-
let s:case_indent = s:m[1]
89-
endif
90-
let s:m = matchlist(&cinoptions, '=\(.\)')
91-
if (len(s:m) > 2)
92-
let s:case_indent_after = s:m[1]
93-
endif
9480
" 2. Auxiliary Functions {{{1
9581
" ======================
9682

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

161147
" if there are more closing brackets, continue from the line which has the matching opening bracket
@@ -327,7 +313,6 @@ endfunction
327313
function GetJavascriptIndent()
328314
" 3.1. Setup {{{2
329315
" ----------
330-
331316
" Set up variables for restoring position in file. Could use v:lnum here.
332317
let vcol = col('.')
333318

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

343328
if (line =~ s:expr_case)
344-
if (getline(prevline) =~ s:expr_case)
345-
return indent(prevline)
346-
else
347-
if (getline(prevline) =~ s:block_regex)
348-
return indent(prevline) + s:case_indent
349-
else
350-
return indent(prevline) - s:case_indent_after
351-
endif
352-
endif
329+
return cindent(v:lnum)
353330
endif
354331
" If we got a closing bracket on an empty line, find its match and indent
355332
" according to it. For parentheses we indent to its column - 1, for the
@@ -393,9 +370,6 @@ function GetJavascriptIndent()
393370
if (getline(prevline) =~ s:comma_first)
394371
return indent(prevline) - s:sw()
395372
endif
396-
if (getline(prevline) =~ s:expr_case)
397-
return indent(prevline) + s:case_indent_after
398-
endif
399373

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

476450
" If the previous line ended with a block opening, add a level of indent.
477451
if s:Match(lnum, s:block_regex)
478-
if (line =~ s:expr_case)
479-
return indent(s:GetMSL(lnum, 0)) + s:sw()/2
480-
else
481-
return indent(s:GetMSL(lnum, 0)) + s:sw()
482-
endif
452+
return indent(s:GetMSL(lnum, 0)) + s:sw()
483453
endif
484454

485455
" Set up variables for current line.

0 commit comments

Comments
 (0)