rrst.vim (1352B)
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 9 10 " Only load this indent file when no other was loaded. 11 if exists("b:did_indent") 12 finish 13 endif 14 runtime indent/r.vim 15 let s:RIndent = function(substitute(&indentexpr, "()", "", "")) 16 let b:did_indent = 1 17 18 setlocal indentkeys=0{,0},:,!^F,o,O,e 19 setlocal indentexpr=GetRrstIndent() 20 21 let b:undo_indent = "setl inde< indk<" 22 23 if exists("*GetRrstIndent") 24 finish 25 endif 26 27 function GetRstIndent() 28 let pline = getline(v:lnum - 1) 29 let cline = getline(v:lnum) 30 if prevnonblank(v:lnum - 1) < v:lnum - 1 || cline =~ '^\s*[-\+\*]\s' || cline =~ '^\s*\d\+\.\s\+' 31 return indent(v:lnum) 32 elseif pline =~ '^\s*[-\+\*]\s' 33 return indent(v:lnum - 1) + 2 34 elseif pline =~ '^\s*\d\+\.\s\+' 35 return indent(v:lnum - 1) + 3 36 endif 37 return indent(prevnonblank(v:lnum - 1)) 38 endfunction 39 40 function GetRrstIndent() 41 if getline(".") =~ '^\.\. {r .*}$' || getline(".") =~ '^\.\. \.\.$' 42 return 0 43 endif 44 if search('^\.\. {r', "bncW") > search('^\.\. \.\.$', "bncW") 45 return s:RIndent() 46 else 47 return GetRstIndent() 48 endif 49 endfunction 50 51 " vim: sw=2