Skip to content

Commit 295e8ee

Browse files
committed
Update javascript.vim
1 parent 3bcc2ba commit 295e8ee

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

indent/javascript.vim

Lines changed: 8 additions & 19 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-
setl cino+=b0
20+
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*\|^\s*break\>'
44+
let s:expr_case = '^\s*\(case\s\+[^\:]*\|default\)\s*:\s*'
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

@@ -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,8 +77,8 @@ let s:var_stmt = '^\s*\%(const\|let\|var\)'
8177
let s:comma_first = '^\s*,'
8278
let s:comma_last = ',\s*$'
8379

84-
" " 2. Auxiliary Functions {{{1
85-
" " ======================
80+
" 2. Auxiliary Functions {{{1
81+
" ======================
8682

8783
" Check if the character at lnum:col is inside a string, comment, or is ascii.
8884
function s:IsInStringOrComment(lnum, col)
@@ -142,10 +138,10 @@ function s:GetMSL(lnum, in_one_line_scope)
142138
" If we have a continuation line, or we're in a string, use line as MSL.
143139
" Otherwise, terminate search as we have found our MSL already.
144140
let line = getline(lnum)
145-
let col = match(line, s:msl_regex) + 1
141+
let col = match(line, s:continuation_regex) + 1
146142
let line2 = getline(msl)
147143
let col2 = matchend(line2, ')')
148-
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))
149145
let msl = lnum
150146

151147
" if there are more closing brackets, continue from the line which has the matching opening bracket
@@ -317,7 +313,6 @@ endfunction
317313
function GetJavascriptIndent()
318314
" 3.1. Setup {{{2
319315
" ----------
320-
321316
" Set up variables for restoring position in file. Could use v:lnum here.
322317
let vcol = col('.')
323318

@@ -331,13 +326,7 @@ function GetJavascriptIndent()
331326
let prevline = prevnonblank(v:lnum - 1)
332327

333328
if (line =~ s:expr_case)
334-
if (getline(prevline) =~ s:expr_case)
335-
return cindent(line)
336-
else
337-
if (getline(prevline) !~ s:block_regex)
338-
return cindent(line)
339-
endif
340-
endif
329+
return cindent(v:lnum)
341330
endif
342331
" If we got a closing bracket on an empty line, find its match and indent
343332
" according to it. For parentheses we indent to its column - 1, for the
@@ -382,7 +371,7 @@ function GetJavascriptIndent()
382371
return indent(prevline) - s:sw()
383372
endif
384373
if (getline(prevline) =~ s:expr_case)
385-
return cindent(line)
374+
return cindent(v:lnum)
386375
endif
387376

388377
" If line starts with an operator...

0 commit comments

Comments
 (0)