treetop.vim 785 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. " Vim indent file
  2. " Language: Treetop
  3. " Maintainer: Doug Kearns <dougkearns@gmail.com>
  4. " Previous Maintainer: Nikolai Weibull <now@bitwi.se>
  5. " Last Change: 2022 April 25
  6. if exists("b:did_indent")
  7. finish
  8. endif
  9. let b:did_indent = 1
  10. setlocal indentexpr=GetTreetopIndent()
  11. setlocal indentkeys=0{,0},!^F,o,O,=end
  12. setlocal nosmartindent
  13. let b:undo_indent = "setl inde< indk< si<"
  14. if exists("*GetTreetopIndent")
  15. finish
  16. endif
  17. function GetTreetopIndent()
  18. let pnum = prevnonblank(v:lnum - 1)
  19. if pnum == 0
  20. return 0
  21. endif
  22. let ind = indent(pnum)
  23. let line = getline(pnum)
  24. if line =~ '^\s*\%(grammar\|module\|rule\)\>'
  25. let ind += shiftwidth()
  26. endif
  27. let line = getline(v:lnum)
  28. if line =~ '^\s*end\>'
  29. let ind -= shiftwidth()
  30. end
  31. return ind
  32. endfunction