vim-polyglot/indent/gohtmltmpl.vim

59 lines
1.2 KiB
VimL
Raw Normal View History

if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'go') == -1
2015-05-11 09:05:13 -04:00
if exists("b:did_indent")
finish
endif
runtime! indent/html.vim
2016-05-02 04:42:37 -04:00
" Indent Golang HTML templates
setlocal indentexpr=GetGoHTMLTmplIndent(v:lnum)
setlocal indentkeys+==else,=end
" Only define the function once.
if exists("*GetGoHTMLTmplIndent")
finish
endif
2018-12-26 04:41:57 -05:00
" don't spam the user when Vim is started in Vi compatibility mode
let s:cpo_save = &cpo
set cpo&vim
2016-05-02 04:42:37 -04:00
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)
2016-12-20 14:57:20 -05:00
if last_line =~ '^\s*{{-\=\s*\%(if\|else\|range\|with\|define\|block\).*}}'
2016-05-02 04:42:37 -04:00
let ind += sw
endif
" End of FuncMap block
let current_line = getline(a:lnum)
2016-12-20 14:57:20 -05:00
if current_line =~ '^\s*{{-\=\s*\%(else\|end\).*}}'
2016-05-02 04:42:37 -04:00
let ind -= sw
endif
return ind
endfunction
2018-12-26 04:41:57 -05:00
" restore Vi compatibility settings
let &cpo = s:cpo_save
unlet s:cpo_save
2016-06-26 12:03:28 -04:00
" vim: sw=2 ts=2 et
endif