robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqvim-patch:f9ca139e3aa1 (#27554)9bb046d1be

master
3.0 KiB112 linesraw
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")
12  finish
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")
29  finish
30endif
31
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 newline
40endfunction
41
42function GetRHelpIndent()
43
44  let clnum = line(".")    " current line
45  if clnum == 1
46    return 0
47  endif
48  let cline = getline(clnum)
49
50  if cline =~ '^\s*}\s*$'
51    let i = clnum
52    let bb = -1
53    while bb != 0 && i > 1
54      let i -= 1
55      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 - closeb
61    endwhile
62    return indent(i)
63  endif
64
65  if cline =~ '^\s*#ifdef\>' || cline =~ '^\s*#endif\>'
66    return 0
67  endif
68
69  let lnum = clnum - 1
70  let line = getline(lnum)
71  if line =~ '^\s*#ifdef\>' || line =~ '^\s*#endif\>'
72    let lnum -= 1
73    let line = getline(lnum)
74  endif
75  while lnum > 1 && (line =~ '^\s*$' || line =~ '^#ifdef' || line =~ '^#endif')
76    let lnum -= 1
77    let line = getline(lnum)
78  endwhile
79  if lnum == 1
80    return 0
81  endif
82  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 - closeb
88
89  let ind = indent(lnum) + (bb * shiftwidth())
90
91  if line =~ '^\s*}\s*$'
92    let ind = indent(lnum)
93  endif
94
95  if ind < 0
96    return 0
97  endif
98
99  return ind
100endfunction
101
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  else
108    return GetRHelpIndent()
109  endif
110endfunction
111
112" vim: sw=2