Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +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 06 |
| 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 rhelpIdentifier matchgroup=rhelpSection start="\\name{" end="}" |
| 29 | syn region rhelpIdentifier matchgroup=rhelpSection start="\\alias{" end="}" |
| 30 | syn region rhelpIdentifier matchgroup=rhelpSection start="\\pkg{" end="}" |
| 31 | syn region rhelpIdentifier matchgroup=rhelpSection start="\\item{" end="}" contained |
| 32 | syn region rhelpIdentifier matchgroup=rhelpSection 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 rhelpRComment /\#.*/ "if no r.vim is found, do comments |
| 43 | syn cluster R contains=rhelpRComment |
| 44 | endif |
| 45 | syn region rhelpRcode matchgroup=Delimiter start="\\examples{" matchgroup=Delimiter transparent end=/}/ contains=@R,rhelpSection |
| 46 | syn region rhelpRcode matchgroup=Delimiter start="\\usage{" matchgroup=Delimiter transparent end=/}/ contains=@R,rhelpIdentifier |
| 47 | syn region rhelpRcode matchgroup=Delimiter start="\\synopsis{" matchgroup=Delimiter transparent end=/}/ contains=@R |
| 48 | syn region rhelpRcode matchgroup=Delimiter start="\\special{" matchgroup=Delimiter transparent end=/}/ contains=@R contained |
| 49 | syn region rhelpRcode matchgroup=Delimiter start="\\code{" matchgroup=Delimiter transparent end=/}/ contains=@R contained |
| 50 | |
| 51 | " Strings {{{1 |
| 52 | syn region rhelpString start=/"/ end=/"/ |
| 53 | |
| 54 | " Special TeX characters ( \$ \& \% \# \{ \} \_) {{{1 |
| 55 | syn match rhelpSpecialChar "\\[$&%#{}_]" |
| 56 | |
| 57 | " Special Delimiters {{{1 |
| 58 | syn match rhelpDelimiter "\\cr" |
| 59 | syn match rhelpDelimiter "\\tab " |
| 60 | |
| 61 | " Keywords {{{1 |
| 62 | syn match rhelpKeyword "\\R" |
| 63 | syn match rhelpKeyword "\\dots" |
| 64 | syn match rhelpKeyword "\\ldots" |
| 65 | |
| 66 | " Links {{{1 |
| 67 | syn region rhelpLink matchgroup=rhelpSection start="\\link{" end="}" contained keepend |
| 68 | syn region rhelpLink matchgroup=rhelpSection start="\\link\[.*\]{" end="}" contained keepend |
| 69 | |
| 70 | " Type Styles {{{1 |
| 71 | syn match rhelpType "\\emph\>" |
| 72 | syn match rhelpType "\\strong\>" |
| 73 | syn match rhelpType "\\bold\>" |
| 74 | syn match rhelpType "\\sQuote\>" |
| 75 | syn match rhelpType "\\dQuote\>" |
| 76 | syn match rhelpType "\\preformatted\>" |
| 77 | syn match rhelpType "\\kbd\>" |
| 78 | syn match rhelpType "\\samp\>" |
| 79 | syn match rhelpType "\\eqn\>" |
| 80 | syn match rhelpType "\\deqn\>" |
| 81 | syn match rhelpType "\\file\>" |
| 82 | syn match rhelpType "\\email\>" |
| 83 | syn match rhelpType "\\url\>" |
| 84 | syn match rhelpType "\\var\>" |
| 85 | syn match rhelpType "\\env\>" |
| 86 | syn match rhelpType "\\option\>" |
| 87 | syn match rhelpType "\\command\>" |
| 88 | syn match rhelpType "\\dfn\>" |
| 89 | syn match rhelpType "\\cite\>" |
| 90 | syn match rhelpType "\\acronym\>" |
| 91 | |
| 92 | " rhelp sections {{{1 |
| 93 | syn match rhelpSection "\\encoding\>" |
| 94 | syn match rhelpSection "\\title\>" |
| 95 | syn match rhelpSection "\\description\>" |
| 96 | syn match rhelpSection "\\concept\>" |
| 97 | syn match rhelpSection "\\arguments\>" |
| 98 | syn match rhelpSection "\\details\>" |
| 99 | syn match rhelpSection "\\value\>" |
| 100 | syn match rhelpSection "\\references\>" |
| 101 | syn match rhelpSection "\\note\>" |
| 102 | syn match rhelpSection "\\author\>" |
| 103 | syn match rhelpSection "\\seealso\>" |
| 104 | syn match rhelpSection "\\keyword\>" |
| 105 | syn match rhelpSection "\\docType\>" |
| 106 | syn match rhelpSection "\\format\>" |
| 107 | syn match rhelpSection "\\source\>" |
| 108 | syn match rhelpSection "\\itemize\>" |
| 109 | syn match rhelpSection "\\describe\>" |
| 110 | syn match rhelpSection "\\enumerate\>" |
| 111 | syn match rhelpSection "\\item " |
| 112 | syn match rhelpSection "\\item$" |
| 113 | syn match rhelpSection "\\tabular{[lcr]*}" |
| 114 | syn match rhelpSection "\\dontrun\>" |
| 115 | syn match rhelpSection "\\dontshow\>" |
| 116 | syn match rhelpSection "\\testonly\>" |
| 117 | |
| 118 | " Freely named Sections {{{1 |
| 119 | syn region rhelpFreesec matchgroup=Delimiter start="\\section{" matchgroup=Delimiter transparent end=/}/ |
| 120 | |
| 121 | " Rd comments {{{1 |
| 122 | syn match rhelpComment /%.*$/ contained |
| 123 | |
| 124 | " Error {{{1 |
| 125 | syn region rhelpRegion matchgroup=Delimiter start=/(/ matchgroup=Delimiter end=/)/ transparent contains=ALLBUT,rhelpError,rhelpBraceError,rhelpCurlyError |
| 126 | syn region rhelpRegion matchgroup=Delimiter start=/{/ matchgroup=Delimiter end=/}/ transparent contains=ALLBUT,rhelpError,rhelpBraceError,rhelpParenError |
| 127 | syn region rhelpRegion matchgroup=Delimiter start=/\[/ matchgroup=Delimiter end=/]/ transparent contains=ALLBUT,rhelpError,rhelpCurlyError,rhelpParenError |
| 128 | syn match rhelpError /[)\]}]/ |
| 129 | syn match rhelpBraceError /[)}]/ contained |
| 130 | syn match rhelpCurlyError /[)\]]/ contained |
| 131 | syn match rhelpParenError /[\]}]/ contained |
| 132 | |
| 133 | " Define the default highlighting {{{1 |
| 134 | " For version 5.7 and earlier: only when not done already |
| 135 | " For version 5.8 and later: only when an item doesn't have highlighting yet |
| 136 | if version >= 508 || !exists("did_rhelp_syntax_inits") |
| 137 | if version < 508 |
| 138 | let did_rhelp_syntax_inits = 1 |
| 139 | command -nargs=+ HiLink hi link <args> |
| 140 | else |
| 141 | command -nargs=+ HiLink hi def link <args> |
| 142 | endif |
| 143 | HiLink rhelpIdentifier Identifier |
| 144 | HiLink rhelpString String |
| 145 | HiLink rhelpKeyword Keyword |
| 146 | HiLink rhelpLink Underlined |
| 147 | HiLink rhelpType Type |
| 148 | HiLink rhelpSection PreCondit |
| 149 | HiLink rhelpError Error |
| 150 | HiLink rhelpBraceError Error |
| 151 | HiLink rhelpCurlyError Error |
| 152 | HiLink rhelpParenError Error |
| 153 | HiLink rhelpDelimiter Delimiter |
| 154 | HiLink rhelpComment Comment |
| 155 | HiLink rhelpRComment Comment |
| 156 | HiLink rhelpSpecialChar SpecialChar |
| 157 | delcommand HiLink |
| 158 | endif |
| 159 | |
| 160 | let b:current_syntax = "rhelp" |
| 161 | " vim: foldmethod=marker: |