blob: 7407538e4c8c07587d809facce819300698f6701 [file] [log] [blame]
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001" Vim syntax file
2" Language: R Help File
Christian Brabandtf9ca1392024-02-19 20:37:11 +01003" Maintainer: This runtime file is looking for a new maintainer.
4" Former Maintainers: Jakson Aquino <jalvesaq@gmail.com>
5" Johannes Ranke <jranke@uni-bremen.de>
6" Former Repository: https://github.com/jalvesaq/R-Vim-runtime
7" Last Change: 2016 Jun 28 08:53AM
8" 2024 Feb 19 by Vim Project (announce adoption)
Bram Moolenaar81af9252010-12-10 20:35:50 +01009" Remarks: - Includes R syntax highlighting in the appropriate
Bram Moolenaar362e1a32006-03-06 23:29:24 +000010" sections if an r.vim file is in the same directory or in the
11" default debian location.
Bram Moolenaar362e1a32006-03-06 23:29:24 +000012" - There is no Latex markup in equations
Bram Moolenaar5c736222010-01-06 20:54:52 +010013" - Thanks to Will Gray for finding and fixing a bug
Bram Moolenaar77cdfd12016-03-12 12:57:59 +010014" - No support for \var tag within quoted string
Bram Moolenaar362e1a32006-03-06 23:29:24 +000015
16" Version Clears: {{{1
Bram Moolenaar77cdfd12016-03-12 12:57:59 +010017if exists("b:current_syntax")
Bram Moolenaar362e1a32006-03-06 23:29:24 +000018 finish
19endif
20
Bram Moolenaar77cdfd12016-03-12 12:57:59 +010021scriptencoding utf-8
Bram Moolenaardb6ea062014-07-10 22:01:47 +020022
Bram Moolenaar362e1a32006-03-06 23:29:24 +000023syn case match
24
Bram Moolenaar662db672011-03-22 14:05:35 +010025" R help identifiers {{{1
Bram Moolenaar362e1a32006-03-06 23:29:24 +000026syn region rhelpIdentifier matchgroup=rhelpSection start="\\name{" end="}"
27syn region rhelpIdentifier matchgroup=rhelpSection start="\\alias{" end="}"
Bram Moolenaar662db672011-03-22 14:05:35 +010028syn region rhelpIdentifier matchgroup=rhelpSection start="\\pkg{" end="}" contains=rhelpLink
Bram Moolenaar77cdfd12016-03-12 12:57:59 +010029syn region rhelpIdentifier matchgroup=rhelpSection start="\\CRANpkg{" end="}" contains=rhelpLink
Bram Moolenaar81af9252010-12-10 20:35:50 +010030syn region rhelpIdentifier matchgroup=rhelpSection start="\\method{" end="}" contained
31syn region rhelpIdentifier matchgroup=rhelpSection start="\\Rdversion{" end="}"
Bram Moolenaar362e1a32006-03-06 23:29:24 +000032
Bram Moolenaar77cdfd12016-03-12 12:57:59 +010033
Bram Moolenaar362e1a32006-03-06 23:29:24 +000034" Highlighting of R code using an existing r.vim syntax file if available {{{1
Bram Moolenaar18144c82006-04-12 21:52:12 +000035syn include @R syntax/r.vim
Bram Moolenaar362e1a32006-03-06 23:29:24 +000036
37" Strings {{{1
Bram Moolenaar662db672011-03-22 14:05:35 +010038syn region rhelpString start=/"/ skip=/\\"/ end=/"/ contains=rhelpSpecialChar,rhelpCodeSpecial,rhelpLink contained
Bram Moolenaar362e1a32006-03-06 23:29:24 +000039
Bram Moolenaar662db672011-03-22 14:05:35 +010040" Special characters in R strings
41syn match rhelpCodeSpecial display contained "\\\\\(n\|r\|t\|b\|a\|f\|v\|'\|\"\)\|\\\\"
42
43" Special characters ( \$ \& \% \# \{ \} \_)
Bram Moolenaar362e1a32006-03-06 23:29:24 +000044syn match rhelpSpecialChar "\\[$&%#{}_]"
45
Bram Moolenaar662db672011-03-22 14:05:35 +010046
47" R code {{{1
48syn match rhelpDots "\\dots" containedin=@R
49syn region rhelpRcode matchgroup=Delimiter start="\\examples{" matchgroup=Delimiter transparent end="}" contains=@R,rhelpLink,rhelpIdentifier,rhelpString,rhelpSpecialChar,rhelpSection
50syn region rhelpRcode matchgroup=Delimiter start="\\usage{" matchgroup=Delimiter transparent end="}" contains=@R,rhelpIdentifier,rhelpS4method
51syn region rhelpRcode matchgroup=Delimiter start="\\synopsis{" matchgroup=Delimiter transparent end="}" contains=@R
52syn region rhelpRcode matchgroup=Delimiter start="\\special{" matchgroup=Delimiter transparent end="}" contains=@R
Bram Moolenaardb6ea062014-07-10 22:01:47 +020053
54if v:version > 703
55 syn region rhelpRcode matchgroup=Delimiter start="\\code{" skip='\\\@1<!{.\{-}\\\@1<!}' transparent end="}" contains=@R,rhelpDots,rhelpString,rhelpSpecialChar,rhelpLink keepend
56else
57 syn region rhelpRcode matchgroup=Delimiter start="\\code{" skip='\\\@<!{.\{-}\\\@<!}' transparent end="}" contains=@R,rhelpDots,rhelpString,rhelpSpecialChar,rhelpLink keepend
58endif
Bram Moolenaar662db672011-03-22 14:05:35 +010059syn region rhelpS4method matchgroup=Delimiter start="\\S4method{.*}(" matchgroup=Delimiter transparent end=")" contains=@R,rhelpDots
60syn region rhelpSexpr matchgroup=Delimiter start="\\Sexpr{" matchgroup=Delimiter transparent end="}" contains=@R
61
62" PreProc {{{1
63syn match rhelpPreProc "^#ifdef.*"
64syn match rhelpPreProc "^#endif.*"
65
Bram Moolenaar362e1a32006-03-06 23:29:24 +000066" Special Delimiters {{{1
67syn match rhelpDelimiter "\\cr"
68syn match rhelpDelimiter "\\tab "
69
70" Keywords {{{1
Bram Moolenaar77cdfd12016-03-12 12:57:59 +010071syn match rhelpKeyword "\\R\>"
72syn match rhelpKeyword "\\ldots\>"
73syn match rhelpKeyword "\\sspace\>"
Bram Moolenaarf9393ef2006-04-24 19:47:27 +000074syn match rhelpKeyword "--"
75syn match rhelpKeyword "---"
Bram Moolenaar77cdfd12016-03-12 12:57:59 +010076
77" Condition Keywords {{{2
78syn match rhelpKeyword "\\if\>"
79syn match rhelpKeyword "\\ifelse\>"
80syn match rhelpKeyword "\\out\>"
81" Examples of usage:
82" \ifelse{latex}{\eqn{p = 5 + 6 - 7 \times 8}}{\eqn{p = 5 + 6 - 7 * 8}}
83" \ifelse{latex}{\out{$\alpha$}}{\ifelse{html}{\out{&alpha;}}{alpha}}
84
85" Keywords and operators valid only if in math mode {{{2
86syn match rhelpMathOp "<" contained
87syn match rhelpMathOp ">" contained
88syn match rhelpMathOp "+" contained
89syn match rhelpMathOp "-" contained
90syn match rhelpMathOp "=" contained
91
92" Conceal function based on syntax/tex.vim {{{2
93if exists("g:tex_conceal")
94 let s:tex_conceal = g:tex_conceal
95else
96 let s:tex_conceal = 'gm'
97endif
98function s:HideSymbol(pat, cchar, hide)
99 if a:hide
100 exe "syn match rhelpMathSymb '" . a:pat . "' contained conceal cchar=" . a:cchar
101 else
102 exe "syn match rhelpMathSymb '" . a:pat . "' contained"
103 endif
104endfunction
105
106" Math symbols {{{2
107if s:tex_conceal =~ 'm'
108 let s:hd = 1
109else
110 let s:hd = 0
111endif
112call s:HideSymbol('\\infty\>', '∞', s:hd)
113call s:HideSymbol('\\ge\>', '≥', s:hd)
114call s:HideSymbol('\\le\>', '≤', s:hd)
115call s:HideSymbol('\\prod\>', '∏', s:hd)
116call s:HideSymbol('\\sum\>', '∑', s:hd)
117syn match rhelpMathSymb "\\sqrt\>" contained
118
119" Greek letters {{{2
120if s:tex_conceal =~ 'g'
121 let s:hd = 1
122else
123 let s:hd = 0
124endif
125call s:HideSymbol('\\alpha\>', 'α', s:hd)
126call s:HideSymbol('\\beta\>', 'β', s:hd)
127call s:HideSymbol('\\gamma\>', 'γ', s:hd)
128call s:HideSymbol('\\delta\>', 'δ', s:hd)
129call s:HideSymbol('\\epsilon\>', 'ϵ', s:hd)
130call s:HideSymbol('\\zeta\>', 'ζ', s:hd)
131call s:HideSymbol('\\eta\>', 'η', s:hd)
132call s:HideSymbol('\\theta\>', 'θ', s:hd)
133call s:HideSymbol('\\iota\>', 'ι', s:hd)
134call s:HideSymbol('\\kappa\>', 'κ', s:hd)
135call s:HideSymbol('\\lambda\>', 'λ', s:hd)
136call s:HideSymbol('\\mu\>', 'μ', s:hd)
137call s:HideSymbol('\\nu\>', 'ν', s:hd)
138call s:HideSymbol('\\xi\>', 'ξ', s:hd)
139call s:HideSymbol('\\pi\>', 'π', s:hd)
140call s:HideSymbol('\\rho\>', 'ρ', s:hd)
141call s:HideSymbol('\\sigma\>', 'σ', s:hd)
142call s:HideSymbol('\\tau\>', 'τ', s:hd)
143call s:HideSymbol('\\upsilon\>', 'υ', s:hd)
144call s:HideSymbol('\\phi\>', 'ϕ', s:hd)
145call s:HideSymbol('\\chi\>', 'χ', s:hd)
146call s:HideSymbol('\\psi\>', 'ψ', s:hd)
147call s:HideSymbol('\\omega\>', 'ω', s:hd)
148call s:HideSymbol('\\Gamma\>', 'Γ', s:hd)
149call s:HideSymbol('\\Delta\>', 'Δ', s:hd)
150call s:HideSymbol('\\Theta\>', 'Θ', s:hd)
151call s:HideSymbol('\\Lambda\>', 'Λ', s:hd)
152call s:HideSymbol('\\Xi\>', 'Ξ', s:hd)
153call s:HideSymbol('\\Pi\>', 'Π', s:hd)
154call s:HideSymbol('\\Sigma\>', 'Σ', s:hd)
155call s:HideSymbol('\\Upsilon\>', 'Υ', s:hd)
156call s:HideSymbol('\\Phi\>', 'Φ', s:hd)
157call s:HideSymbol('\\Psi\>', 'Ψ', s:hd)
158call s:HideSymbol('\\Omega\>', 'Ω', s:hd)
159delfunction s:HideSymbol
160" Note: The letters 'omicron', 'Alpha', 'Beta', 'Epsilon', 'Zeta', 'Eta',
161" 'Iota', 'Kappa', 'Mu', 'Nu', 'Omicron', 'Rho', 'Tau' and 'Chi' are listed
162" at src/library/tools/R/Rd2txt.R because they are valid in HTML, although
163" they do not make valid LaTeX code (e.g. &Alpha; versus \Alpha).
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000164
165" Links {{{1
Bram Moolenaar77cdfd12016-03-12 12:57:59 +0100166syn region rhelpLink matchgroup=rhelpType start="\\link{" end="}" contained keepend extend
167syn region rhelpLink matchgroup=rhelpType start="\\link\[.\{-}\]{" end="}" contained keepend extend
168syn region rhelpLink matchgroup=rhelpType start="\\linkS4class{" end="}" contained keepend extend
169syn region rhelpLink matchgroup=rhelpType start="\\url{" end="}" contained keepend extend
170syn region rhelpLink matchgroup=rhelpType start="\\href{" end="}" contained keepend extend
171syn region rhelpLink matchgroup=rhelpType start="\\figure{" end="}" contained keepend extend
Bram Moolenaar662db672011-03-22 14:05:35 +0100172
173" Verbatim like {{{1
Bram Moolenaar77cdfd12016-03-12 12:57:59 +0100174syn region rhelpVerbatim matchgroup=rhelpType start="\\samp{" skip='\\\@1<!{.\{-}\\\@1<!}' end="}" contains=rhelpSpecialChar,rhelpComment
175syn region rhelpVerbatim matchgroup=rhelpType start="\\verb{" skip='\\\@1<!{.\{-}\\\@1<!}' end="}" contains=rhelpSpecialChar,rhelpComment
176
177" Equation {{{1
178syn region rhelpEquation matchgroup=rhelpType start="\\eqn{" skip='\\\@1<!{.\{-}\\\@1<!}' end="}" contains=rhelpMathSymb,rhelpMathOp,rhelpRegion contained keepend extend
179syn region rhelpEquation matchgroup=rhelpType start="\\deqn{" skip='\\\@1<!{.\{-}\\\@1<!}' end="}" contains=rhelpMathSymb,rhelpMathOp,rhelpRegion contained keepend extend
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000180
181" Type Styles {{{1
182syn match rhelpType "\\emph\>"
183syn match rhelpType "\\strong\>"
184syn match rhelpType "\\bold\>"
185syn match rhelpType "\\sQuote\>"
186syn match rhelpType "\\dQuote\>"
187syn match rhelpType "\\preformatted\>"
188syn match rhelpType "\\kbd\>"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000189syn match rhelpType "\\file\>"
190syn match rhelpType "\\email\>"
Bram Moolenaar77cdfd12016-03-12 12:57:59 +0100191syn match rhelpType "\\enc\>"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000192syn match rhelpType "\\var\>"
193syn match rhelpType "\\env\>"
194syn match rhelpType "\\option\>"
195syn match rhelpType "\\command\>"
Bram Moolenaar81af9252010-12-10 20:35:50 +0100196syn match rhelpType "\\newcommand\>"
197syn match rhelpType "\\renewcommand\>"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000198syn match rhelpType "\\dfn\>"
199syn match rhelpType "\\cite\>"
200syn match rhelpType "\\acronym\>"
Bram Moolenaar77cdfd12016-03-12 12:57:59 +0100201syn match rhelpType "\\doi\>"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000202
203" rhelp sections {{{1
204syn match rhelpSection "\\encoding\>"
205syn match rhelpSection "\\title\>"
Bram Moolenaar81af9252010-12-10 20:35:50 +0100206syn match rhelpSection "\\item\>"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000207syn match rhelpSection "\\description\>"
208syn match rhelpSection "\\concept\>"
209syn match rhelpSection "\\arguments\>"
210syn match rhelpSection "\\details\>"
211syn match rhelpSection "\\value\>"
212syn match rhelpSection "\\references\>"
213syn match rhelpSection "\\note\>"
214syn match rhelpSection "\\author\>"
215syn match rhelpSection "\\seealso\>"
216syn match rhelpSection "\\keyword\>"
217syn match rhelpSection "\\docType\>"
218syn match rhelpSection "\\format\>"
219syn match rhelpSection "\\source\>"
Bram Moolenaar81af9252010-12-10 20:35:50 +0100220syn match rhelpSection "\\itemize\>"
221syn match rhelpSection "\\describe\>"
222syn match rhelpSection "\\enumerate\>"
223syn match rhelpSection "\\item "
224syn match rhelpSection "\\item$"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000225syn match rhelpSection "\\tabular{[lcr]*}"
226syn match rhelpSection "\\dontrun\>"
227syn match rhelpSection "\\dontshow\>"
228syn match rhelpSection "\\testonly\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000229syn match rhelpSection "\\donttest\>"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000230
231" Freely named Sections {{{1
Bram Moolenaar81af9252010-12-10 20:35:50 +0100232syn region rhelpFreesec matchgroup=Delimiter start="\\section{" matchgroup=Delimiter transparent end="}"
233syn region rhelpFreesubsec matchgroup=Delimiter start="\\subsection{" matchgroup=Delimiter transparent end="}"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000234
Bram Moolenaar662db672011-03-22 14:05:35 +0100235syn match rhelpDelimiter "{\|\[\|(\|)\|\]\|}"
236
Bram Moolenaarf9393ef2006-04-24 19:47:27 +0000237" R help file comments {{{1
Bram Moolenaar81af9252010-12-10 20:35:50 +0100238syn match rhelpComment /%.*$/
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000239
240" Error {{{1
Bram Moolenaar77cdfd12016-03-12 12:57:59 +0100241syn 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
243syn 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 +0000244syn match rhelpError /[)\]}]/
245syn match rhelpBraceError /[)}]/ contained
246syn match rhelpCurlyError /[)\]]/ contained
247syn match rhelpParenError /[\]}]/ contained
248
Bram Moolenaardb6ea062014-07-10 22:01:47 +0200249syntax sync match rhelpSyncRcode grouphere rhelpRcode "\\examples{"
250
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000251" Define the default highlighting {{{1
Bram Moolenaar77cdfd12016-03-12 12:57:59 +0100252hi def link rhelpVerbatim String
253hi def link rhelpDelimiter Delimiter
254hi def link rhelpIdentifier Identifier
255hi def link rhelpString String
256hi def link rhelpCodeSpecial Special
257hi def link rhelpKeyword Keyword
258hi def link rhelpDots Keyword
259hi def link rhelpLink Underlined
260hi def link rhelpType Type
261hi def link rhelpSection PreCondit
262hi def link rhelpError Error
263hi def link rhelpBraceError Error
264hi def link rhelpCurlyError Error
265hi def link rhelpParenError Error
266hi def link rhelpPreProc PreProc
267hi def link rhelpDelimiter Delimiter
268hi def link rhelpComment Comment
269hi def link rhelpRComment Comment
270hi def link rhelpSpecialChar SpecialChar
271hi def link rhelpMathSymb Special
272hi def link rhelpMathOp Operator
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000273
274let b:current_syntax = "rhelp"
Bram Moolenaardb6ea062014-07-10 22:01:47 +0200275
276" vim: foldmethod=marker sw=2