rhelp.vim 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. " Vim syntax file
  2. " Language: R Help File
  3. " Maintainer: Jakson Aquino <jalvesaq@gmail.com>
  4. " Former Maintainer: Johannes Ranke <jranke@uni-bremen.de>
  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. " Version Clears: {{{1
  14. if exists("b:current_syntax")
  15. finish
  16. endif
  17. scriptencoding utf-8
  18. syn case match
  19. " R help identifiers {{{1
  20. syn region rhelpIdentifier matchgroup=rhelpSection start="\\name{" end="}"
  21. syn region rhelpIdentifier matchgroup=rhelpSection start="\\alias{" end="}"
  22. syn region rhelpIdentifier matchgroup=rhelpSection start="\\pkg{" end="}" contains=rhelpLink
  23. syn region rhelpIdentifier matchgroup=rhelpSection start="\\CRANpkg{" end="}" contains=rhelpLink
  24. syn region rhelpIdentifier matchgroup=rhelpSection start="\\method{" end="}" contained
  25. syn region rhelpIdentifier matchgroup=rhelpSection start="\\Rdversion{" end="}"
  26. " Highlighting of R code using an existing r.vim syntax file if available {{{1
  27. syn include @R syntax/r.vim
  28. " Strings {{{1
  29. syn region rhelpString start=/"/ skip=/\\"/ end=/"/ contains=rhelpSpecialChar,rhelpCodeSpecial,rhelpLink contained
  30. " Special characters in R strings
  31. syn match rhelpCodeSpecial display contained "\\\\\(n\|r\|t\|b\|a\|f\|v\|'\|\"\)\|\\\\"
  32. " Special characters ( \$ \& \% \# \{ \} \_)
  33. syn match rhelpSpecialChar "\\[$&%#{}_]"
  34. " R code {{{1
  35. syn match rhelpDots "\\dots" containedin=@R
  36. syn region rhelpRcode matchgroup=Delimiter start="\\examples{" matchgroup=Delimiter transparent end="}" contains=@R,rhelpLink,rhelpIdentifier,rhelpString,rhelpSpecialChar,rhelpSection
  37. syn region rhelpRcode matchgroup=Delimiter start="\\usage{" matchgroup=Delimiter transparent end="}" contains=@R,rhelpIdentifier,rhelpS4method
  38. syn region rhelpRcode matchgroup=Delimiter start="\\synopsis{" matchgroup=Delimiter transparent end="}" contains=@R
  39. syn region rhelpRcode matchgroup=Delimiter start="\\special{" matchgroup=Delimiter transparent end="}" contains=@R
  40. if v:version > 703
  41. syn region rhelpRcode matchgroup=Delimiter start="\\code{" skip='\\\@1<!{.\{-}\\\@1<!}' transparent end="}" contains=@R,rhelpDots,rhelpString,rhelpSpecialChar,rhelpLink keepend
  42. else
  43. syn region rhelpRcode matchgroup=Delimiter start="\\code{" skip='\\\@<!{.\{-}\\\@<!}' transparent end="}" contains=@R,rhelpDots,rhelpString,rhelpSpecialChar,rhelpLink keepend
  44. endif
  45. syn region rhelpS4method matchgroup=Delimiter start="\\S4method{.*}(" matchgroup=Delimiter transparent end=")" contains=@R,rhelpDots
  46. syn region rhelpSexpr matchgroup=Delimiter start="\\Sexpr{" matchgroup=Delimiter transparent end="}" contains=@R
  47. " PreProc {{{1
  48. syn match rhelpPreProc "^#ifdef.*"
  49. syn match rhelpPreProc "^#endif.*"
  50. " Special Delimiters {{{1
  51. syn match rhelpDelimiter "\\cr"
  52. syn match rhelpDelimiter "\\tab "
  53. " Keywords {{{1
  54. syn match rhelpKeyword "\\R\>"
  55. syn match rhelpKeyword "\\ldots\>"
  56. syn match rhelpKeyword "\\sspace\>"
  57. syn match rhelpKeyword "--"
  58. syn match rhelpKeyword "---"
  59. " Condition Keywords {{{2
  60. syn match rhelpKeyword "\\if\>"
  61. syn match rhelpKeyword "\\ifelse\>"
  62. syn match rhelpKeyword "\\out\>"
  63. " Examples of usage:
  64. " \ifelse{latex}{\eqn{p = 5 + 6 - 7 \times 8}}{\eqn{p = 5 + 6 - 7 * 8}}
  65. " \ifelse{latex}{\out{$\alpha$}}{\ifelse{html}{\out{&alpha;}}{alpha}}
  66. " Keywords and operators valid only if in math mode {{{2
  67. syn match rhelpMathOp "<" contained
  68. syn match rhelpMathOp ">" contained
  69. syn match rhelpMathOp "+" contained
  70. syn match rhelpMathOp "-" contained
  71. syn match rhelpMathOp "=" contained
  72. " Conceal function based on syntax/tex.vim {{{2
  73. if exists("g:tex_conceal")
  74. let s:tex_conceal = g:tex_conceal
  75. else
  76. let s:tex_conceal = 'gm'
  77. endif
  78. function s:HideSymbol(pat, cchar, hide)
  79. if a:hide
  80. exe "syn match rhelpMathSymb '" . a:pat . "' contained conceal cchar=" . a:cchar
  81. else
  82. exe "syn match rhelpMathSymb '" . a:pat . "' contained"
  83. endif
  84. endfunction
  85. " Math symbols {{{2
  86. if s:tex_conceal =~ 'm'
  87. let s:hd = 1
  88. else
  89. let s:hd = 0
  90. endif
  91. call s:HideSymbol('\\infty\>', '∞', s:hd)
  92. call s:HideSymbol('\\ge\>', '≥', s:hd)
  93. call s:HideSymbol('\\le\>', '≤', s:hd)
  94. call s:HideSymbol('\\prod\>', '∏', s:hd)
  95. call s:HideSymbol('\\sum\>', '∑', s:hd)
  96. syn match rhelpMathSymb "\\sqrt\>" contained
  97. " Greek letters {{{2
  98. if s:tex_conceal =~ 'g'
  99. let s:hd = 1
  100. else
  101. let s:hd = 0
  102. endif
  103. call s:HideSymbol('\\alpha\>', 'α', s:hd)
  104. call s:HideSymbol('\\beta\>', 'β', s:hd)
  105. call s:HideSymbol('\\gamma\>', 'γ', s:hd)
  106. call s:HideSymbol('\\delta\>', 'δ', s:hd)
  107. call s:HideSymbol('\\epsilon\>', 'ϵ', s:hd)
  108. call s:HideSymbol('\\zeta\>', 'ζ', s:hd)
  109. call s:HideSymbol('\\eta\>', 'η', s:hd)
  110. call s:HideSymbol('\\theta\>', 'θ', s:hd)
  111. call s:HideSymbol('\\iota\>', 'ι', s:hd)
  112. call s:HideSymbol('\\kappa\>', 'κ', s:hd)
  113. call s:HideSymbol('\\lambda\>', 'λ', s:hd)
  114. call s:HideSymbol('\\mu\>', 'μ', s:hd)
  115. call s:HideSymbol('\\nu\>', 'ν', s:hd)
  116. call s:HideSymbol('\\xi\>', 'ξ', s:hd)
  117. call s:HideSymbol('\\pi\>', 'π', s:hd)
  118. call s:HideSymbol('\\rho\>', 'ρ', s:hd)
  119. call s:HideSymbol('\\sigma\>', 'σ', s:hd)
  120. call s:HideSymbol('\\tau\>', 'τ', s:hd)
  121. call s:HideSymbol('\\upsilon\>', 'υ', s:hd)
  122. call s:HideSymbol('\\phi\>', 'ϕ', s:hd)
  123. call s:HideSymbol('\\chi\>', 'χ', s:hd)
  124. call s:HideSymbol('\\psi\>', 'ψ', s:hd)
  125. call s:HideSymbol('\\omega\>', 'ω', s:hd)
  126. call s:HideSymbol('\\Gamma\>', 'Γ', s:hd)
  127. call s:HideSymbol('\\Delta\>', 'Δ', s:hd)
  128. call s:HideSymbol('\\Theta\>', 'Θ', s:hd)
  129. call s:HideSymbol('\\Lambda\>', 'Λ', s:hd)
  130. call s:HideSymbol('\\Xi\>', 'Ξ', s:hd)
  131. call s:HideSymbol('\\Pi\>', 'Π', s:hd)
  132. call s:HideSymbol('\\Sigma\>', 'Σ', s:hd)
  133. call s:HideSymbol('\\Upsilon\>', 'Υ', s:hd)
  134. call s:HideSymbol('\\Phi\>', 'Φ', s:hd)
  135. call s:HideSymbol('\\Psi\>', 'Ψ', s:hd)
  136. call s:HideSymbol('\\Omega\>', 'Ω', s:hd)
  137. delfunction s:HideSymbol
  138. " Note: The letters 'omicron', 'Alpha', 'Beta', 'Epsilon', 'Zeta', 'Eta',
  139. " 'Iota', 'Kappa', 'Mu', 'Nu', 'Omicron', 'Rho', 'Tau' and 'Chi' are listed
  140. " at src/library/tools/R/Rd2txt.R because they are valid in HTML, although
  141. " they do not make valid LaTeX code (e.g. &Alpha; versus \Alpha).
  142. " Links {{{1
  143. syn region rhelpLink matchgroup=rhelpType start="\\link{" end="}" contained keepend extend
  144. syn region rhelpLink matchgroup=rhelpType start="\\link\[.\{-}\]{" end="}" contained keepend extend
  145. syn region rhelpLink matchgroup=rhelpType start="\\linkS4class{" end="}" contained keepend extend
  146. syn region rhelpLink matchgroup=rhelpType start="\\url{" end="}" contained keepend extend
  147. syn region rhelpLink matchgroup=rhelpType start="\\href{" end="}" contained keepend extend
  148. syn region rhelpLink matchgroup=rhelpType start="\\figure{" end="}" contained keepend extend
  149. " Verbatim like {{{1
  150. syn region rhelpVerbatim matchgroup=rhelpType start="\\samp{" skip='\\\@1<!{.\{-}\\\@1<!}' end="}" contains=rhelpSpecialChar,rhelpComment
  151. syn region rhelpVerbatim matchgroup=rhelpType start="\\verb{" skip='\\\@1<!{.\{-}\\\@1<!}' end="}" contains=rhelpSpecialChar,rhelpComment
  152. " Equation {{{1
  153. syn region rhelpEquation matchgroup=rhelpType start="\\eqn{" skip='\\\@1<!{.\{-}\\\@1<!}' end="}" contains=rhelpMathSymb,rhelpMathOp,rhelpRegion contained keepend extend
  154. syn region rhelpEquation matchgroup=rhelpType start="\\deqn{" skip='\\\@1<!{.\{-}\\\@1<!}' end="}" contains=rhelpMathSymb,rhelpMathOp,rhelpRegion contained keepend extend
  155. " Type Styles {{{1
  156. syn match rhelpType "\\emph\>"
  157. syn match rhelpType "\\strong\>"
  158. syn match rhelpType "\\bold\>"
  159. syn match rhelpType "\\sQuote\>"
  160. syn match rhelpType "\\dQuote\>"
  161. syn match rhelpType "\\preformatted\>"
  162. syn match rhelpType "\\kbd\>"
  163. syn match rhelpType "\\file\>"
  164. syn match rhelpType "\\email\>"
  165. syn match rhelpType "\\enc\>"
  166. syn match rhelpType "\\var\>"
  167. syn match rhelpType "\\env\>"
  168. syn match rhelpType "\\option\>"
  169. syn match rhelpType "\\command\>"
  170. syn match rhelpType "\\newcommand\>"
  171. syn match rhelpType "\\renewcommand\>"
  172. syn match rhelpType "\\dfn\>"
  173. syn match rhelpType "\\cite\>"
  174. syn match rhelpType "\\acronym\>"
  175. syn match rhelpType "\\doi\>"
  176. " rhelp sections {{{1
  177. syn match rhelpSection "\\encoding\>"
  178. syn match rhelpSection "\\title\>"
  179. syn match rhelpSection "\\item\>"
  180. syn match rhelpSection "\\description\>"
  181. syn match rhelpSection "\\concept\>"
  182. syn match rhelpSection "\\arguments\>"
  183. syn match rhelpSection "\\details\>"
  184. syn match rhelpSection "\\value\>"
  185. syn match rhelpSection "\\references\>"
  186. syn match rhelpSection "\\note\>"
  187. syn match rhelpSection "\\author\>"
  188. syn match rhelpSection "\\seealso\>"
  189. syn match rhelpSection "\\keyword\>"
  190. syn match rhelpSection "\\docType\>"
  191. syn match rhelpSection "\\format\>"
  192. syn match rhelpSection "\\source\>"
  193. syn match rhelpSection "\\itemize\>"
  194. syn match rhelpSection "\\describe\>"
  195. syn match rhelpSection "\\enumerate\>"
  196. syn match rhelpSection "\\item "
  197. syn match rhelpSection "\\item$"
  198. syn match rhelpSection "\\tabular{[lcr]*}"
  199. syn match rhelpSection "\\dontrun\>"
  200. syn match rhelpSection "\\dontshow\>"
  201. syn match rhelpSection "\\testonly\>"
  202. syn match rhelpSection "\\donttest\>"
  203. " Freely named Sections {{{1
  204. syn region rhelpFreesec matchgroup=Delimiter start="\\section{" matchgroup=Delimiter transparent end="}"
  205. syn region rhelpFreesubsec matchgroup=Delimiter start="\\subsection{" matchgroup=Delimiter transparent end="}"
  206. syn match rhelpDelimiter "{\|\[\|(\|)\|\]\|}"
  207. " R help file comments {{{1
  208. syn match rhelpComment /%.*$/
  209. " Error {{{1
  210. syn 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
  211. syn 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
  212. syn 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
  213. syn match rhelpError /[)\]}]/
  214. syn match rhelpBraceError /[)}]/ contained
  215. syn match rhelpCurlyError /[)\]]/ contained
  216. syn match rhelpParenError /[\]}]/ contained
  217. syntax sync match rhelpSyncRcode grouphere rhelpRcode "\\examples{"
  218. " Define the default highlighting {{{1
  219. hi def link rhelpVerbatim String
  220. hi def link rhelpDelimiter Delimiter
  221. hi def link rhelpIdentifier Identifier
  222. hi def link rhelpString String
  223. hi def link rhelpCodeSpecial Special
  224. hi def link rhelpKeyword Keyword
  225. hi def link rhelpDots Keyword
  226. hi def link rhelpLink Underlined
  227. hi def link rhelpType Type
  228. hi def link rhelpSection PreCondit
  229. hi def link rhelpError Error
  230. hi def link rhelpBraceError Error
  231. hi def link rhelpCurlyError Error
  232. hi def link rhelpParenError Error
  233. hi def link rhelpPreProc PreProc
  234. hi def link rhelpDelimiter Delimiter
  235. hi def link rhelpComment Comment
  236. hi def link rhelpRComment Comment
  237. hi def link rhelpSpecialChar SpecialChar
  238. hi def link rhelpMathSymb Special
  239. hi def link rhelpMathOp Operator
  240. let b:current_syntax = "rhelp"
  241. " vim: foldmethod=marker sw=2