rrst.vim 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. " Vim indent file
  2. " Language: Rrst
  3. " Author: Jakson Alves de Aquino <jalvesaq@gmail.com>
  4. " Homepage: https://github.com/jalvesaq/R-Vim-runtime
  5. " Last Change: Tue Apr 07, 2015 04:38PM
  6. " Only load this indent file when no other was loaded.
  7. if exists("b:did_indent")
  8. finish
  9. endif
  10. runtime indent/r.vim
  11. let s:RIndent = function(substitute(&indentexpr, "()", "", ""))
  12. let b:did_indent = 1
  13. setlocal indentkeys=0{,0},:,!^F,o,O,e
  14. setlocal indentexpr=GetRrstIndent()
  15. if exists("*GetRrstIndent")
  16. finish
  17. endif
  18. function GetRstIndent()
  19. let pline = getline(v:lnum - 1)
  20. let cline = getline(v:lnum)
  21. if prevnonblank(v:lnum - 1) < v:lnum - 1 || cline =~ '^\s*[-\+\*]\s' || cline =~ '^\s*\d\+\.\s\+'
  22. return indent(v:lnum)
  23. elseif pline =~ '^\s*[-\+\*]\s'
  24. return indent(v:lnum - 1) + 2
  25. elseif pline =~ '^\s*\d\+\.\s\+'
  26. return indent(v:lnum - 1) + 3
  27. endif
  28. return indent(prevnonblank(v:lnum - 1))
  29. endfunction
  30. function GetRrstIndent()
  31. if getline(".") =~ '^\.\. {r .*}$' || getline(".") =~ '^\.\. \.\.$'
  32. return 0
  33. endif
  34. if search('^\.\. {r', "bncW") > search('^\.\. \.\.$', "bncW")
  35. return s:RIndent()
  36. else
  37. return GetRstIndent()
  38. endif
  39. endfunction
  40. " vim: sw=2