Skip to content

Commit

Permalink
Indent tmpl templates
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Feb 13, 2016
1 parent de369ba commit d0dae0c
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions indent/gohtmltmpl.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,42 @@ if exists("b:did_indent")
endif

runtime! indent/html.vim

" Indent Golang HTML templates
setlocal indentexpr=GetGoHTMLTmplIndent(v:lnum)
setlocal indentkeys+==else,=end

" Only define the function once.
if exists("*GetGoHTMLTmplIndent")
finish
endif

function! GetGoHTMLTmplIndent(lnum)
" Get HTML indent
if exists('*HtmlIndent')
let ind = HtmlIndent()
else
let ind = HtmlIndentGet(a:lnum)
endif

" The value of a single shift-width
if exists('*shiftwidth')
let sw = shiftwidth()
else
let sw = &sw
endif

" If need to indent based on last line
let last_line = getline(a:lnum-1)
if last_line =~ '^\s*{{\s*\%(if\|else\|range\|with\|define\|block\).*}}'
let ind += sw
endif

" End of FuncMap block
let current_line = getline(a:lnum)
if current_line =~ '^\s*{{\s*\%(else\|end\).*}}'
let ind -= sw
endif

return ind
endfunction

0 comments on commit d0dae0c

Please sign in to comment.