I'm working with handlebars right now and I'd like to get tags like:
{{#component 'whatever'}}
{{/component}}
and
{{#if}}
{{else}}
{{/if}}
to increase the indent count. Unfortunately, it doesn't look like you can add handlebars with g:html_indent_tags
or indentkeys
. Even Tim Pope's ragtag
doesn't seem to support handlebars.
Does anyone know how I can add handlebars to html.vim so that they increase the indent count?
Thanks!
Progress
I'm hacking the html5.vim package to try to move this forward. I've gotten the increase in indentation working by adding these changes to html5.vim/indent/html.vim
:
add the pattern to tags
call add(s:tags, 'view')
Modify HtmlIndentOpen Function
original:
" [-- count indent-increasing tags of line a:lnum --]
fun! <SID>HtmlIndentOpen(lnum, pattern)
let s = substitute('x'.getline(a:lnum),
\ '.\{-}\(\(<\)\('.a:pattern.'\)\>\)', "\1", 'g')
let s = substitute(s, "[^\1].*$", '', '')
return strlen(s)
endfun
modified:
" [-- count indent-increasing tags of line a:lnum --]
fun! <SID>HtmlIndentOpen(lnum, pattern)
let s = substitute('x'.getline(a:lnum),
\ '.\{-}\(\(<\|{{#\)\('.a:pattern.'\)\>\)', "\1", 'g')
let s = substitute(s, "[^\1].*$", '', '')
return strlen(s)
endfun
The only change is in the regex that substitute
is using. I've changed the first group from <
(i.e. match only an opening bracket) to <\|{{#
(i.e. match an opening bracket or an opening handlebar expression).
And it works:
{{#view 'thing'}}
stuff about things
{{/view}}
The indentation gets increased on the {{#view 'thing'}}
line. But, the closing tag {{/view}}
isn't decreasing the indent count yet.
Modify HtmlIndentClose Function
original:
" [-- count indent-decreasing tags of line a:lnum --]
fun! <SID>HtmlIndentClose(lnum, pattern)
let s = substitute('x'.getline(a:lnum),
\ '.\{-}\(\(<\)/\('.a:pattern.'\)\>>\)', "\1", 'g')
let s = substitute(s, "[^\1].*$", '', '')
return strlen(s)
endfun
modified:
" [-- count indent-decreasing tags of line a:lnum --]
fun! <SID>HtmlIndentClose(lnum, pattern)
let s = substitute('x'.getline(a:lnum),
\ '.\{-}\(\(<\|{{\)/\('.a:pattern.'\)\>>\|}}\)', "\1", 'g')
let s = substitute(s, "[^\1].*$", '', '')
return strlen(s)
endfun
Basically, the original is looking for a:pattern
inside of </
and >
. I've tried to modify it to look for a:pattern
inside of </
or {{/
and >
or }}
but it's matching every handlebar expression (e.g. this regex is matching {{outlet}}
).
Any help on figuring out the regex would be greatly appreciated.
$VIMRUNTIME/indent
. They work by settingindentexpr
. Create a file for Handlebars that, err, handles the patterns you want, and returnHtmlIndent()
for everything else. – lcd047 Jun 30 '15 at 23:10