yacc.vim 858 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. " Vim indent file
  2. " Language: YACC input file
  3. " Maintainer: Doug Kearns <dougkearns@gmail.com>
  4. " Previous Maintainer: Nikolai Weibull <now@bitwi.se>
  5. " Last Change: 2022 April 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=GetYaccIndent()
  12. setlocal indentkeys=!^F,o,O
  13. setlocal nosmartindent
  14. let b:undo_indent = "setl inde< indk< si<"
  15. " Only define the function once.
  16. if exists("*GetYaccIndent")
  17. finish
  18. endif
  19. function GetYaccIndent()
  20. if v:lnum == 1
  21. return 0
  22. endif
  23. let ind = indent(v:lnum - 1)
  24. let line = getline(v:lnum - 1)
  25. if line == ''
  26. let ind = 0
  27. elseif line =~ '^\w\+\s*:'
  28. let ind = ind + matchend(line, '^\w\+\s*')
  29. elseif line =~ '^\s*;'
  30. let ind = 0
  31. else
  32. let ind = indent(v:lnum)
  33. endif
  34. return ind
  35. endfunction