summaryrefslogtreecommitdiffstats
path: root/indent/gohtmltmpl.vim
diff options
context:
space:
mode:
Diffstat (limited to 'indent/gohtmltmpl.vim')
-rw-r--r--indent/gohtmltmpl.vim39
1 files changed, 39 insertions, 0 deletions
diff --git a/indent/gohtmltmpl.vim b/indent/gohtmltmpl.vim
index 7275383e..e1708552 100644
--- a/indent/gohtmltmpl.vim
+++ b/indent/gohtmltmpl.vim
@@ -6,4 +6,43 @@ 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
+
endif