xref: /vim-8.2.3635/runtime/syntax/rhelp.vim (revision 77cdfd10)
1" Vim syntax file
2" Language:    R Help File
3" Maintainer: Jakson Aquino <[email protected]>
4" Former Maintainer: Johannes Ranke <[email protected]>
5" Homepage: https://github.com/jalvesaq/R-Vim-runtime
6" Last Change: Sat Feb 06, 2016  11:34AM
7" Remarks:     - Includes R syntax highlighting in the appropriate
8"                sections if an r.vim file is in the same directory or in the
9"                default debian location.
10"              - There is no Latex markup in equations
11"              - Thanks to Will Gray for finding and fixing a bug
12"              - No support for \var tag within quoted string
13
14" Version Clears: {{{1
15if exists("b:current_syntax")
16  finish
17endif
18
19scriptencoding utf-8
20setlocal iskeyword=@,48-57,_,.
21
22syn case match
23
24" R help identifiers {{{1
25syn region rhelpIdentifier matchgroup=rhelpSection	start="\\name{" end="}"
26syn region rhelpIdentifier matchgroup=rhelpSection	start="\\alias{" end="}"
27syn region rhelpIdentifier matchgroup=rhelpSection	start="\\pkg{" end="}" contains=rhelpLink
28syn region rhelpIdentifier matchgroup=rhelpSection	start="\\CRANpkg{" end="}" contains=rhelpLink
29syn region rhelpIdentifier matchgroup=rhelpSection start="\\method{" end="}" contained
30syn region rhelpIdentifier matchgroup=rhelpSection start="\\Rdversion{" end="}"
31
32
33" Highlighting of R code using an existing r.vim syntax file if available {{{1
34syn include @R syntax/r.vim
35
36" Strings {{{1
37syn region rhelpString start=/"/ skip=/\\"/ end=/"/ contains=rhelpSpecialChar,rhelpCodeSpecial,rhelpLink contained
38
39" Special characters in R strings
40syn match rhelpCodeSpecial display contained "\\\\\(n\|r\|t\|b\|a\|f\|v\|'\|\"\)\|\\\\"
41
42" Special characters  ( \$ \& \% \# \{ \} \_)
43syn match rhelpSpecialChar        "\\[$&%#{}_]"
44
45
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
52
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
58syn 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
65" Special Delimiters {{{1
66syn match rhelpDelimiter		"\\cr"
67syn match rhelpDelimiter		"\\tab "
68
69" Keywords {{{1
70syn match rhelpKeyword	"\\R\>"
71syn match rhelpKeyword	"\\ldots\>"
72syn match rhelpKeyword	"\\sspace\>"
73syn match rhelpKeyword  "--"
74syn match rhelpKeyword  "---"
75
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).
163
164" Links {{{1
165syn 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
171
172" Verbatim like {{{1
173syn 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
179
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\>"
188syn match rhelpType		"\\file\>"
189syn match rhelpType		"\\email\>"
190syn match rhelpType		"\\enc\>"
191syn match rhelpType		"\\var\>"
192syn match rhelpType		"\\env\>"
193syn match rhelpType		"\\option\>"
194syn match rhelpType		"\\command\>"
195syn match rhelpType		"\\newcommand\>"
196syn match rhelpType		"\\renewcommand\>"
197syn match rhelpType		"\\dfn\>"
198syn match rhelpType		"\\cite\>"
199syn match rhelpType		"\\acronym\>"
200syn match rhelpType		"\\doi\>"
201
202" rhelp sections {{{1
203syn match rhelpSection		"\\encoding\>"
204syn match rhelpSection		"\\title\>"
205syn match rhelpSection		"\\item\>"
206syn 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\>"
219syn match rhelpSection    "\\itemize\>"
220syn match rhelpSection    "\\describe\>"
221syn match rhelpSection    "\\enumerate\>"
222syn match rhelpSection    "\\item "
223syn match rhelpSection    "\\item$"
224syn match rhelpSection		"\\tabular{[lcr]*}"
225syn match rhelpSection		"\\dontrun\>"
226syn match rhelpSection		"\\dontshow\>"
227syn match rhelpSection		"\\testonly\>"
228syn match rhelpSection		"\\donttest\>"
229
230" Freely named Sections {{{1
231syn region rhelpFreesec matchgroup=Delimiter start="\\section{" matchgroup=Delimiter transparent end="}"
232syn region rhelpFreesubsec matchgroup=Delimiter start="\\subsection{" matchgroup=Delimiter transparent end="}"
233
234syn match rhelpDelimiter "{\|\[\|(\|)\|\]\|}"
235
236" R help file comments {{{1
237syn match rhelpComment /%.*$/
238
239" Error {{{1
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
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 match rhelpError      /[)\]}]/
244syn match rhelpBraceError /[)}]/ contained
245syn match rhelpCurlyError /[)\]]/ contained
246syn match rhelpParenError /[\]}]/ contained
247
248syntax sync match rhelpSyncRcode grouphere rhelpRcode "\\examples{"
249
250" Define the default highlighting {{{1
251hi 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
272
273let   b:current_syntax = "rhelp"
274
275" vim: foldmethod=marker sw=2
276