tf.vim 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. " Vim indent file
  2. " Language: tf (TinyFugue)
  3. " Maintainer: Christian J. Robinson <heptite@gmail.com>
  4. " URL: http://www.vim.org/scripts/script.php?script_id=174
  5. " Last Change: 2017 Feb 25
  6. " Only load this indent file when no other was loaded.
  7. if exists("b:did_indent")
  8. finish
  9. endif
  10. let b:did_indent = 1
  11. setlocal indentexpr=GetTFIndent()
  12. setlocal indentkeys-=0{,0} indentkeys-=0# indentkeys-=:
  13. setlocal indentkeys+==/endif,=/then,=/else,=/done,0;
  14. " Only define the function once:
  15. if exists("*GetTFIndent")
  16. finish
  17. endif
  18. function GetTFIndent()
  19. " Find a non-blank line above the current line:
  20. let lnum = prevnonblank(v:lnum - 1)
  21. " No indent for the start of the file:
  22. if lnum == 0
  23. return 0
  24. endif
  25. let ind = indent(lnum)
  26. let line = getline(lnum)
  27. " No indentation if the previous line didn't end with "\":
  28. " (Could be annoying, but it lets you know if you made a mistake.)
  29. if line !~ '\\$'
  30. return 0
  31. endif
  32. if line =~ '\(/def.*\\\|/for.*\(%;\s*\)\@\<!\\\)$'
  33. let ind = ind + shiftwidth()
  34. elseif line =~ '\(/if\|/else\|/then\)'
  35. if line !~ '/endif'
  36. let ind = ind + shiftwidth()
  37. endif
  38. elseif line =~ '/while'
  39. if line !~ '/done'
  40. let ind = ind + shiftwidth()
  41. endif
  42. endif
  43. let line = getline(v:lnum)
  44. if line =~ '\(/else\|/endif\|/then\)'
  45. if line !~ '/if'
  46. let ind = ind - shiftwidth()
  47. endif
  48. elseif line =~ '/done'
  49. if line !~ '/while'
  50. let ind = ind - shiftwidth()
  51. endif
  52. endif
  53. " Comments at the beginning of a line:
  54. if line =~ '^\s*;'
  55. let ind = 0
  56. endif
  57. return ind
  58. endfunction