teraterm.vim 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. " Vim indent file
  2. " Language: Tera Term Language (TTL)
  3. " Based on Tera Term Version 4.100
  4. " Maintainer: Ken Takata
  5. " URL: https://github.com/k-takata/vim-teraterm
  6. " Last Change: 2018-08-31
  7. " Filenames: *.ttl
  8. " License: VIM License
  9. if exists("b:did_indent")
  10. finish
  11. endif
  12. let b:did_indent = 1
  13. setlocal nosmartindent
  14. setlocal noautoindent
  15. setlocal indentexpr=GetTeraTermIndent(v:lnum)
  16. setlocal indentkeys=!^F,o,O,e
  17. setlocal indentkeys+==elseif,=endif,=loop,=next,=enduntil,=endwhile
  18. if exists("*GetTeraTermIndent")
  19. finish
  20. endif
  21. function! GetTeraTermIndent(lnum)
  22. let l:prevlnum = prevnonblank(a:lnum-1)
  23. if l:prevlnum == 0
  24. " top of file
  25. return 0
  26. endif
  27. " grab the previous and current line, stripping comments.
  28. let l:prevl = substitute(getline(l:prevlnum), ';.*$', '', '')
  29. let l:thisl = substitute(getline(a:lnum), ';.*$', '', '')
  30. let l:previ = indent(l:prevlnum)
  31. let l:ind = l:previ
  32. if l:prevl =~ '^\s*if\>.*\<then\>'
  33. " previous line opened a block
  34. let l:ind += shiftwidth()
  35. endif
  36. if l:prevl =~ '^\s*\%(elseif\|else\|do\|until\|while\|for\)\>'
  37. " previous line opened a block
  38. let l:ind += shiftwidth()
  39. endif
  40. if l:thisl =~ '^\s*\%(elseif\|else\|endif\|enduntil\|endwhile\|loop\|next\)\>'
  41. " this line closed a block
  42. let l:ind -= shiftwidth()
  43. endif
  44. return l:ind
  45. endfunction
  46. " vim: ts=8 sw=2 sts=2