diff options
author | Adam Stankiewicz <sheerun@sher.pl> | 2016-05-02 10:42:37 +0200 |
---|---|---|
committer | Adam Stankiewicz <sheerun@sher.pl> | 2016-05-02 10:42:37 +0200 |
commit | 5dd1a7e83966c92d220073185f1738dfe441f59e (patch) | |
tree | 9c4bee389a51a9bb111dcc894c9db0f6d1809d81 /indent/gohtmltmpl.vim | |
parent | bc098370c1bb81840734f5764f431dee270e75ce (diff) | |
download | vim-polyglot-5dd1a7e83966c92d220073185f1738dfe441f59e.tar.gz vim-polyglot-5dd1a7e83966c92d220073185f1738dfe441f59e.zip |
Update
Diffstat (limited to 'indent/gohtmltmpl.vim')
-rw-r--r-- | indent/gohtmltmpl.vim | 39 |
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 |