robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
9bb046d1be
master
1" Vim indent file 2" Language: R Documentation (Help), *.Rd 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 27 07:01PM 7" 2024 Feb 19 by Vim Project (announce adoption) 8 9 10" Only load this indent file when no other was loaded. 11if exists ( "b:did_indent" ) 12finish 13endif 14runtime indent/r.vim 15let s: RIndent = function ( substitute ( & indentexpr , "()" , "" , "" )) 16let b: did_indent = 1 17 18setlocal noautoindent 19setlocal nocindent 20setlocal nosmartindent 21setlocal nolisp 22setlocal indentkeys = 0{,0},:,!^F,o,O,e 23setlocal indentexpr = GetCorrectRHelpIndent () 24 25let b: undo_indent = "setl ai< cin< inde< indk< lisp< si<" 26 27" Only define the functions once. 28if exists ( "*GetRHelpIndent" ) 29finish 30endif 31 32function s: SanitizeRHelpLine ( line ) 33let newline = substitute ( a: line , '\\\\' , "x" , "g" ) 34let newline = substitute ( newline , '\\{' , "x" , "g" ) 35let newline = substitute ( newline , '\\}' , "x" , "g" ) 36let newline = substitute ( newline , '\\%' , "x" , "g" ) 37let newline = substitute ( newline , '%.*' , "" , "" ) 38let newline = substitute ( newline , '\s*$' , "" , "" ) 39return newline 40endfunction 41 42function GetRHelpIndent () 43 44let clnum = line ( "." ) " current line 45if clnum == 1 46return 0 47endif 48let cline = getline ( clnum ) 49 50if cline =~ '^\s*}\s*$' 51let i = clnum 52let bb = -1 53while bb != 0 && i > 1 54let i -= 1 55let line = s: SanitizeRHelpLine ( getline ( i )) 56let line2 = substitute ( line , "{" , "" , "g" ) 57let openb = strlen ( line ) - strlen ( line2 ) 58let line3 = substitute ( line2 , "}" , "" , "g" ) 59let closeb = strlen ( line2 ) - strlen ( line3 ) 60let bb += openb - closeb 61endwhile 62return indent ( i ) 63endif 64 65if cline =~ '^\s*#ifdef\>' || cline =~ '^\s*#endif\>' 66return 0 67endif 68 69let lnum = clnum - 1 70let line = getline ( lnum ) 71if line =~ '^\s*#ifdef\>' || line =~ '^\s*#endif\>' 72let lnum -= 1 73let line = getline ( lnum ) 74endif 75while lnum > 1 && ( line =~ '^\s*$' || line =~ '^#ifdef' || line =~ '^#endif' ) 76let lnum -= 1 77let line = getline ( lnum ) 78endwhile 79if lnum == 1 80return 0 81endif 82let line = s: SanitizeRHelpLine ( line ) 83let line2 = substitute ( line , "{" , "" , "g" ) 84let openb = strlen ( line ) - strlen ( line2 ) 85let line3 = substitute ( line2 , "}" , "" , "g" ) 86let closeb = strlen ( line2 ) - strlen ( line3 ) 87let bb = openb - closeb 88 89let ind = indent ( lnum ) + ( bb * shiftwidth ()) 90 91if line =~ '^\s*}\s*$' 92let ind = indent ( lnum ) 93endif 94 95if ind < 0 96return 0 97endif 98 99return ind 100endfunction 101 102function GetCorrectRHelpIndent () 103let lastsection = search ( '^\\[a-z]*{' , "bncW" ) 104let secname = getline ( lastsection ) 105if secname =~ '^\\usage{' || secname =~ '^\\examples{' || secname =~ '^\\dontshow{' || secname =~ '^\\dontrun{' || secname =~ '^\\donttest{' || secname =~ '^\\testonly{' || secname =~ '^\\method{.*}{.*}(' 106return s: RIndent () 107else 108return GetRHelpIndent () 109endif 110endfunction 111 112" vim: sw=2