yacc.vim 781 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. " Vim indent file
  2. " Language: YACC input file
  3. " Previous Maintainer: Nikolai Weibull <now@bitwi.se>
  4. " Latest Revision: 2006-12-20
  5. " Only load this indent file when no other was loaded.
  6. if exists("b:did_indent")
  7. finish
  8. endif
  9. let b:did_indent = 1
  10. setlocal indentexpr=GetYaccIndent()
  11. setlocal indentkeys=!^F,o,O
  12. setlocal nosmartindent
  13. " Only define the function once.
  14. if exists("*GetYaccIndent")
  15. finish
  16. endif
  17. function GetYaccIndent()
  18. if v:lnum == 1
  19. return 0
  20. endif
  21. let ind = indent(v:lnum - 1)
  22. let line = getline(v:lnum - 1)
  23. if line == ''
  24. let ind = 0
  25. elseif line =~ '^\w\+\s*:'
  26. let ind = ind + matchend(line, '^\w\+\s*')
  27. elseif line =~ '^\s*;'
  28. let ind = 0
  29. else
  30. let ind = indent(v:lnum)
  31. endif
  32. return ind
  33. endfunction