annotate runtime/indent/rhelp.vim @ 9442:4fe3772969cf v7.4.2002

commit https://github.com/vim/vim/commit/a06ec8f345eabb66e5b7d7c0192cfebdde63115d Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jul 8 20:11:07 2016 +0200 patch 7.4.2002 Problem: Crash when passing number to filter() or map(). Solution: Convert to a string. (Ozaki Kiichi)
author Christian Brabandt <cb@256bit.org>
date Fri, 08 Jul 2016 20:15:06 +0200
parents da01d5da2cfa
children 4aae8146c21f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1 " Vim indent file
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2 " Language: R Documentation (Help), *.Rd
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3 " Author: Jakson Alves de Aquino <jalvesaq@gmail.com>
8497
da01d5da2cfa commit https://github.com/vim/vim/commit/77cdfd10382e01cc51f4ba1a9177032351843151
Christian Brabandt <cb@256bit.org>
parents: 6840
diff changeset
4 " Homepage: https://github.com/jalvesaq/R-Vim-runtime
da01d5da2cfa commit https://github.com/vim/vim/commit/77cdfd10382e01cc51f4ba1a9177032351843151
Christian Brabandt <cb@256bit.org>
parents: 6840
diff changeset
5 " Last Change: Tue Apr 07, 2015 04:38PM
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
7
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
8 " Only load this indent file when no other was loaded.
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
9 if exists("b:did_indent")
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
10 finish
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
11 endif
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
12 runtime indent/r.vim
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
13 let s:RIndent = function(substitute(&indentexpr, "()", "", ""))
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
14 let b:did_indent = 1
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
15
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
16 setlocal noautoindent
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
17 setlocal nocindent
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
18 setlocal nosmartindent
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
19 setlocal nolisp
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
20 setlocal indentkeys=0{,0},:,!^F,o,O,e
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
21 setlocal indentexpr=GetCorrectRHelpIndent()
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
22
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 6051
diff changeset
23 " Only define the functions once.
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 6051
diff changeset
24 if exists("*GetRHelpIndent")
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 6051
diff changeset
25 finish
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 6051
diff changeset
26 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 6051
diff changeset
27
6051
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
28 function s:SanitizeRHelpLine(line)
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
29 let newline = substitute(a:line, '\\\\', "x", "g")
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
30 let newline = substitute(newline, '\\{', "x", "g")
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
31 let newline = substitute(newline, '\\}', "x", "g")
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
32 let newline = substitute(newline, '\\%', "x", "g")
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
33 let newline = substitute(newline, '%.*', "", "")
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
34 let newline = substitute(newline, '\s*$', "", "")
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
35 return newline
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
36 endfunction
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
37
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
38 function GetRHelpIndent()
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
39
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
40 let clnum = line(".") " current line
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
41 if clnum == 1
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
42 return 0
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
43 endif
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
44 let cline = getline(clnum)
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
45
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
46 if cline =~ '^\s*}\s*$'
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
47 let i = clnum
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
48 let bb = -1
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
49 while bb != 0 && i > 1
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
50 let i -= 1
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
51 let line = s:SanitizeRHelpLine(getline(i))
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
52 let line2 = substitute(line, "{", "", "g")
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
53 let openb = strlen(line) - strlen(line2)
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
54 let line3 = substitute(line2, "}", "", "g")
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
55 let closeb = strlen(line2) - strlen(line3)
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
56 let bb += openb - closeb
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
57 endwhile
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
58 return indent(i)
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
59 endif
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
60
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
61 if cline =~ '^\s*#ifdef\>' || cline =~ '^\s*#endif\>'
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
62 return 0
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
63 endif
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
64
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
65 let lnum = clnum - 1
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
66 let line = getline(lnum)
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
67 if line =~ '^\s*#ifdef\>' || line =~ '^\s*#endif\>'
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
68 let lnum -= 1
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
69 let line = getline(lnum)
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
70 endif
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
71 while lnum > 1 && (line =~ '^\s*$' || line =~ '^#ifdef' || line =~ '^#endif')
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
72 let lnum -= 1
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
73 let line = getline(lnum)
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
74 endwhile
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
75 if lnum == 1
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
76 return 0
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
77 endif
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
78 let line = s:SanitizeRHelpLine(line)
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
79 let line2 = substitute(line, "{", "", "g")
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
80 let openb = strlen(line) - strlen(line2)
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
81 let line3 = substitute(line2, "}", "", "g")
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
82 let closeb = strlen(line2) - strlen(line3)
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
83 let bb = openb - closeb
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
84
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
85 let ind = indent(lnum) + (bb * &sw)
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
86
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
87 if line =~ '^\s*}\s*$'
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
88 let ind = indent(lnum)
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
89 endif
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
90
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
91 if ind < 0
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
92 return 0
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
93 endif
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
94
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
95 return ind
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
96 endfunction
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
97
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
98 function GetCorrectRHelpIndent()
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
99 let lastsection = search('^\\[a-z]*{', "bncW")
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
100 let secname = getline(lastsection)
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
101 if secname =~ '^\\usage{' || secname =~ '^\\examples{' || secname =~ '^\\dontshow{' || secname =~ '^\\dontrun{' || secname =~ '^\\donttest{' || secname =~ '^\\testonly{' || secname =~ '^\\method{.*}{.*}('
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
102 return s:RIndent()
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
103 else
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
104 return GetRHelpIndent()
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
105 endif
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
106 endfunction
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
107
0efec12f52ac Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
108 " vim: sw=2