Bram Moolenaar | e1438bb | 2006-03-01 22:01:55 +0000 | [diff] [blame] | 1 | " 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 |
| 19 | if version < 600 |
| 20 | syntax clear |
| 21 | elseif exists("b:current_syntax") |
| 22 | finish |
| 23 | endif |
| 24 | |
| 25 | syn case match |
| 26 | |
| 27 | " Rd identifiers {{{ |
| 28 | syn region rdIdentifier matchgroup=rdSection start="\\name{" end="}" |
| 29 | syn region rdIdentifier matchgroup=rdSection start="\\alias{" end="}" |
| 30 | syn region rdIdentifier matchgroup=rdSection start="\\pkg{" end="}" |
| 31 | syn region rdIdentifier matchgroup=rdSection start="\\item{" end="}" contained |
| 32 | syn region rdIdentifier matchgroup=rdSection start="\\method{" end=/}/ contained |
| 33 | |
| 34 | " Highlighting of R code using an existing r.vim syntax file if available {{{1 |
| 35 | let s:syntaxdir = expand("<sfile>:p:h") "look in the directory of this file |
| 36 | let s:rsyntax = s:syntaxdir . "/r.vim" |
| 37 | if filereadable(s:rsyntax) |
| 38 | syn include @R <sfile>:p:h/r.vim |
| 39 | elseif filereadable('/usr/share/vim/vim64/syntax/r.vim') "and debian location |
| 40 | syn include @R /usr/share/vim/vimcurrent/syntax/r.vim |
| 41 | else |
| 42 | syn match rdRComment /\#.*/ "if no r.vim is found, do comments |
| 43 | syn cluster R contains=rdRComment |
| 44 | endif |
| 45 | syn region rdRcode matchgroup=Delimiter start="\\examples{" matchgroup=Delimiter transparent end=/}/ contains=@R,rdSection |
| 46 | syn region rdRcode matchgroup=Delimiter start="\\usage{" matchgroup=Delimiter transparent end=/}/ contains=@R,rdIdentifier |
| 47 | syn region rdRcode matchgroup=Delimiter start="\\synopsis{" matchgroup=Delimiter transparent end=/}/ contains=@R |
| 48 | syn region rdRcode matchgroup=Delimiter start="\\special{" matchgroup=Delimiter transparent end=/}/ contains=@R contained |
| 49 | syn region rdRcode matchgroup=Delimiter start="\\code{" matchgroup=Delimiter transparent end=/}/ contains=@R contained |
| 50 | |
| 51 | " Strings {{{1 |
| 52 | syn region rdString start=/"/ end=/"/ |
| 53 | |
| 54 | " Special TeX characters ( \$ \& \% \# \{ \} \_) {{{1 |
| 55 | syn match rdSpecialChar "\\[$&%#{}_]" |
| 56 | |
| 57 | " Special Delimiters {{{1 |
| 58 | syn match rdDelimiter "\\cr" |
| 59 | syn match rdDelimiter "\\tab " |
| 60 | |
| 61 | " Keywords {{{1 |
| 62 | syn match rdKeyword "\\R" |
| 63 | syn match rdKeyword "\\dots" |
| 64 | syn match rdKeyword "\\ldots" |
| 65 | |
| 66 | " Links {{{1 |
| 67 | syn region rdLink matchgroup=rdSection start="\\link{" end="}" contained keepend |
| 68 | syn region rdLink matchgroup=rdSection start="\\link\[.*\]{" end="}" contained keepend |
| 69 | |
| 70 | " Type Styles {{{1 |
| 71 | syn match rdType "\\emph\>" |
| 72 | syn match rdType "\\strong\>" |
| 73 | syn match rdType "\\bold\>" |
| 74 | syn match rdType "\\sQuote\>" |
| 75 | syn match rdType "\\dQuote\>" |
| 76 | syn match rdType "\\code\>" |
| 77 | syn match rdType "\\preformatted\>" |
| 78 | syn match rdType "\\kbd\>" |
| 79 | syn match rdType "\\samp\>" |
| 80 | syn match rdType "\\eqn\>" |
| 81 | syn match rdType "\\deqn\>" |
| 82 | syn match rdType "\\file\>" |
| 83 | syn match rdType "\\email\>" |
| 84 | syn match rdType "\\url\>" |
| 85 | syn match rdType "\\var\>" |
| 86 | syn match rdType "\\env\>" |
| 87 | syn match rdType "\\option\>" |
| 88 | syn match rdType "\\command\>" |
| 89 | syn match rdType "\\dfn\>" |
| 90 | syn match rdType "\\cite\>" |
| 91 | syn match rdType "\\acronym\>" |
| 92 | |
| 93 | " Rd sections {{{1 |
| 94 | syn match rdSection "\\encoding\>" |
| 95 | syn match rdSection "\\title\>" |
| 96 | syn match rdSection "\\description\>" |
| 97 | syn match rdSection "\\concept\>" |
| 98 | syn match rdSection "\\arguments\>" |
| 99 | syn match rdSection "\\details\>" |
| 100 | syn match rdSection "\\value\>" |
| 101 | syn match rdSection "\\references\>" |
| 102 | syn match rdSection "\\note\>" |
| 103 | syn match rdSection "\\author\>" |
| 104 | syn match rdSection "\\seealso\>" |
| 105 | syn match rdSection "\\keyword\>" |
| 106 | syn match rdSection "\\docType\>" |
| 107 | syn match rdSection "\\format\>" |
| 108 | syn match rdSection "\\source\>" |
| 109 | syn match rdSection "\\itemize\>" |
| 110 | syn match rdSection "\\describe\>" |
| 111 | syn match rdSection "\\enumerate\>" |
| 112 | syn match rdSection "\\item " |
| 113 | syn match rdSection "\\item$" |
| 114 | syn match rdSection "\\tabular{[lcr]*}" |
| 115 | syn match rdSection "\\dontrun\>" |
| 116 | syn match rdSection "\\dontshow\>" |
| 117 | syn match rdSection "\\testonly\>" |
| 118 | |
| 119 | " Freely named Sections {{{1 |
| 120 | syn region rdFreesec matchgroup=Delimiter start="\\section{" matchgroup=Delimiter transparent end=/}/ |
| 121 | |
| 122 | " Rd comments {{{1 |
| 123 | syn match rdComment /%.*$/ contained |
| 124 | |
| 125 | " Error {{{1 |
| 126 | syn region rdRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rdError,rdBraceError,rdCurlyError |
| 127 | syn region rdRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rdError,rdBraceError,rdParenError |
| 128 | syn region rdRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rdError,rdCurlyError,rdParenError |
| 129 | syn match rdError /[)\]}]/ |
| 130 | syn match rdBraceError /[)}]/ contained |
| 131 | syn match rdCurlyError /[)\]]/ contained |
| 132 | syn 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 |
| 137 | if 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 |
| 159 | endif |
| 160 | |
| 161 | let b:current_syntax = "rd" |
| 162 | " vim: foldmethod=marker: |