blob: 8cac585bb0feb6e14dc809e94bfb1e707ffd4dc2 [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
Bram Moolenaare4a3bcf2016-08-26 19:52:37 +02006" Last Change: Tue Jun 28, 2016 08:53AM
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 +020020
Bram Moolenaar362e1a32006-03-06 23:29:24 +000021syn case match
22
Bram Moolenaar662db672011-03-22 14:05:35 +010023" R help identifiers {{{1
Bram Moolenaar362e1a32006-03-06 23:29:24 +000024syn region rhelpIdentifier matchgroup=rhelpSection start="\\name{" end="}"
25syn region rhelpIdentifier matchgroup=rhelpSection start="\\alias{" end="}"
Bram Moolenaar662db672011-03-22 14:05:35 +010026syn region rhelpIdentifier matchgroup=rhelpSection start="\\pkg{" end="}" contains=rhelpLink
Bram Moolenaar77cdfd12016-03-12 12:57:59 +010027syn region rhelpIdentifier matchgroup=rhelpSection start="\\CRANpkg{" end="}" contains=rhelpLink
Bram Moolenaar81af9252010-12-10 20:35:50 +010028syn region rhelpIdentifier matchgroup=rhelpSection start="\\method{" end="}" contained
29syn region rhelpIdentifier matchgroup=rhelpSection start="\\Rdversion{" end="}"
Bram Moolenaar362e1a32006-03-06 23:29:24 +000030
Bram Moolenaar77cdfd12016-03-12 12:57:59 +010031
Bram Moolenaar362e1a32006-03-06 23:29:24 +000032" Highlighting of R code using an existing r.vim syntax file if available {{{1
Bram Moolenaar18144c82006-04-12 21:52:12 +000033syn include @R syntax/r.vim
Bram Moolenaar362e1a32006-03-06 23:29:24 +000034
35" Strings {{{1
Bram Moolenaar662db672011-03-22 14:05:35 +010036syn region rhelpString start=/"/ skip=/\\"/ end=/"/ contains=rhelpSpecialChar,rhelpCodeSpecial,rhelpLink contained
Bram Moolenaar362e1a32006-03-06 23:29:24 +000037
Bram Moolenaar662db672011-03-22 14:05:35 +010038" Special characters in R strings
39syn match rhelpCodeSpecial display contained "\\\\\(n\|r\|t\|b\|a\|f\|v\|'\|\"\)\|\\\\"
40
41" Special characters ( \$ \& \% \# \{ \} \_)
Bram Moolenaar362e1a32006-03-06 23:29:24 +000042syn match rhelpSpecialChar "\\[$&%#{}_]"
43
Bram Moolenaar662db672011-03-22 14:05:35 +010044
45" R code {{{1
46syn match rhelpDots "\\dots" containedin=@R
47syn region rhelpRcode matchgroup=Delimiter start="\\examples{" matchgroup=Delimiter transparent end="}" contains=@R,rhelpLink,rhelpIdentifier,rhelpString,rhelpSpecialChar,rhelpSection
48syn region rhelpRcode matchgroup=Delimiter start="\\usage{" matchgroup=Delimiter transparent end="}" contains=@R,rhelpIdentifier,rhelpS4method
49syn region rhelpRcode matchgroup=Delimiter start="\\synopsis{" matchgroup=Delimiter transparent end="}" contains=@R
50syn region rhelpRcode matchgroup=Delimiter start="\\special{" matchgroup=Delimiter transparent end="}" contains=@R
Bram Moolenaardb6ea062014-07-10 22:01:47 +020051
52if v:version > 703
53 syn region rhelpRcode matchgroup=Delimiter start="\\code{" skip='\\\@1<!{.\{-}\\\@1<!}' transparent end="}" contains=@R,rhelpDots,rhelpString,rhelpSpecialChar,rhelpLink keepend
54else
55 syn region rhelpRcode matchgroup=Delimiter start="\\code{" skip='\\\@<!{.\{-}\\\@<!}' transparent end="}" contains=@R,rhelpDots,rhelpString,rhelpSpecialChar,rhelpLink keepend
56endif
Bram Moolenaar662db672011-03-22 14:05:35 +010057syn region rhelpS4method matchgroup=Delimiter start="\\S4method{.*}(" matchgroup=Delimiter transparent end=")" contains=@R,rhelpDots
58syn region rhelpSexpr matchgroup=Delimiter start="\\Sexpr{" matchgroup=Delimiter transparent end="}" contains=@R
59
60" PreProc {{{1
61syn match rhelpPreProc "^#ifdef.*"
62syn match rhelpPreProc "^#endif.*"
63
Bram Moolenaar362e1a32006-03-06 23:29:24 +000064" Special Delimiters {{{1
65syn match rhelpDelimiter "\\cr"
66syn match rhelpDelimiter "\\tab "
67
68" Keywords {{{1
Bram Moolenaar77cdfd12016-03-12 12:57:59 +010069syn match rhelpKeyword "\\R\>"
70syn match rhelpKeyword "\\ldots\>"
71syn match rhelpKeyword "\\sspace\>"
Bram Moolenaarf9393ef2006-04-24 19:47:27 +000072syn match rhelpKeyword "--"
73syn match rhelpKeyword "---"
Bram Moolenaar77cdfd12016-03-12 12:57:59 +010074
75" Condition Keywords {{{2
76syn match rhelpKeyword "\\if\>"
77syn match rhelpKeyword "\\ifelse\>"
78syn match rhelpKeyword "\\out\>"
79" Examples of usage:
80" \ifelse{latex}{\eqn{p = 5 + 6 - 7 \times 8}}{\eqn{p = 5 + 6 - 7 * 8}}
81" \ifelse{latex}{\out{$\alpha$}}{\ifelse{html}{\out{&alpha;}}{alpha}}
82
83" Keywords and operators valid only if in math mode {{{2
84syn match rhelpMathOp "<" contained
85syn match rhelpMathOp ">" contained
86syn match rhelpMathOp "+" contained
87syn match rhelpMathOp "-" contained
88syn match rhelpMathOp "=" contained
89
90" Conceal function based on syntax/tex.vim {{{2
91if exists("g:tex_conceal")
92 let s:tex_conceal = g:tex_conceal
93else
94 let s:tex_conceal = 'gm'
95endif
96function s:HideSymbol(pat, cchar, hide)
97 if a:hide
98 exe "syn match rhelpMathSymb '" . a:pat . "' contained conceal cchar=" . a:cchar
99 else
100 exe "syn match rhelpMathSymb '" . a:pat . "' contained"
101 endif
102endfunction
103
104" Math symbols {{{2
105if s:tex_conceal =~ 'm'
106 let s:hd = 1
107else
108 let s:hd = 0
109endif
110call s:HideSymbol('\\infty\>', '∞', s:hd)
111call s:HideSymbol('\\ge\>', '≥', s:hd)
112call s:HideSymbol('\\le\>', '≤', s:hd)
113call s:HideSymbol('\\prod\>', '∏', s:hd)
114call s:HideSymbol('\\sum\>', '∑', s:hd)
115syn match rhelpMathSymb "\\sqrt\>" contained
116
117" Greek letters {{{2
118if s:tex_conceal =~ 'g'
119 let s:hd = 1
120else
121 let s:hd = 0
122endif
123call s:HideSymbol('\\alpha\>', 'α', s:hd)
124call s:HideSymbol('\\beta\>', 'β', s:hd)
125call s:HideSymbol('\\gamma\>', 'γ', s:hd)
126call s:HideSymbol('\\delta\>', 'δ', s:hd)
127call s:HideSymbol('\\epsilon\>', 'ϵ', s:hd)
128call s:HideSymbol('\\zeta\>', 'ζ', s:hd)
129call s:HideSymbol('\\eta\>', 'η', s:hd)
130call s:HideSymbol('\\theta\>', 'θ', s:hd)
131call s:HideSymbol('\\iota\>', 'ι', s:hd)
132call s:HideSymbol('\\kappa\>', 'κ', s:hd)
133call s:HideSymbol('\\lambda\>', 'λ', s:hd)
134call s:HideSymbol('\\mu\>', 'μ', s:hd)
135call s:HideSymbol('\\nu\>', 'ν', s:hd)
136call s:HideSymbol('\\xi\>', 'ξ', s:hd)
137call s:HideSymbol('\\pi\>', 'π', s:hd)
138call s:HideSymbol('\\rho\>', 'ρ', s:hd)
139call s:HideSymbol('\\sigma\>', 'σ', s:hd)
140call s:HideSymbol('\\tau\>', 'τ', s:hd)
141call s:HideSymbol('\\upsilon\>', 'υ', s:hd)
142call s:HideSymbol('\\phi\>', 'ϕ', s:hd)
143call s:HideSymbol('\\chi\>', 'χ', s:hd)
144call s:HideSymbol('\\psi\>', 'ψ', s:hd)
145call s:HideSymbol('\\omega\>', 'ω', s:hd)
146call s:HideSymbol('\\Gamma\>', 'Γ', s:hd)
147call s:HideSymbol('\\Delta\>', 'Δ', s:hd)
148call s:HideSymbol('\\Theta\>', 'Θ', s:hd)
149call s:HideSymbol('\\Lambda\>', 'Λ', s:hd)
150call s:HideSymbol('\\Xi\>', 'Ξ', s:hd)
151call s:HideSymbol('\\Pi\>', 'Π', s:hd)
152call s:HideSymbol('\\Sigma\>', 'Σ', s:hd)
153call s:HideSymbol('\\Upsilon\>', 'Υ', s:hd)
154call s:HideSymbol('\\Phi\>', 'Φ', s:hd)
155call s:HideSymbol('\\Psi\>', 'Ψ', s:hd)
156call s:HideSymbol('\\Omega\>', 'Ω', s:hd)
157delfunction s:HideSymbol
158" Note: The letters 'omicron', 'Alpha', 'Beta', 'Epsilon', 'Zeta', 'Eta',
159" 'Iota', 'Kappa', 'Mu', 'Nu', 'Omicron', 'Rho', 'Tau' and 'Chi' are listed
160" at src/library/tools/R/Rd2txt.R because they are valid in HTML, although
161" they do not make valid LaTeX code (e.g. &Alpha; versus \Alpha).
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000162
163" Links {{{1
Bram Moolenaar77cdfd12016-03-12 12:57:59 +0100164syn region rhelpLink matchgroup=rhelpType start="\\link{" end="}" contained keepend extend
165syn region rhelpLink matchgroup=rhelpType start="\\link\[.\{-}\]{" end="}" contained keepend extend
166syn region rhelpLink matchgroup=rhelpType start="\\linkS4class{" end="}" contained keepend extend
167syn region rhelpLink matchgroup=rhelpType start="\\url{" end="}" contained keepend extend
168syn region rhelpLink matchgroup=rhelpType start="\\href{" end="}" contained keepend extend
169syn region rhelpLink matchgroup=rhelpType start="\\figure{" end="}" contained keepend extend
Bram Moolenaar662db672011-03-22 14:05:35 +0100170
171" Verbatim like {{{1
Bram Moolenaar77cdfd12016-03-12 12:57:59 +0100172syn region rhelpVerbatim matchgroup=rhelpType start="\\samp{" skip='\\\@1<!{.\{-}\\\@1<!}' end="}" contains=rhelpSpecialChar,rhelpComment
173syn region rhelpVerbatim matchgroup=rhelpType start="\\verb{" skip='\\\@1<!{.\{-}\\\@1<!}' end="}" contains=rhelpSpecialChar,rhelpComment
174
175" Equation {{{1
176syn region rhelpEquation matchgroup=rhelpType start="\\eqn{" skip='\\\@1<!{.\{-}\\\@1<!}' end="}" contains=rhelpMathSymb,rhelpMathOp,rhelpRegion contained keepend extend
177syn region rhelpEquation matchgroup=rhelpType start="\\deqn{" skip='\\\@1<!{.\{-}\\\@1<!}' end="}" contains=rhelpMathSymb,rhelpMathOp,rhelpRegion contained keepend extend
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000178
179" Type Styles {{{1
180syn match rhelpType "\\emph\>"
181syn match rhelpType "\\strong\>"
182syn match rhelpType "\\bold\>"
183syn match rhelpType "\\sQuote\>"
184syn match rhelpType "\\dQuote\>"
185syn match rhelpType "\\preformatted\>"
186syn match rhelpType "\\kbd\>"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000187syn match rhelpType "\\file\>"
188syn match rhelpType "\\email\>"
Bram Moolenaar77cdfd12016-03-12 12:57:59 +0100189syn match rhelpType "\\enc\>"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000190syn match rhelpType "\\var\>"
191syn match rhelpType "\\env\>"
192syn match rhelpType "\\option\>"
193syn match rhelpType "\\command\>"
Bram Moolenaar81af9252010-12-10 20:35:50 +0100194syn match rhelpType "\\newcommand\>"
195syn match rhelpType "\\renewcommand\>"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000196syn match rhelpType "\\dfn\>"
197syn match rhelpType "\\cite\>"
198syn match rhelpType "\\acronym\>"
Bram Moolenaar77cdfd12016-03-12 12:57:59 +0100199syn match rhelpType "\\doi\>"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000200
201" rhelp sections {{{1
202syn match rhelpSection "\\encoding\>"
203syn match rhelpSection "\\title\>"
Bram Moolenaar81af9252010-12-10 20:35:50 +0100204syn match rhelpSection "\\item\>"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000205syn match rhelpSection "\\description\>"
206syn match rhelpSection "\\concept\>"
207syn match rhelpSection "\\arguments\>"
208syn match rhelpSection "\\details\>"
209syn match rhelpSection "\\value\>"
210syn match rhelpSection "\\references\>"
211syn match rhelpSection "\\note\>"
212syn match rhelpSection "\\author\>"
213syn match rhelpSection "\\seealso\>"
214syn match rhelpSection "\\keyword\>"
215syn match rhelpSection "\\docType\>"
216syn match rhelpSection "\\format\>"
217syn match rhelpSection "\\source\>"
Bram Moolenaar81af9252010-12-10 20:35:50 +0100218syn match rhelpSection "\\itemize\>"
219syn match rhelpSection "\\describe\>"
220syn match rhelpSection "\\enumerate\>"
221syn match rhelpSection "\\item "
222syn match rhelpSection "\\item$"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000223syn match rhelpSection "\\tabular{[lcr]*}"
224syn match rhelpSection "\\dontrun\>"
225syn match rhelpSection "\\dontshow\>"
226syn match rhelpSection "\\testonly\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000227syn match rhelpSection "\\donttest\>"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000228
229" Freely named Sections {{{1
Bram Moolenaar81af9252010-12-10 20:35:50 +0100230syn region rhelpFreesec matchgroup=Delimiter start="\\section{" matchgroup=Delimiter transparent end="}"
231syn region rhelpFreesubsec matchgroup=Delimiter start="\\subsection{" matchgroup=Delimiter transparent end="}"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000232
Bram Moolenaar662db672011-03-22 14:05:35 +0100233syn match rhelpDelimiter "{\|\[\|(\|)\|\]\|}"
234
Bram Moolenaarf9393ef2006-04-24 19:47:27 +0000235" R help file comments {{{1
Bram Moolenaar81af9252010-12-10 20:35:50 +0100236syn match rhelpComment /%.*$/
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000237
238" Error {{{1
Bram Moolenaar77cdfd12016-03-12 12:57:59 +0100239syn 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
240syn 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
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000242syn match rhelpError /[)\]}]/
243syn match rhelpBraceError /[)}]/ contained
244syn match rhelpCurlyError /[)\]]/ contained
245syn match rhelpParenError /[\]}]/ contained
246
Bram Moolenaardb6ea062014-07-10 22:01:47 +0200247syntax sync match rhelpSyncRcode grouphere rhelpRcode "\\examples{"
248
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000249" Define the default highlighting {{{1
Bram Moolenaar77cdfd12016-03-12 12:57:59 +0100250hi def link rhelpVerbatim String
251hi def link rhelpDelimiter Delimiter
252hi def link rhelpIdentifier Identifier
253hi def link rhelpString String
254hi def link rhelpCodeSpecial Special
255hi def link rhelpKeyword Keyword
256hi def link rhelpDots Keyword
257hi def link rhelpLink Underlined
258hi def link rhelpType Type
259hi def link rhelpSection PreCondit
260hi def link rhelpError Error
261hi def link rhelpBraceError Error
262hi def link rhelpCurlyError Error
263hi def link rhelpParenError Error
264hi def link rhelpPreProc PreProc
265hi def link rhelpDelimiter Delimiter
266hi def link rhelpComment Comment
267hi def link rhelpRComment Comment
268hi def link rhelpSpecialChar SpecialChar
269hi def link rhelpMathSymb Special
270hi def link rhelpMathOp Operator
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000271
272let b:current_syntax = "rhelp"
Bram Moolenaardb6ea062014-07-10 22:01:47 +0200273
274" vim: foldmethod=marker sw=2