tf.vim 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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: 2022 Apr 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. let b:undo_indent = "setlocal indentexpr< indentkeys<"
  15. " Only define the function once:
  16. if exists("*GetTFIndent")
  17. finish
  18. endif
  19. function GetTFIndent()
  20. " Find a non-blank line above the current line:
  21. let lnum = prevnonblank(v:lnum - 1)
  22. " No indent for the start of the file:
  23. if lnum == 0
  24. return 0
  25. endif
  26. let ind = indent(lnum)
  27. let line = getline(lnum)
  28. " No indentation if the previous line didn't end with "\":
  29. " (Could be annoying, but it lets you know if you made a mistake.)
  30. if line !~ '\\$'
  31. return 0
  32. endif
  33. if line =~ '\(/def.*\\\|/for.*\(%;\s*\)\@\<!\\\)$'
  34. let ind = ind + shiftwidth()
  35. elseif line =~ '\(/if\|/else\|/then\)'
  36. if line !~ '/endif'
  37. let ind = ind + shiftwidth()
  38. endif
  39. elseif line =~ '/while'
  40. if line !~ '/done'
  41. let ind = ind + shiftwidth()
  42. endif
  43. endif
  44. let line = getline(v:lnum)
  45. if line =~ '\(/else\|/endif\|/then\)'
  46. if line !~ '/if'
  47. let ind = ind - shiftwidth()
  48. endif
  49. elseif line =~ '/done'
  50. if line !~ '/while'
  51. let ind = ind - shiftwidth()
  52. endif
  53. endif
  54. " Comments at the beginning of a line:
  55. if line =~ '^\s*;'
  56. let ind = 0
  57. endif
  58. return ind
  59. endfunction