|
43 | 43 | 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 | 44 | let s:expr_case = '^\s*\(case\s\+[^\:]*\|default\)\s*:\s*'
|
45 | 45 | " 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' |
47 | 50 |
|
48 | 51 | " Regex of syntax group names that are strings.
|
49 | 52 | let s:syng_string = 'regex\c'
|
@@ -102,6 +105,11 @@ function s:IsInString(lnum, col)
|
102 | 105 | return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_string
|
103 | 106 | endfunction
|
104 | 107 |
|
| 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 | + |
105 | 113 | " Check if the character at lnum:col is inside a multi-line comment.
|
106 | 114 | function s:IsInMultilineComment(lnum, col)
|
107 | 115 | return !s:IsLineComment(a:lnum, a:col) && synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_multiline
|
@@ -386,6 +394,14 @@ function GetJavascriptIndent()
|
386 | 394 | endif
|
387 | 395 | endif
|
388 | 396 |
|
| 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 | + |
389 | 405 | " If we are in a multi-line comment, cindent does the right thing.
|
390 | 406 | if s:IsInMultilineComment(v:lnum, 1) && !s:IsLineComment(v:lnum, 1)
|
391 | 407 | return cindent(v:lnum)
|
|
0 commit comments