blob: 32c91add4823b943b0f0fbff765d6f69dae31978 [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 Moolenaardb6ea062014-07-10 22:01:47 +02005" Last Change: Wed Jul 09, 2014 10:28PM
Bram Moolenaar81af9252010-12-10 20:35:50 +01006" Remarks: - Includes R syntax highlighting in the appropriate
Bram Moolenaar362e1a32006-03-06 23:29:24 +00007" sections if an r.vim file is in the same directory or in the
8" default debian location.
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009" - There is no Latex markup in equations
Bram Moolenaar5c736222010-01-06 20:54:52 +010010" - Thanks to Will Gray for finding and fixing a bug
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011" - No support for \if, \ifelse and \out as I don't understand
12" them and have no examples at hand (help welcome).
13" - No support for \var tag within quoted string (dito)
Bram Moolenaar362e1a32006-03-06 23:29:24 +000014
15" Version Clears: {{{1
16" For version 5.x: Clear all syntax items
Bram Moolenaar910f66f2006-04-05 20:41:53 +000017" For version 6.x and 7.x: Quit when a syntax file was already loaded
Bram Moolenaar362e1a32006-03-06 23:29:24 +000018if version < 600
19 syntax clear
20elseif exists("b:current_syntax")
21 finish
22endif
23
Bram Moolenaardb6ea062014-07-10 22:01:47 +020024setlocal iskeyword=@,48-57,_,.
25
Bram Moolenaar362e1a32006-03-06 23:29:24 +000026syn case match
27
Bram Moolenaar662db672011-03-22 14:05:35 +010028" R help identifiers {{{1
Bram Moolenaar362e1a32006-03-06 23:29:24 +000029syn region rhelpIdentifier matchgroup=rhelpSection start="\\name{" end="}"
30syn region rhelpIdentifier matchgroup=rhelpSection start="\\alias{" end="}"
Bram Moolenaar662db672011-03-22 14:05:35 +010031syn region rhelpIdentifier matchgroup=rhelpSection start="\\pkg{" end="}" contains=rhelpLink
Bram Moolenaar81af9252010-12-10 20:35:50 +010032syn region rhelpIdentifier matchgroup=rhelpSection start="\\method{" end="}" contained
33syn region rhelpIdentifier matchgroup=rhelpSection start="\\Rdversion{" end="}"
Bram Moolenaar362e1a32006-03-06 23:29:24 +000034
35" Highlighting of R code using an existing r.vim syntax file if available {{{1
Bram Moolenaar18144c82006-04-12 21:52:12 +000036syn include @R syntax/r.vim
Bram Moolenaar362e1a32006-03-06 23:29:24 +000037
38" Strings {{{1
Bram Moolenaar662db672011-03-22 14:05:35 +010039syn region rhelpString start=/"/ skip=/\\"/ end=/"/ contains=rhelpSpecialChar,rhelpCodeSpecial,rhelpLink contained
Bram Moolenaar362e1a32006-03-06 23:29:24 +000040
Bram Moolenaar662db672011-03-22 14:05:35 +010041" Special characters in R strings
42syn match rhelpCodeSpecial display contained "\\\\\(n\|r\|t\|b\|a\|f\|v\|'\|\"\)\|\\\\"
43
44" Special characters ( \$ \& \% \# \{ \} \_)
Bram Moolenaar362e1a32006-03-06 23:29:24 +000045syn match rhelpSpecialChar "\\[$&%#{}_]"
46
Bram Moolenaar662db672011-03-22 14:05:35 +010047
48" R code {{{1
49syn match rhelpDots "\\dots" containedin=@R
50syn region rhelpRcode matchgroup=Delimiter start="\\examples{" matchgroup=Delimiter transparent end="}" contains=@R,rhelpLink,rhelpIdentifier,rhelpString,rhelpSpecialChar,rhelpSection
51syn region rhelpRcode matchgroup=Delimiter start="\\usage{" matchgroup=Delimiter transparent end="}" contains=@R,rhelpIdentifier,rhelpS4method
52syn region rhelpRcode matchgroup=Delimiter start="\\synopsis{" matchgroup=Delimiter transparent end="}" contains=@R
53syn region rhelpRcode matchgroup=Delimiter start="\\special{" matchgroup=Delimiter transparent end="}" contains=@R
Bram Moolenaardb6ea062014-07-10 22:01:47 +020054
55if v:version > 703
56 syn region rhelpRcode matchgroup=Delimiter start="\\code{" skip='\\\@1<!{.\{-}\\\@1<!}' transparent end="}" contains=@R,rhelpDots,rhelpString,rhelpSpecialChar,rhelpLink keepend
57else
58 syn region rhelpRcode matchgroup=Delimiter start="\\code{" skip='\\\@<!{.\{-}\\\@<!}' transparent end="}" contains=@R,rhelpDots,rhelpString,rhelpSpecialChar,rhelpLink keepend
59endif
Bram Moolenaar662db672011-03-22 14:05:35 +010060syn region rhelpS4method matchgroup=Delimiter start="\\S4method{.*}(" matchgroup=Delimiter transparent end=")" contains=@R,rhelpDots
61syn region rhelpSexpr matchgroup=Delimiter start="\\Sexpr{" matchgroup=Delimiter transparent end="}" contains=@R
62
63" PreProc {{{1
64syn match rhelpPreProc "^#ifdef.*"
65syn match rhelpPreProc "^#endif.*"
66
Bram Moolenaar362e1a32006-03-06 23:29:24 +000067" Special Delimiters {{{1
68syn match rhelpDelimiter "\\cr"
69syn match rhelpDelimiter "\\tab "
70
71" Keywords {{{1
Bram Moolenaar662db672011-03-22 14:05:35 +010072syn match rhelpKeyword "\\R"
Bram Moolenaar362e1a32006-03-06 23:29:24 +000073syn match rhelpKeyword "\\ldots"
Bram Moolenaarf9393ef2006-04-24 19:47:27 +000074syn match rhelpKeyword "--"
75syn match rhelpKeyword "---"
76syn match rhelpKeyword "<"
77syn match rhelpKeyword ">"
Bram Moolenaar00a927d2010-05-14 23:24:24 +020078syn match rhelpKeyword "\\ge"
79syn match rhelpKeyword "\\le"
80syn match rhelpKeyword "\\alpha"
81syn match rhelpKeyword "\\beta"
82syn match rhelpKeyword "\\gamma"
83syn match rhelpKeyword "\\delta"
84syn match rhelpKeyword "\\epsilon"
85syn match rhelpKeyword "\\zeta"
86syn match rhelpKeyword "\\eta"
87syn match rhelpKeyword "\\theta"
88syn match rhelpKeyword "\\iota"
89syn match rhelpKeyword "\\kappa"
90syn match rhelpKeyword "\\lambda"
91syn match rhelpKeyword "\\mu"
92syn match rhelpKeyword "\\nu"
93syn match rhelpKeyword "\\xi"
94syn match rhelpKeyword "\\omicron"
95syn match rhelpKeyword "\\pi"
96syn match rhelpKeyword "\\rho"
97syn match rhelpKeyword "\\sigma"
98syn match rhelpKeyword "\\tau"
99syn match rhelpKeyword "\\upsilon"
100syn match rhelpKeyword "\\phi"
101syn match rhelpKeyword "\\chi"
102syn match rhelpKeyword "\\psi"
103syn match rhelpKeyword "\\omega"
104syn match rhelpKeyword "\\Alpha"
105syn match rhelpKeyword "\\Beta"
106syn match rhelpKeyword "\\Gamma"
107syn match rhelpKeyword "\\Delta"
108syn match rhelpKeyword "\\Epsilon"
109syn match rhelpKeyword "\\Zeta"
110syn match rhelpKeyword "\\Eta"
111syn match rhelpKeyword "\\Theta"
112syn match rhelpKeyword "\\Iota"
113syn match rhelpKeyword "\\Kappa"
114syn match rhelpKeyword "\\Lambda"
115syn match rhelpKeyword "\\Mu"
116syn match rhelpKeyword "\\Nu"
117syn match rhelpKeyword "\\Xi"
118syn match rhelpKeyword "\\Omicron"
119syn match rhelpKeyword "\\Pi"
120syn match rhelpKeyword "\\Rho"
121syn match rhelpKeyword "\\Sigma"
122syn match rhelpKeyword "\\Tau"
123syn match rhelpKeyword "\\Upsilon"
124syn match rhelpKeyword "\\Phi"
125syn match rhelpKeyword "\\Chi"
126syn match rhelpKeyword "\\Psi"
127syn match rhelpKeyword "\\Omega"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000128
129" Links {{{1
Bram Moolenaar662db672011-03-22 14:05:35 +0100130syn region rhelpLink matchgroup=rhelpSection start="\\link{" end="}" contained keepend extend
131syn region rhelpLink matchgroup=rhelpSection start="\\link\[.\{-}\]{" end="}" contained keepend extend
132syn region rhelpLink matchgroup=rhelpSection start="\\linkS4class{" end="}" contained keepend extend
133
134" Verbatim like {{{1
Bram Moolenaardb6ea062014-07-10 22:01:47 +0200135if v:version > 703
136 syn region rhelpVerbatim matchgroup=rhelpType start="\\samp{" skip='\\\@1<!{.\{-}\\\@1<!}' end="}" contains=rhelpSpecialChar,rhelpComment
137 syn region rhelpVerbatim matchgroup=rhelpType start="\\verb{" skip='\\\@1<!{.\{-}\\\@1<!}' end="}" contains=rhelpSpecialChar,rhelpComment
138else
139 syn region rhelpVerbatim matchgroup=rhelpType start="\\samp{" skip='\\\@<!{.\{-}\\\@<!}' end="}" contains=rhelpSpecialChar,rhelpComment
140 syn region rhelpVerbatim matchgroup=rhelpType start="\\verb{" skip='\\\@<!{.\{-}\\\@<!}' end="}" contains=rhelpSpecialChar,rhelpComment
141endif
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000142
143" Type Styles {{{1
144syn match rhelpType "\\emph\>"
145syn match rhelpType "\\strong\>"
146syn match rhelpType "\\bold\>"
147syn match rhelpType "\\sQuote\>"
148syn match rhelpType "\\dQuote\>"
149syn match rhelpType "\\preformatted\>"
150syn match rhelpType "\\kbd\>"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000151syn match rhelpType "\\eqn\>"
152syn match rhelpType "\\deqn\>"
153syn match rhelpType "\\file\>"
154syn match rhelpType "\\email\>"
155syn match rhelpType "\\url\>"
Bram Moolenaar81af9252010-12-10 20:35:50 +0100156syn match rhelpType "\\href\>"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000157syn match rhelpType "\\var\>"
158syn match rhelpType "\\env\>"
159syn match rhelpType "\\option\>"
160syn match rhelpType "\\command\>"
Bram Moolenaar81af9252010-12-10 20:35:50 +0100161syn match rhelpType "\\newcommand\>"
162syn match rhelpType "\\renewcommand\>"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000163syn match rhelpType "\\dfn\>"
164syn match rhelpType "\\cite\>"
165syn match rhelpType "\\acronym\>"
166
167" rhelp sections {{{1
168syn match rhelpSection "\\encoding\>"
169syn match rhelpSection "\\title\>"
Bram Moolenaar81af9252010-12-10 20:35:50 +0100170syn match rhelpSection "\\item\>"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000171syn match rhelpSection "\\description\>"
172syn match rhelpSection "\\concept\>"
173syn match rhelpSection "\\arguments\>"
174syn match rhelpSection "\\details\>"
175syn match rhelpSection "\\value\>"
176syn match rhelpSection "\\references\>"
177syn match rhelpSection "\\note\>"
178syn match rhelpSection "\\author\>"
179syn match rhelpSection "\\seealso\>"
180syn match rhelpSection "\\keyword\>"
181syn match rhelpSection "\\docType\>"
182syn match rhelpSection "\\format\>"
183syn match rhelpSection "\\source\>"
Bram Moolenaar81af9252010-12-10 20:35:50 +0100184syn match rhelpSection "\\itemize\>"
185syn match rhelpSection "\\describe\>"
186syn match rhelpSection "\\enumerate\>"
187syn match rhelpSection "\\item "
188syn match rhelpSection "\\item$"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000189syn match rhelpSection "\\tabular{[lcr]*}"
190syn match rhelpSection "\\dontrun\>"
191syn match rhelpSection "\\dontshow\>"
192syn match rhelpSection "\\testonly\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000193syn match rhelpSection "\\donttest\>"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000194
195" Freely named Sections {{{1
Bram Moolenaar81af9252010-12-10 20:35:50 +0100196syn region rhelpFreesec matchgroup=Delimiter start="\\section{" matchgroup=Delimiter transparent end="}"
197syn region rhelpFreesubsec matchgroup=Delimiter start="\\subsection{" matchgroup=Delimiter transparent end="}"
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000198
Bram Moolenaar662db672011-03-22 14:05:35 +0100199syn match rhelpDelimiter "{\|\[\|(\|)\|\]\|}"
200
Bram Moolenaarf9393ef2006-04-24 19:47:27 +0000201" R help file comments {{{1
Bram Moolenaar81af9252010-12-10 20:35:50 +0100202syn match rhelpComment /%.*$/
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000203
204" Error {{{1
Bram Moolenaar15146672011-10-20 22:22:38 +0200205syn 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
206syn 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
207syn 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
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000208syn match rhelpError /[)\]}]/
209syn match rhelpBraceError /[)}]/ contained
210syn match rhelpCurlyError /[)\]]/ contained
211syn match rhelpParenError /[\]}]/ contained
212
Bram Moolenaardb6ea062014-07-10 22:01:47 +0200213syntax sync match rhelpSyncRcode grouphere rhelpRcode "\\examples{"
214
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000215" Define the default highlighting {{{1
216" For version 5.7 and earlier: only when not done already
217" For version 5.8 and later: only when an item doesn't have highlighting yet
218if version >= 508 || !exists("did_rhelp_syntax_inits")
219 if version < 508
220 let did_rhelp_syntax_inits = 1
221 command -nargs=+ HiLink hi link <args>
222 else
223 command -nargs=+ HiLink hi def link <args>
224 endif
Bram Moolenaar662db672011-03-22 14:05:35 +0100225 HiLink rhelpVerbatim String
226 HiLink rhelpDelimiter Delimiter
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000227 HiLink rhelpIdentifier Identifier
228 HiLink rhelpString String
Bram Moolenaar662db672011-03-22 14:05:35 +0100229 HiLink rhelpCodeSpecial Special
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000230 HiLink rhelpKeyword Keyword
Bram Moolenaarf9393ef2006-04-24 19:47:27 +0000231 HiLink rhelpDots Keyword
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000232 HiLink rhelpLink Underlined
Bram Moolenaar662db672011-03-22 14:05:35 +0100233 HiLink rhelpType Type
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000234 HiLink rhelpSection PreCondit
235 HiLink rhelpError Error
236 HiLink rhelpBraceError Error
237 HiLink rhelpCurlyError Error
238 HiLink rhelpParenError Error
Bram Moolenaar662db672011-03-22 14:05:35 +0100239 HiLink rhelpPreProc PreProc
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000240 HiLink rhelpDelimiter Delimiter
241 HiLink rhelpComment Comment
242 HiLink rhelpRComment Comment
243 HiLink rhelpSpecialChar SpecialChar
244 delcommand HiLink
245endif
246
247let b:current_syntax = "rhelp"
Bram Moolenaardb6ea062014-07-10 22:01:47 +0200248
249" vim: foldmethod=marker sw=2