"Fossies" - the Fresh Open Source Software Archive

Member "vim-8.2.1354/runtime/indent/rhelp.vim" (2 Aug 2020, 2840 Bytes) of package /linux/misc/vim-8.2.1354.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) vimscript source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

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