blob: 47c764e29639dbb17fd4b830e3217e9cd5386beb [file] [log] [blame]
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001" Vim syntax file
2" Language: R Help File
Bram Moolenaar662db672011-03-22 14:05:35 +01003" Maintainer: Jakson Aquino <jalvesaq@gmail.com>
4" Former Maintainer: Johannes Ranke <jranke@uni-bremen.de>
Bram Moolenaar77cdfd12016-03-12 12:57:59 +01005" Homepage: https://github.com/jalvesaq/R-Vim-runtime
6" Last Change: Sat Feb 06, 2016 11:34AM
Bram Moolenaar81af9252010-12-10 20:35:50 +01007" Remarks: - Includes R syntax highlighting in the appropriate
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008" sections if an r.vim file is in the same directory or in the
9" default debian location.
Bram Moolenaar362e1a32006-03-06 23:29:24 +000010" - There is no Latex markup in equations
Bram Moolenaar5c736222010-01-06 20:54:52 +010011" - Thanks to Will Gray for finding and fixing a bug
Bram Moolenaar77cdfd12016-03-12 12:57:59 +010012" - No support for \var tag within quoted string
Bram Moolenaar362e1a32006-03-06 23:29:24 +000013
14" Version Clears: {{{1
Bram Moolenaar77cdfd12016-03-12 12:57:59 +010015if exists("b:current_syntax")
Bram Moolenaar362e1a32006-03-06 23:29:24 +000016 finish
17endif
18
Bram Moolenaar77cdfd12016-03-12 12:57:59 +010019scriptencoding utf-8
Bram Moolenaardb6ea062014-07-10 22:01:47 +020020setlocal iskeyword=@,48-57,_,.
21
Bram Moolenaar362e1a32006-03-06 23:29:24 +000022syn case match
23
Bram Moolenaar662db672011-03-22 14:05:35 +010024" R help identifiers {{{1
Bram Moolenaar362e1a32006-03-06 23:29:24 +000025syn region rhelpIdentifier matchgroup=rhelpSection start="\\name{" end="}"
26syn region rhelpIdentifier matchgroup=rhelpSection start="\\alias{" end="}"
Bram Moolenaar662db672011-03-22 14:05:35 +010027syn region rhelpIdentifier matchgroup=rhelpSection start="\\pkg{" end="}" contains=rhelpLink
Bram Moolenaar77cdfd12016-03-12 12:57:59 +010028syn region rhelpIdentifier matchgroup=rhelpSection start="\\CRANpkg{" end="}" contains=rhelpLink
Bram Moolenaar81af9252010-12-10 20:35:50 +010029syn region rhelpIdentifier matchgroup=rhelpSection start="\\method{" end="}" contained
30syn region rhelpIdentifier matchgroup=rhelpSection start="\\Rdversion{" end="}"
Bram Moolenaar362e1a32006-03-06 23:29:24 +000031
Bram Moolenaar77cdfd12016-03-12 12:57:59 +010032
Bram Moolenaar362e1a32006-03-06 23:29:24 +000033" Highlighting of R code using an existing r.vim syntax file if available {{{1
Bram Moolenaar18144c82006-04-12 21:52:12 +000034syn include @R syntax/r.vim
Bram Moolenaar362e1a32006-03-06 23:29:24 +000035
36" Strings {{{1
Bram Moolenaar662db672011-03-22 14:05:35 +010037syn region rhelpString start=/"/ skip=/\\"/ end=/"/ contains=rhelpSpecialChar,rhelpCodeSpecial,rhelpLink contained
Bram Moolenaar362e1a32006-03-06 23:29:24 +000038
Bram Moolenaar662db672011-03-22 14:05:35 +010039" Special characters in R strings
40syn match rhelpCodeSpecial display contained "\\\\\(n\|r\|t\|b\|a\|f\|v\|'\|\"\)\|\\\\"
41
42" Special characters ( \$ \& \% \# \{ \} \_)
Bram Moolenaar362e1a32006-03-06 23:29:24 +000043syn match rhelpSpecialChar "\\[$&%#{}_]"
44
Bram Moolenaar662db672011-03-22 14:05:35 +010045
46" R code {{{1
47syn match rhelpDots "\\dots" containedin=@R
48syn region rhelpRcode matchgroup=Delimiter start="\\examples{" matchgroup=Delimiter transparent end="}" contains=@R,rhelpLink,rhelpIdentifier,rhelpString,rhelpSpecialChar,rhelpSection
49syn region rhelpRcode matchgroup=Delimiter start="\\usage{" matchgroup=Delimiter transparent end="}" contains=@R,rhelpIdentifier,rhelpS4method
50syn region rhelpRcode matchgroup=Delimiter start="\\synopsis{" matchgroup=Delimiter transparent end="}" contains=@R
51syn region rhelpRcode matchgroup=Delimiter start="\\special{" matchgroup=Delimiter transparent end="}" contains=@R
Bram Moolenaardb6ea062014-07-10 22:01:47 +020052
53if v:version > 703
54 syn region rhelpRcode matchgroup=Delimiter start="\\code{" skip='\\\@1<!{.\{-}\\\@1<!}' transparent end="}" contains=@R,rhelpDots,rhelpString,rhelpSpecialChar,rhelpLink keepend
55else
56 syn region rhelpRcode matchgroup=Delimiter start="\\code{" skip='\\\@<!{.\{-}\\\@<!}' transparent end="}" contains=@R,rhelpDots,rhelpString,rhelpSpecialChar,rhelpLink keepend
57endif
Bram Moolenaar662db672011-03-22 14:05:35 +010058syn region rhelpS4method matchgroup=Delimiter start="\\S4method{.*}(" matchgroup=Delimiter transparent end=")" contains=@R,rhelpDots
59syn region rhelpSexpr matchgroup=Delimiter start="\\Sexpr{" matchgroup=Delimiter transparent end="}" contains=@R
60
61" PreProc {{{1
62syn match rhelpPreProc "^#ifdef.*"
63syn match rhelpPreProc "^#endif.*"
64
Bram Moolenaar362e1a32006-03-06 23:29:24 +000065" Special Delimiters {{{1
66syn match rhelpDelimiter "\\cr"
67syn match rhelpDelimiter "\\tab "
68
69" Keywords {{{1
Bram Moolenaar77cdfd12016-03-12 12:57:59 +010070syn match rhelpKeyword "\\R\>"
71syn match rhelpKeyword "\\ldots\>"
72syn match rhelpKeyword "\\sspace\>"
Bram Moolenaarf9393ef2006-04-24 19:47:27 +000073syn match rhelpKeyword "--"
74syn match rhelpKeyword "---"
Bram Moolenaar77cdfd12016-03-12 12:57:59 +010075
76" Condition Keywords {{{2
77syn match rhelpKeyword "\\if\>"
78syn match rhelpKeyword "\\ifelse\>"
79syn match rhelpKeyword "\\out\>"
80" Examples of usage:
81" \ifelse{latex}{\eqn{p = 5 + 6 - 7 \times 8}}{\eqn{p = 5 + 6 - 7 * 8}}
82" \ifelse{latex}{\out{$\alpha$}}{\ifelse{html}{\out{&alpha;}}{alpha}}
83
84" Keywords and operators valid only if in math mode {{{2
85syn match rhelpMathOp "<" contained
86syn match rhelpMathOp ">" contained
87syn match rhelpMathOp "+" contained
88syn match rhelpMathOp "-" contained
89syn match rhelpMathOp "=" contained
90
91" Conceal function based on syntax/tex.vim {{{2
92if exists("g:tex_conceal")
93 let s:tex_conceal = g:tex_conceal
94else
95 let s:tex_conceal = 'gm'
96endif
97function s:HideSymbol(pat, cchar, hide)
98 if a:hide
99 exe "syn match rhelpMathSymb '" . a:pat . "' contained conceal cchar=" . a:cchar
100 else
101 exe "syn match rhelpMathSymb '" . a:pat . "' contained"
102 endif
103endfunction
104
105" Math symbols {{{2
106if s:tex_conceal =~ 'm'
107 let s:hd = 1
108else
109 let s:hd = 0
110endif
111call s:HideSymbol('\\infty\>', '∞', s:hd)
112call s:HideSymbol('\\ge\>', '≥', s:hd)
113call s:HideSymbol('\\le\>', '≤', s:hd)
114call s:HideSymbol('\\prod\>', '∏', s:hd)
115call s:HideSymbol('\\sum\>', '∑', s:hd)
116syn match rhelpMathSymb "\\sqrt\>" contained
117
118" Greek letters {{{2
119if s:tex_conceal =~ 'g'
120 let s:hd = 1
121else
122 let s:hd = 0
123endif
124call s:HideSymbol('\\alpha\>', 'α', s:hd)
125call s:HideSymbol('\\beta\>', 'β', s:hd)
126call s:HideSymbol('\\gamma\>', 'γ', s:hd)
127call s:HideSymbol('\\delta\>', 'δ', s:hd)
128call s:HideSymbol('\\epsilon\>', 'ϵ', s:hd)
129call s:HideSymbol('\\zeta\>', 'ζ', s:hd)
130call s:HideSymbol('\\eta\>', 'η', s:hd)
131call s:HideSymbol('\\theta\>', 'θ', s:hd)
132call s:HideSymbol('\\iota\>', 'ι', s:hd)
133call s:HideSymbol('\\kappa\>', 'κ', s:hd)
134call s:HideSymbol('\\lambda\>', 'λ', s:hd)
135call s:HideSymbol('\\mu\>', 'μ', s:hd)
136call s:HideSymbol('\\nu\>', 'ν', s:hd)
137call s:HideSymbol('\\xi\>', 'ξ', s:hd)
138call s:HideSymbol('\\pi\>', 'π', s:hd)
139call s:HideSymbol('\\rho\>', 'ρ', s:hd)
140call s:HideSymbol('\\sigma\>', 'σ', s:hd)
141call s:HideSymbol('\\tau\>', 'τ', s:hd)
142call s:HideSymbol('\\upsilon\>', 'υ', s:hd)
143call s:HideSymbol('\\phi\>', 'ϕ', s:hd)
144call s:HideSymbol('\\chi\>', 'χ', s:hd)
145call s:HideSymbol('\\psi\>', 'ψ', s:hd)
146call s:HideSymbol('\\omega\>', 'ω', s:hd)
147call s:HideSymbol('\\Gamma\>', 'Γ', s:hd)
148call s:HideSymbol('\\Delta\>', 'Δ', s:hd)
149call s:HideSymbol('\\Theta\>', 'Θ', s:hd)
150call s:HideSymbol('\\Lambda\>', 'Λ', s:hd)
151call s:HideSymbol('\\Xi\>', 'Ξ', s:hd)
152call s:HideSymbol('\\Pi\>', 'Π', s:hd)
153call s:HideSymbol('\\Sigma\>', 'Σ', s:hd)
154call s:HideSymbol('\\Upsilon\>', 'Υ', s:hd)
155call s:HideSymbol('\\Phi\>', 'Φ', s:hd)
156call s:HideSymbol('\\Psi\>', 'Ψ', s:hd)
157call s:HideSymbol('\\Omega\>', 'Ω', s:hd)
158delfunction s:HideSymbol
159" Note: The letters 'omicron', 'Alpha', 'Beta', 'Epsilon', 'Zeta', 'Eta',
160" 'Iota', 'Kappa', 'Mu', 'Nu', 'Omicron', 'Rho', 'Tau' and 'Chi' are listed
161" at src/library/tools/R/Rd2txt.R because they are valid in HTML, although
162" they do not make valid LaTeX code (e.g. &Alpha; versus \Alpha).
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000163
164" Links {{{1
Bram Moolenaar77cdfd12016-03-12 12:57:59 +0100165syn region rhelpLink matchgroup=rhelpType start="\\link{" end="}" contained keepend extend
166syn region rhelpLink matchgroup=rhelpType start="\\link\[.\{-}\]{" end="}" contained keepend extend
167syn region rhelpLink matchgroup=rhelpType start="\\linkS4class{" end="}" contained keepend extend
168syn region rhelpLink matchgroup=rhelpType start="\\url{" end="}" contained keepend extend
169syn region rhelpLink matchgroup=rhelpType start="\\href{" end="}" contained keepend extend
170syn region rhelpLink matchgroup=rhelpType start="\\figure{" end="}" contained keepend extend
Bram Moolenaar662db672011-03-22 14:05:35 +0100171
172" Verbatim like {{{1
Bram Moolenaar77cdfd12016-03-12 12:57:59 +0100173syn region rhelpVerbatim matchgroup=rhelpType start="\\samp{" skip='\\\@1<!{.\{-}\\\@1<!}' end="}" contains=rhelpSpecialChar,rhelpComment
174syn region rhelpVerbatim matchgroup=rhelpType start="\\verb{" skip='\\\@1<!{.\{-}\\\@1<!}' end="}" contains=rhelpSpecialChar,rhelpComment
175
176" Equation {{{1
177syn region rhelpEquation matchgroup=rhelpType start="\\eqn{" skip='\\\@1<!{.\{-}\\\@1<!}' end="}" contains=rhelpMathSymb,rhelpMathOp,rhelpRegion contained keepend extend
178syn region rhelpEquation matchgroup=rhelpType start="\\deqn{" skip='\\\@1<!{.\{-}\\\@1<!}' end="}" contains=rhelpMathSymb,rhelpMathOp,rhelpRegion contained keepend extend
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000179
180" Type Styles {{{1
181syn match rhelpType "\\emph\>"
182syn match rhelpType "\\strong\>"
183syn match rhelpType "\\bold\>"
184syn match rhelpType "\\sQuote\>"
185syn match rhelpType "\\dQuote\>"
186syn match rhelpType "\\preformatted\>"
187syn match rhelpType "\\kbd\>"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000188syn match rhelpType "\\file\>"
189syn match rhelpType "\\email\>"
Bram Moolenaar77cdfd12016-03-12 12:57:59 +0100190syn match rhelpType "\\enc\>"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000191syn match rhelpType "\\var\>"
192syn match rhelpType "\\env\>"
193syn match rhelpType "\\option\>"
194syn match rhelpType "\\command\>"
Bram Moolenaar81af9252010-12-10 20:35:50 +0100195syn match rhelpType "\\newcommand\>"
196syn match rhelpType "\\renewcommand\>"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000197syn match rhelpType "\\dfn\>"
198syn match rhelpType "\\cite\>"
199syn match rhelpType "\\acronym\>"
Bram Moolenaar77cdfd12016-03-12 12:57:59 +0100200syn match rhelpType "\\doi\>"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000201
202" rhelp sections {{{1
203syn match rhelpSection "\\encoding\>"
204syn match rhelpSection "\\title\>"
Bram Moolenaar81af9252010-12-10 20:35:50 +0100205syn match rhelpSection "\\item\>"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000206syn match rhelpSection "\\description\>"
207syn match rhelpSection "\\concept\>"
208syn match rhelpSection "\\arguments\>"
209syn match rhelpSection "\\details\>"
210syn match rhelpSection "\\value\>"
211syn match rhelpSection "\\references\>"
212syn match rhelpSection "\\note\>"
213syn match rhelpSection "\\author\>"
214syn match rhelpSection "\\seealso\>"
215syn match rhelpSection "\\keyword\>"
216syn match rhelpSection "\\docType\>"
217syn match rhelpSection "\\format\>"
218syn match rhelpSection "\\source\>"
Bram Moolenaar81af9252010-12-10 20:35:50 +0100219syn match rhelpSection "\\itemize\>"
220syn match rhelpSection "\\describe\>"
221syn match rhelpSection "\\enumerate\>"
222syn match rhelpSection "\\item "
223syn match rhelpSection "\\item$"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000224syn match rhelpSection "\\tabular{[lcr]*}"
225syn match rhelpSection "\\dontrun\>"
226syn match rhelpSection "\\dontshow\>"
227syn match rhelpSection "\\testonly\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000228syn match rhelpSection "\\donttest\>"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000229
230" Freely named Sections {{{1
Bram Moolenaar81af9252010-12-10 20:35:50 +0100231syn region rhelpFreesec matchgroup=Delimiter start="\\section{" matchgroup=Delimiter transparent end="}"
232syn region rhelpFreesubsec matchgroup=Delimiter start="\\subsection{" matchgroup=Delimiter transparent end="}"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000233
Bram Moolenaar662db672011-03-22 14:05:35 +0100234syn match rhelpDelimiter "{\|\[\|(\|)\|\]\|}"
235
Bram Moolenaarf9393ef2006-04-24 19:47:27 +0000236" R help file comments {{{1
Bram Moolenaar81af9252010-12-10 20:35:50 +0100237syn match rhelpComment /%.*$/
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000238
239" Error {{{1
Bram Moolenaar77cdfd12016-03-12 12:57:59 +0100240syn region rhelpRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ contains=@Spell,rhelpCodeSpecial,rhelpComment,rhelpDelimiter,rhelpDots,rhelpFreesec,rhelpFreesubsec,rhelpIdentifier,rhelpKeyword,rhelpLink,rhelpPreProc,rhelpRComment,rhelpRcode,rhelpRegion,rhelpS4method,rhelpSection,rhelpSexpr,rhelpSpecialChar,rhelpString,rhelpType,rhelpVerbatim,rhelpEquation
241syn region rhelpRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ contains=@Spell,rhelpCodeSpecial,rhelpComment,rhelpDelimiter,rhelpDots,rhelpFreesec,rhelpFreesubsec,rhelpIdentifier,rhelpKeyword,rhelpLink,rhelpPreProc,rhelpRComment,rhelpRcode,rhelpRegion,rhelpS4method,rhelpSection,rhelpSexpr,rhelpSpecialChar,rhelpString,rhelpType,rhelpVerbatim,rhelpEquation
242syn region rhelpRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ contains=@Spell,rhelpCodeSpecial,rhelpComment,rhelpDelimiter,rhelpDots,rhelpFreesec,rhelpFreesubsec,rhelpIdentifier,rhelpKeyword,rhelpLink,rhelpPreProc,rhelpRComment,rhelpRcode,rhelpRegion,rhelpS4method,rhelpSection,rhelpSexpr,rhelpSpecialChar,rhelpString,rhelpType,rhelpVerbatim,rhelpEquation
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000243syn match rhelpError /[)\]}]/
244syn match rhelpBraceError /[)}]/ contained
245syn match rhelpCurlyError /[)\]]/ contained
246syn match rhelpParenError /[\]}]/ contained
247
Bram Moolenaardb6ea062014-07-10 22:01:47 +0200248syntax sync match rhelpSyncRcode grouphere rhelpRcode "\\examples{"
249
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000250" Define the default highlighting {{{1
Bram Moolenaar77cdfd12016-03-12 12:57:59 +0100251hi def link rhelpVerbatim String
252hi def link rhelpDelimiter Delimiter
253hi def link rhelpIdentifier Identifier
254hi def link rhelpString String
255hi def link rhelpCodeSpecial Special
256hi def link rhelpKeyword Keyword
257hi def link rhelpDots Keyword
258hi def link rhelpLink Underlined
259hi def link rhelpType Type
260hi def link rhelpSection PreCondit
261hi def link rhelpError Error
262hi def link rhelpBraceError Error
263hi def link rhelpCurlyError Error
264hi def link rhelpParenError Error
265hi def link rhelpPreProc PreProc
266hi def link rhelpDelimiter Delimiter
267hi def link rhelpComment Comment
268hi def link rhelpRComment Comment
269hi def link rhelpSpecialChar SpecialChar
270hi def link rhelpMathSymb Special
271hi def link rhelpMathOp Operator
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000272
273let b:current_syntax = "rhelp"
Bram Moolenaardb6ea062014-07-10 22:01:47 +0200274
275" vim: foldmethod=marker sw=2