Skip to content

Commit 6cb0c96

Browse files
bouncemebounceme
bounceme
authored and
bounceme
committed
old changes reset
1 parent 5fea23e commit 6cb0c96

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

indent/javascript.vim

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ endif
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\)'
4444
let s:expr_case = '^\s*\(case\s\+[^\:]*\|default\)\s*:\s*'
4545
" Regex of syntax group names that are or delimit string or are comments.
46-
let s:syng_strcom = 'string\|regex\|comment\c'
46+
let s:syng_strcom = '\%(\%(template\)\@<!string\|regex\|comment\)\c'
47+
48+
" Regex of syntax group names that are or delimit template strings
49+
let s:syng_template = 'template\c'
4750

4851
" Regex of syntax group names that are strings.
4952
let s:syng_string = 'regex\c'
@@ -102,6 +105,11 @@ function s:IsInString(lnum, col)
102105
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_string
103106
endfunction
104107

108+
" Check if the character at lnum:col is inside a template string.
109+
function s:IsInTempl(lnum, col)
110+
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_template
111+
endfunction
112+
105113
" Check if the character at lnum:col is inside a multi-line comment.
106114
function s:IsInMultilineComment(lnum, col)
107115
return !s:IsLineComment(a:lnum, a:col) && synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_multiline
@@ -386,6 +394,14 @@ function GetJavascriptIndent()
386394
endif
387395
endif
388396

397+
if getline(prevline) =~ '^\s*`$' && s:IsInTempl(v:lnum, 1)
398+
if line !~ '^\s*`$'
399+
return indent(prevline) + s:sw()
400+
endif
401+
elseif line =~ '^\s*`$' && s:IsInTempl(prevline, 1)
402+
return indent(prevline) - s:sw()
403+
endif
404+
389405
" If we are in a multi-line comment, cindent does the right thing.
390406
if s:IsInMultilineComment(v:lnum, 1) && !s:IsLineComment(v:lnum, 1)
391407
return cindent(v:lnum)

0 commit comments

Comments
 (0)