blob: b08e4b2bb7310d841bb3a02ae4decf606d9c3b84 [file] [log] [blame]
Bram Moolenaare1438bb2006-03-01 22:01:55 +00001" Vim syntax file
2" Language: R Help File
3" Maintainer: Johannes Ranke <jranke@uni-bremen.de>
4" Last Change: 2006 Mรคr 01
5" Version: 0.5
6" Remarks: - Now includes R syntax highlighting in the appropriate
7" sections if an r.vim file is in the same directory or in the
8" default debian location.
9" - I didn't yet include any special markup for S4 methods.
10" - The two versions of \item{}{} markup are not
11" distinguished (in the \arguments{} environment, the items to
12" be described are R identifiers, but not in the \describe{}
13" environment).
14" - There is no Latex markup in equations
15
16" Version Clears: {{{1
17" For version 5.x: Clear all syntax items
18" For version 6.x: Quit when a syntax file was already loaded
19if version < 600
20 syntax clear
21elseif exists("b:current_syntax")
22 finish
23endif
24
25syn case match
26
27" Rd identifiers {{{
28syn region rdIdentifier matchgroup=rdSection start="\\name{" end="}"
29syn region rdIdentifier matchgroup=rdSection start="\\alias{" end="}"
30syn region rdIdentifier matchgroup=rdSection start="\\pkg{" end="}"
31syn region rdIdentifier matchgroup=rdSection start="\\item{" end="}" contained
32syn region rdIdentifier matchgroup=rdSection start="\\method{" end=/}/ contained
33
34" Highlighting of R code using an existing r.vim syntax file if available {{{1
35let s:syntaxdir = expand("<sfile>:p:h") "look in the directory of this file
36let s:rsyntax = s:syntaxdir . "/r.vim"
37if filereadable(s:rsyntax)
38 syn include @R <sfile>:p:h/r.vim
39elseif filereadable('/usr/share/vim/vim64/syntax/r.vim') "and debian location
40 syn include @R /usr/share/vim/vimcurrent/syntax/r.vim
41else
42 syn match rdRComment /\#.*/ "if no r.vim is found, do comments
43 syn cluster R contains=rdRComment
44endif
45syn region rdRcode matchgroup=Delimiter start="\\examples{" matchgroup=Delimiter transparent end=/}/ contains=@R,rdSection
46syn region rdRcode matchgroup=Delimiter start="\\usage{" matchgroup=Delimiter transparent end=/}/ contains=@R,rdIdentifier
47syn region rdRcode matchgroup=Delimiter start="\\synopsis{" matchgroup=Delimiter transparent end=/}/ contains=@R
48syn region rdRcode matchgroup=Delimiter start="\\special{" matchgroup=Delimiter transparent end=/}/ contains=@R contained
49syn region rdRcode matchgroup=Delimiter start="\\code{" matchgroup=Delimiter transparent end=/}/ contains=@R contained
50
51" Strings {{{1
52syn region rdString start=/"/ end=/"/
53
54" Special TeX characters ( \$ \& \% \# \{ \} \_) {{{1
55syn match rdSpecialChar "\\[$&%#{}_]"
56
57" Special Delimiters {{{1
58syn match rdDelimiter "\\cr"
59syn match rdDelimiter "\\tab "
60
61" Keywords {{{1
62syn match rdKeyword "\\R"
63syn match rdKeyword "\\dots"
64syn match rdKeyword "\\ldots"
65
66" Links {{{1
67syn region rdLink matchgroup=rdSection start="\\link{" end="}" contained keepend
68syn region rdLink matchgroup=rdSection start="\\link\[.*\]{" end="}" contained keepend
69
70" Type Styles {{{1
71syn match rdType "\\emph\>"
72syn match rdType "\\strong\>"
73syn match rdType "\\bold\>"
74syn match rdType "\\sQuote\>"
75syn match rdType "\\dQuote\>"
76syn match rdType "\\code\>"
77syn match rdType "\\preformatted\>"
78syn match rdType "\\kbd\>"
79syn match rdType "\\samp\>"
80syn match rdType "\\eqn\>"
81syn match rdType "\\deqn\>"
82syn match rdType "\\file\>"
83syn match rdType "\\email\>"
84syn match rdType "\\url\>"
85syn match rdType "\\var\>"
86syn match rdType "\\env\>"
87syn match rdType "\\option\>"
88syn match rdType "\\command\>"
89syn match rdType "\\dfn\>"
90syn match rdType "\\cite\>"
91syn match rdType "\\acronym\>"
92
93" Rd sections {{{1
94syn match rdSection "\\encoding\>"
95syn match rdSection "\\title\>"
96syn match rdSection "\\description\>"
97syn match rdSection "\\concept\>"
98syn match rdSection "\\arguments\>"
99syn match rdSection "\\details\>"
100syn match rdSection "\\value\>"
101syn match rdSection "\\references\>"
102syn match rdSection "\\note\>"
103syn match rdSection "\\author\>"
104syn match rdSection "\\seealso\>"
105syn match rdSection "\\keyword\>"
106syn match rdSection "\\docType\>"
107syn match rdSection "\\format\>"
108syn match rdSection "\\source\>"
109syn match rdSection "\\itemize\>"
110syn match rdSection "\\describe\>"
111syn match rdSection "\\enumerate\>"
112syn match rdSection "\\item "
113syn match rdSection "\\item$"
114syn match rdSection "\\tabular{[lcr]*}"
115syn match rdSection "\\dontrun\>"
116syn match rdSection "\\dontshow\>"
117syn match rdSection "\\testonly\>"
118
119" Freely named Sections {{{1
120syn region rdFreesec matchgroup=Delimiter start="\\section{" matchgroup=Delimiter transparent end=/}/
121
122" Rd comments {{{1
123syn match rdComment /%.*$/ contained
124
125" Error {{{1
126syn region rdRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rdError,rdBraceError,rdCurlyError
127syn region rdRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rdError,rdBraceError,rdParenError
128syn region rdRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rdError,rdCurlyError,rdParenError
129syn match rdError /[)\]}]/
130syn match rdBraceError /[)}]/ contained
131syn match rdCurlyError /[)\]]/ contained
132syn match rdParenError /[\]}]/ contained
133
134" Define the default highlighting {{{1
135" For version 5.7 and earlier: only when not done already
136" For version 5.8 and later: only when an item doesn't have highlighting yet
137if version >= 508 || !exists("did_rd_syntax_inits")
138 if version < 508
139 let did_rd_syntax_inits = 1
140 command -nargs=+ HiLink hi link <args>
141 else
142 command -nargs=+ HiLink hi def link <args>
143 endif
144 HiLink rdIdentifier Identifier
145 HiLink rdString String
146 HiLink rdKeyword Keyword
147 HiLink rdLink Underlined
148 HiLink rdType Type
149 HiLink rdSection PreCondit
150 HiLink rdError Error
151 HiLink rdBraceError Error
152 HiLink rdCurlyError Error
153 HiLink rdParenError Error
154 HiLink rdDelimiter Delimiter
155 HiLink rdComment Comment
156 HiLink rdRComment Comment
157 HiLink rdSpecialChar SpecialChar
158 delcommand HiLink
159endif
160
161let b:current_syntax = "rd"
162" vim: foldmethod=marker: