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: Tue Jun 28, 2016 08:53AM 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 20 21syn case match 22 23" R help identifiers {{{1 24syn region rhelpIdentifier matchgroup=rhelpSection start="\\name{" end="}" 25syn region rhelpIdentifier matchgroup=rhelpSection start="\\alias{" end="}" 26syn region rhelpIdentifier matchgroup=rhelpSection start="\\pkg{" end="}" contains=rhelpLink 27syn region rhelpIdentifier matchgroup=rhelpSection start="\\CRANpkg{" end="}" contains=rhelpLink 28syn region rhelpIdentifier matchgroup=rhelpSection start="\\method{" end="}" contained 29syn region rhelpIdentifier matchgroup=rhelpSection start="\\Rdversion{" end="}" 30 31 32" Highlighting of R code using an existing r.vim syntax file if available {{{1 33syn include @R syntax/r.vim 34 35" Strings {{{1 36syn region rhelpString start=/"/ skip=/\\"/ end=/"/ contains=rhelpSpecialChar,rhelpCodeSpecial,rhelpLink contained 37 38" Special characters in R strings 39syn match rhelpCodeSpecial display contained "\\\\\(n\|r\|t\|b\|a\|f\|v\|'\|\"\)\|\\\\" 40 41" Special characters ( \$ \& \% \# \{ \} \_) 42syn match rhelpSpecialChar "\\[$&%#{}_]" 43 44 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 51 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 57syn 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 64" Special Delimiters {{{1 65syn match rhelpDelimiter "\\cr" 66syn match rhelpDelimiter "\\tab " 67 68" Keywords {{{1 69syn match rhelpKeyword "\\R\>" 70syn match rhelpKeyword "\\ldots\>" 71syn match rhelpKeyword "\\sspace\>" 72syn match rhelpKeyword "--" 73syn match rhelpKeyword "---" 74 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}} 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. Α versus \Alpha). 162 163" Links {{{1 164syn 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 170 171" Verbatim like {{{1 172syn 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 178 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\>" 187syn match rhelpType "\\file\>" 188syn match rhelpType "\\email\>" 189syn match rhelpType "\\enc\>" 190syn match rhelpType "\\var\>" 191syn match rhelpType "\\env\>" 192syn match rhelpType "\\option\>" 193syn match rhelpType "\\command\>" 194syn match rhelpType "\\newcommand\>" 195syn match rhelpType "\\renewcommand\>" 196syn match rhelpType "\\dfn\>" 197syn match rhelpType "\\cite\>" 198syn match rhelpType "\\acronym\>" 199syn match rhelpType "\\doi\>" 200 201" rhelp sections {{{1 202syn match rhelpSection "\\encoding\>" 203syn match rhelpSection "\\title\>" 204syn match rhelpSection "\\item\>" 205syn 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\>" 218syn match rhelpSection "\\itemize\>" 219syn match rhelpSection "\\describe\>" 220syn match rhelpSection "\\enumerate\>" 221syn match rhelpSection "\\item " 222syn match rhelpSection "\\item$" 223syn match rhelpSection "\\tabular{[lcr]*}" 224syn match rhelpSection "\\dontrun\>" 225syn match rhelpSection "\\dontshow\>" 226syn match rhelpSection "\\testonly\>" 227syn match rhelpSection "\\donttest\>" 228 229" Freely named Sections {{{1 230syn region rhelpFreesec matchgroup=Delimiter start="\\section{" matchgroup=Delimiter transparent end="}" 231syn region rhelpFreesubsec matchgroup=Delimiter start="\\subsection{" matchgroup=Delimiter transparent end="}" 232 233syn match rhelpDelimiter "{\|\[\|(\|)\|\]\|}" 234 235" R help file comments {{{1 236syn match rhelpComment /%.*$/ 237 238" Error {{{1 239syn 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 242syn match rhelpError /[)\]}]/ 243syn match rhelpBraceError /[)}]/ contained 244syn match rhelpCurlyError /[)\]]/ contained 245syn match rhelpParenError /[\]}]/ contained 246 247syntax sync match rhelpSyncRcode grouphere rhelpRcode "\\examples{" 248 249" Define the default highlighting {{{1 250hi 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 271 272let b:current_syntax = "rhelp" 273 274" vim: foldmethod=marker sw=2 275