Skip to content

Commit 3bcc2ba

Browse files
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 3bcc2ba

File tree

1 file changed

+8
-24
lines changed

1 file changed

+8
-24
lines changed

indent/javascript.vim

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ setlocal nosmartindent
1717
setlocal indentexpr=GetJavascriptIndent()
1818
setlocal formatexpr=Fixedgq(v:lnum,v:count)
1919
setlocal indentkeys=0{,0},0),0],0\,:,!^F,o,O,e
20-
20+
setl cino+=b0
2121
" Only define the function once.
2222
if exists("*GetJavascriptIndent")
2323
finish
@@ -41,7 +41,7 @@ endif
4141
" ============
4242

4343
let s:js_keywords = '^\s*\(break\|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\)'
44-
let s:expr_case = '^\s*\(case\s\+[^\:]*\|default\)\s*:\s*'
44+
let s:expr_case = '^\s*\(case\s\+[^\:]*\|default\)\s*:\s*\|^\s*break\>'
4545
" Regex of syntax group names that are or delimit string or are comments.
4646
let s:syng_strcom = '\%(\%(template\)\@<!string\|regex\|comment\)\c'
4747

@@ -81,18 +81,8 @@ let s:var_stmt = '^\s*\%(const\|let\|var\)'
8181
let s:comma_first = '^\s*,'
8282
let s:comma_last = ',\s*$'
8383

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
94-
" 2. Auxiliary Functions {{{1
95-
" ======================
84+
" " 2. Auxiliary Functions {{{1
85+
" " ======================
9686

9787
" Check if the character at lnum:col is inside a string, comment, or is ascii.
9888
function s:IsInStringOrComment(lnum, col)
@@ -342,12 +332,10 @@ function GetJavascriptIndent()
342332

343333
if (line =~ s:expr_case)
344334
if (getline(prevline) =~ s:expr_case)
345-
return indent(prevline)
335+
return cindent(line)
346336
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
337+
if (getline(prevline) !~ s:block_regex)
338+
return cindent(line)
351339
endif
352340
endif
353341
endif
@@ -394,7 +382,7 @@ function GetJavascriptIndent()
394382
return indent(prevline) - s:sw()
395383
endif
396384
if (getline(prevline) =~ s:expr_case)
397-
return indent(prevline) + s:case_indent_after
385+
return cindent(line)
398386
endif
399387

400388
" If line starts with an operator...
@@ -475,11 +463,7 @@ function GetJavascriptIndent()
475463

476464
" If the previous line ended with a block opening, add a level of indent.
477465
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
481466
return indent(s:GetMSL(lnum, 0)) + s:sw()
482-
endif
483467
endif
484468

485469
" Set up variables for current line.

0 commit comments

Comments
 (0)