Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
rhelp.vim113 linesDownload Raw Back to indent
1" Vim indent file2" Language:	R Documentation (Help), *.Rd3" 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-runtime6" Last Change:	2023 Feb 27  07:01PM7"		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")12  finish13endif14runtime indent/r.vim15let s:RIndent = function(substitute(&indentexpr, "()", "", ""))16let b:did_indent = 117 18setlocal noautoindent19setlocal nocindent20setlocal nosmartindent21setlocal nolisp22setlocal indentkeys=0{,0},:,!^F,o,O,e23setlocal indentexpr=GetCorrectRHelpIndent()24 25let b:undo_indent = "setl ai< cin< inde< indk< lisp< si<"26 27" Only define the functions once.28if exists("*GetRHelpIndent")29  finish30endif31 32function s:SanitizeRHelpLine(line)33  let newline = substitute(a:line, '\\\\', "x", "g")34  let newline = substitute(newline, '\\{', "x", "g")35  let newline = substitute(newline, '\\}', "x", "g")36  let newline = substitute(newline, '\\%', "x", "g")37  let newline = substitute(newline, '%.*', "", "")38  let newline = substitute(newline, '\s*$', "", "")39  return newline40endfunction41 42function GetRHelpIndent()43 44  let clnum = line(".")    " current line45  if clnum == 146    return 047  endif48  let cline = getline(clnum)49 50  if cline =~ '^\s*}\s*$'51    let i = clnum52    let bb = -153    while bb != 0 && i > 154      let i -= 155      let line = s:SanitizeRHelpLine(getline(i))56      let line2 = substitute(line, "{", "", "g")57      let openb = strlen(line) - strlen(line2)58      let line3 = substitute(line2, "}", "", "g")59      let closeb = strlen(line2) - strlen(line3)60      let bb += openb - closeb61    endwhile62    return indent(i)63  endif64 65  if cline =~ '^\s*#ifdef\>' || cline =~ '^\s*#endif\>'66    return 067  endif68 69  let lnum = clnum - 170  let line = getline(lnum)71  if line =~ '^\s*#ifdef\>' || line =~ '^\s*#endif\>'72    let lnum -= 173    let line = getline(lnum)74  endif75  while lnum > 1 && (line =~ '^\s*$' || line =~ '^#ifdef' || line =~ '^#endif')76    let lnum -= 177    let line = getline(lnum)78  endwhile79  if lnum == 180    return 081  endif82  let line = s:SanitizeRHelpLine(line)83  let line2 = substitute(line, "{", "", "g")84  let openb = strlen(line) - strlen(line2)85  let line3 = substitute(line2, "}", "", "g")86  let closeb = strlen(line2) - strlen(line3)87  let bb = openb - closeb88 89  let ind = indent(lnum) + (bb * shiftwidth())90 91  if line =~ '^\s*}\s*$'92    let ind = indent(lnum)93  endif94 95  if ind < 096    return 097  endif98 99  return ind100endfunction101 102function GetCorrectRHelpIndent()103  let lastsection = search('^\\[a-z]*{', "bncW")104  let secname = getline(lastsection)105  if secname =~ '^\\usage{' || secname =~ '^\\examples{' || secname =~ '^\\dontshow{' || secname =~ '^\\dontrun{' || secname =~ '^\\donttest{' || secname =~ '^\\testonly{' || secname =~ '^\\method{.*}{.*}('106    return s:RIndent()107  else108    return GetRHelpIndent()109  endif110endfunction111 112" vim: sw=2113 
codekingpro/portable-devtools · Team Ai