rrst.vim 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. " Vim indent file
  2. " Language: Rrst
  3. " Maintainer: This runtime file is looking for a new maintainer.
  4. " Former Maintainer: Jakson Alves de Aquino <jalvesaq@gmail.com>
  5. " Former Repository: https://github.com/jalvesaq/R-Vim-runtime
  6. " Last Change: 2023 Feb 25
  7. " 2024 Feb 19 by Vim Project (announce adoption)
  8. " Only load this indent file when no other was loaded.
  9. if exists("b:did_indent")
  10. finish
  11. endif
  12. runtime indent/r.vim
  13. let s:RIndent = function(substitute(&indentexpr, "()", "", ""))
  14. let b:did_indent = 1
  15. setlocal indentkeys=0{,0},:,!^F,o,O,e
  16. setlocal indentexpr=GetRrstIndent()
  17. let b:undo_indent = "setl inde< indk<"
  18. if exists("*GetRrstIndent")
  19. finish
  20. endif
  21. function GetRstIndent()
  22. let pline = getline(v:lnum - 1)
  23. let cline = getline(v:lnum)
  24. if prevnonblank(v:lnum - 1) < v:lnum - 1 || cline =~ '^\s*[-\+\*]\s' || cline =~ '^\s*\d\+\.\s\+'
  25. return indent(v:lnum)
  26. elseif pline =~ '^\s*[-\+\*]\s'
  27. return indent(v:lnum - 1) + 2
  28. elseif pline =~ '^\s*\d\+\.\s\+'
  29. return indent(v:lnum - 1) + 3
  30. endif
  31. return indent(prevnonblank(v:lnum - 1))
  32. endfunction
  33. function GetRrstIndent()
  34. if getline(".") =~ '^\.\. {r .*}$' || getline(".") =~ '^\.\. \.\.$'
  35. return 0
  36. endif
  37. if search('^\.\. {r', "bncW") > search('^\.\. \.\.$', "bncW")
  38. return s:RIndent()
  39. else
  40. return GetRstIndent()
  41. endif
  42. endfunction
  43. " vim: sw=2