teraterm.vim 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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: 2021-10-18
  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. let b:undo_indent = "setl ai< inde< indk< si<"
  19. if exists("*GetTeraTermIndent")
  20. finish
  21. endif
  22. function! GetTeraTermIndent(lnum)
  23. let l:prevlnum = prevnonblank(a:lnum-1)
  24. if l:prevlnum == 0
  25. " top of file
  26. return 0
  27. endif
  28. " grab the previous and current line, stripping comments.
  29. let l:prevl = substitute(getline(l:prevlnum), ';.*$', '', '')
  30. let l:thisl = substitute(getline(a:lnum), ';.*$', '', '')
  31. let l:previ = indent(l:prevlnum)
  32. let l:ind = l:previ
  33. if l:prevl =~ '^\s*if\>.*\<then\>'
  34. " previous line opened a block
  35. let l:ind += shiftwidth()
  36. endif
  37. if l:prevl =~ '^\s*\%(elseif\|else\|do\|until\|while\|for\)\>'
  38. " previous line opened a block
  39. let l:ind += shiftwidth()
  40. endif
  41. if l:thisl =~ '^\s*\%(elseif\|else\|endif\|enduntil\|endwhile\|loop\|next\)\>'
  42. " this line closed a block
  43. let l:ind -= shiftwidth()
  44. endif
  45. return l:ind
  46. endfunction
  47. " vim: ts=8 sw=2 sts=2