gohtmltmpl.vim 920 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. if exists("b:did_indent")
  2. finish
  3. endif
  4. runtime! indent/html.vim
  5. " Indent Golang HTML templates
  6. setlocal indentexpr=GetGoHTMLTmplIndent(v:lnum)
  7. setlocal indentkeys+==else,=end
  8. " Only define the function once.
  9. if exists("*GetGoHTMLTmplIndent")
  10. finish
  11. endif
  12. function! GetGoHTMLTmplIndent(lnum)
  13. " Get HTML indent
  14. if exists('*HtmlIndent')
  15. let ind = HtmlIndent()
  16. else
  17. let ind = HtmlIndentGet(a:lnum)
  18. endif
  19. " The value of a single shift-width
  20. if exists('*shiftwidth')
  21. let sw = shiftwidth()
  22. else
  23. let sw = &sw
  24. endif
  25. " If need to indent based on last line
  26. let last_line = getline(a:lnum-1)
  27. if last_line =~ '^\s*{{-\=\s*\%(if\|else\|range\|with\|define\|block\).*}}'
  28. let ind += sw
  29. endif
  30. " End of FuncMap block
  31. let current_line = getline(a:lnum)
  32. if current_line =~ '^\s*{{-\=\s*\%(else\|end\).*}}'
  33. let ind -= sw
  34. endif
  35. return ind
  36. endfunction
  37. " vim: sw=2 ts=2 et