From d0dae0c715a81cdbcde847e4d33a6dd12eac0d37 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Wed, 3 Feb 2016 23:23:30 +0800 Subject: [PATCH] Indent tmpl templates --- indent/gohtmltmpl.vim | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/indent/gohtmltmpl.vim b/indent/gohtmltmpl.vim index 50399f2b2e..94ea135a44 100644 --- a/indent/gohtmltmpl.vim +++ b/indent/gohtmltmpl.vim @@ -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