Mercurial > vim
annotate runtime/syntax/rmd.vim @ 20825:deaf5e8bcb72
Added tag v8.2.0964 for changeset b8ca32dcfabba5aad12bf042f2e702001f145426
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 12 Jun 2020 22:15:04 +0200 |
parents | 1eaf34420bb3 |
children | 5bda4653aced |
rev | line source |
---|---|
6051 | 1 " markdown Text with R statements |
2 " Language: markdown with R code chunks | |
8497
da01d5da2cfa
commit https://github.com/vim/vim/commit/77cdfd10382e01cc51f4ba1a9177032351843151
Christian Brabandt <cb@256bit.org>
parents:
6051
diff
changeset
|
3 " Homepage: https://github.com/jalvesaq/R-Vim-runtime |
16610 | 4 " Last Change: Thu Apr 18, 2019 09:17PM |
11347 | 5 " |
6 " For highlighting pandoc extensions to markdown like citations and TeX and | |
7 " many other advanced features like folding of markdown sections, it is | |
8 " recommended to install the vim-pandoc filetype plugin as well as the | |
9 " vim-pandoc-syntax filetype plugin from https://github.com/vim-pandoc. | |
14637 | 10 |
6051 | 11 |
8497
da01d5da2cfa
commit https://github.com/vim/vim/commit/77cdfd10382e01cc51f4ba1a9177032351843151
Christian Brabandt <cb@256bit.org>
parents:
6051
diff
changeset
|
12 if exists("b:current_syntax") |
6051 | 13 finish |
14 endif | |
15 | |
14637 | 16 " Configuration if not using pandoc syntax: |
17 " Add syntax highlighting of YAML header | |
18 let g:rmd_syn_hl_yaml = get(g:, 'rmd_syn_hl_yaml', 1) | |
19 " Add syntax highlighting of citation keys | |
20 let g:rmd_syn_hl_citations = get(g:, 'rmd_syn_hl_citations', 1) | |
21 " Highlight the header of the chunk of R code | |
22 let g:rmd_syn_hl_chunk = get(g:, 'g:rmd_syn_hl_chunk', 0) | |
23 | |
24 " Pandoc-syntax has more features, but it is slower. | |
11347 | 25 " https://github.com/vim-pandoc/vim-pandoc-syntax |
14637 | 26 let g:pandoc#syntax#codeblocks#embeds#langs = get(g:, 'pandoc#syntax#codeblocks#embeds#langs', ['r']) |
6051 | 27 runtime syntax/pandoc.vim |
28 if exists("b:current_syntax") | |
14637 | 29 " Fix recognition of R code |
30 syn region pandocDelimitedCodeBlock_r start=/^```{r\>.*}$/ end=/^```$/ contained containedin=pandocDelimitedCodeBlock contains=@R | |
31 syn region rmdrInline matchgroup=rmdInlineDelim start="`r " end="`" contains=@R containedin=pandocLaTeXRegion,yamlFlowString keepend | |
32 hi def link rmdInlineDelim Delimiter | |
33 let b:current_syntax = "rmd" | |
34 finish | |
6051 | 35 endif |
36 | |
14637 | 37 let s:cpo_save = &cpo |
38 set cpo&vim | |
39 | |
40 " R chunks will not be highlighted by syntax/markdown because their headers | |
41 " follow a non standard pattern: "```{lang" instead of "^```lang". | |
42 " Make a copy of g:markdown_fenced_languages to highlight the chunks later: | |
43 if exists('g:markdown_fenced_languages') | |
44 if !exists('g:rmd_fenced_languages') | |
45 let g:rmd_fenced_languages = deepcopy(g:markdown_fenced_languages) | |
46 let g:markdown_fenced_languages = [] | |
47 endif | |
6051 | 48 else |
14637 | 49 let g:rmd_fenced_languages = ['r'] |
6051 | 50 endif |
11347 | 51 |
14637 | 52 runtime syntax/markdown.vim |
6051 | 53 |
14637 | 54 " Now highlight chunks: |
55 for s:type in g:rmd_fenced_languages | |
56 if s:type =~ '=' | |
16610 | 57 let s:ft = substitute(s:type, '.*=', '', '') |
58 let s:nm = substitute(s:type, '=.*', '', '') | |
14637 | 59 else |
16610 | 60 let s:ft = s:type |
14637 | 61 let s:nm = s:type |
62 endif | |
63 unlet! b:current_syntax | |
16610 | 64 exe 'syn include @Rmd'.s:nm.' syntax/'.s:ft.'.vim' |
14637 | 65 if g:rmd_syn_hl_chunk |
66 exe 'syn region rmd'.s:nm.'ChunkDelim matchgroup=rmdCodeDelim start="^\s*```\s*{\s*'.s:nm.'\>" matchgroup=rmdCodeDelim end="}$" keepend containedin=rmd'.s:nm.'Chunk contains=@Rmd'.s:nm | |
67 exe 'syn region rmd'.s:nm.'Chunk start="^\s*```\s*{\s*'.s:nm.'\>.*$" matchgroup=rmdCodeDelim end="^\s*```\ze\s*$" keepend contains=rmd'.s:nm.'ChunkDelim,@Rmd'.s:nm | |
68 else | |
69 exe 'syn region rmd'.s:nm.'Chunk matchgroup=rmdCodeDelim start="^\s*```\s*{\s*'.s:nm.'\>.*$" matchgroup=rmdCodeDelim end="^\s*```\ze\s*$" keepend contains=@Rmd'.s:nm | |
6051 | 70 endif |
14637 | 71 exe 'syn region rmd'.s:nm.'Inline matchgroup=rmdInlineDelim start="`'.s:nm.' " end="`" contains=@Rmd'.s:nm.' keepend' |
72 endfor | |
73 unlet! s:type | |
74 | |
75 hi def link rmdInlineDelim Delimiter | |
76 hi def link rmdCodeDelim Delimiter | |
77 | |
78 " You don't need this if either your markdown/syntax.vim already highlights | |
79 " the YAML header or you are writing standard markdown | |
80 if g:rmd_syn_hl_yaml | |
81 " Minimum highlighting of yaml header | |
82 syn match rmdYamlFieldTtl /^\s*\zs\w*\ze:/ contained | |
83 syn match rmdYamlFieldTtl /^\s*-\s*\zs\w*\ze:/ contained | |
84 syn region yamlFlowString matchgroup=yamlFlowStringDelimiter start='"' skip='\\"' end='"' contains=yamlEscape,rmdrInline contained | |
85 syn region yamlFlowString matchgroup=yamlFlowStringDelimiter start="'" skip="''" end="'" contains=yamlSingleEscape,rmdrInline contained | |
86 syn match yamlEscape contained '\\\%([\\"abefnrtv\^0_ NLP\n]\|x\x\x\|u\x\{4}\|U\x\{8}\)' | |
87 syn match yamlSingleEscape contained "''" | |
88 syn region pandocYAMLHeader matchgroup=rmdYamlBlockDelim start=/\%(\%^\|\_^\s*\n\)\@<=\_^-\{3}\ze\n.\+/ end=/^\([-.]\)\1\{2}$/ keepend contains=rmdYamlFieldTtl,yamlFlowString | |
89 hi def link rmdYamlBlockDelim Delimiter | |
90 hi def link rmdYamlFieldTtl Identifier | |
91 hi def link yamlFlowString String | |
6051 | 92 endif |
93 | |
14637 | 94 " You don't need this if either your markdown/syntax.vim already highlights |
95 " citations or you are writing standard markdown | |
96 if g:rmd_syn_hl_citations | |
97 " From vim-pandoc-syntax | |
98 " parenthetical citations | |
99 syn match pandocPCite /\^\@<!\[[^\[\]]\{-}-\{0,1}@[[:alnum:]_][[:alnum:]à-öø-ÿÀ-ÖØ-ß_:.#$%&\-+?<>~\/]*.\{-}\]/ contains=pandocEmphasis,pandocStrong,pandocLatex,pandocCiteKey,@Spell,pandocAmpersandEscape display | |
100 " in-text citations with location | |
101 syn match pandocICite /@[[:alnum:]_][[:alnum:]à-öø-ÿÀ-ÖØ-ß_:.#$%&\-+?<>~\/]*\s\[.\{-1,}\]/ contains=pandocCiteKey,@Spell display | |
102 " cite keys | |
103 syn match pandocCiteKey /\(-\=@[[:alnum:]_][[:alnum:]à-öø-ÿÀ-ÖØ-ß_:.#$%&\-+?<>~\/]*\)/ containedin=pandocPCite,pandocICite contains=@NoSpell display | |
104 syn match pandocCiteAnchor /[-@]/ contained containedin=pandocCiteKey display | |
105 syn match pandocCiteLocator /[\[\]]/ contained containedin=pandocPCite,pandocICite | |
106 hi def link pandocPCite Operator | |
107 hi def link pandocICite Operator | |
108 hi def link pandocCiteKey Label | |
109 hi def link pandocCiteAnchor Operator | |
110 hi def link pandocCiteLocator Operator | |
111 endif | |
6051 | 112 |
113 let b:current_syntax = "rmd" | |
114 | |
14637 | 115 let &cpo = s:cpo_save |
116 unlet s:cpo_save | |
117 | |
6051 | 118 " vim: ts=8 sw=2 |