Mercurial > vim
comparison runtime/syntax/rmd.vim @ 14637:0ecb909e3249
Update runtime files.
commit https://github.com/vim/vim/commit/fc65cabb15d0236bce001ad78e12a40511caf941
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Aug 28 22:58:02 2018 +0200
Update runtime files.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 28 Aug 2018 23:00:08 +0200 |
parents | 4aae8146c21f |
children | 1eaf34420bb3 |
comparison
equal
deleted
inserted
replaced
14636:91eef21ff090 | 14637:0ecb909e3249 |
---|---|
1 " markdown Text with R statements | 1 " markdown Text with R statements |
2 " Language: markdown with R code chunks | 2 " Language: markdown with R code chunks |
3 " Homepage: https://github.com/jalvesaq/R-Vim-runtime | 3 " Homepage: https://github.com/jalvesaq/R-Vim-runtime |
4 " Last Change: Sat Jan 28, 2017 10:06PM | 4 " Last Change: Sat Aug 25, 2018 03:44PM |
5 " | |
6 " CONFIGURATION: | |
7 " To highlight chunk headers as R code, put in your vimrc (e.g. .config/nvim/init.vim): | |
8 " let rmd_syn_hl_chunk = 1 | |
9 " | 5 " |
10 " For highlighting pandoc extensions to markdown like citations and TeX and | 6 " For highlighting pandoc extensions to markdown like citations and TeX and |
11 " many other advanced features like folding of markdown sections, it is | 7 " many other advanced features like folding of markdown sections, it is |
12 " recommended to install the vim-pandoc filetype plugin as well as the | 8 " recommended to install the vim-pandoc filetype plugin as well as the |
13 " vim-pandoc-syntax filetype plugin from https://github.com/vim-pandoc. | 9 " vim-pandoc-syntax filetype plugin from https://github.com/vim-pandoc. |
14 " | 10 |
15 " TODO: | |
16 " - Provide highlighting for rmarkdown parameters in yaml header | |
17 | 11 |
18 if exists("b:current_syntax") | 12 if exists("b:current_syntax") |
19 finish | 13 finish |
20 endif | 14 endif |
21 | 15 |
22 " load all of pandoc info, e.g. from | 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. | |
23 " https://github.com/vim-pandoc/vim-pandoc-syntax | 25 " https://github.com/vim-pandoc/vim-pandoc-syntax |
26 let g:pandoc#syntax#codeblocks#embeds#langs = get(g:, 'pandoc#syntax#codeblocks#embeds#langs', ['r']) | |
24 runtime syntax/pandoc.vim | 27 runtime syntax/pandoc.vim |
25 if exists("b:current_syntax") | 28 if exists("b:current_syntax") |
26 let rmdIsPandoc = 1 | 29 " Fix recognition of R code |
27 unlet b:current_syntax | 30 syn region pandocDelimitedCodeBlock_r start=/^```{r\>.*}$/ end=/^```$/ contained containedin=pandocDelimitedCodeBlock contains=@R |
28 else | 31 syn region rmdrInline matchgroup=rmdInlineDelim start="`r " end="`" contains=@R containedin=pandocLaTeXRegion,yamlFlowString keepend |
29 let rmdIsPandoc = 0 | 32 hi def link rmdInlineDelim Delimiter |
30 runtime syntax/markdown.vim | 33 let b:current_syntax = "rmd" |
31 if exists("b:current_syntax") | 34 finish |
32 unlet b:current_syntax | |
33 endif | |
34 | |
35 " load all of the yaml syntax highlighting rules into @yaml | |
36 syntax include @yaml syntax/yaml.vim | |
37 if exists("b:current_syntax") | |
38 unlet b:current_syntax | |
39 endif | |
40 | |
41 " highlight yaml block commonly used for front matter | |
42 syntax region rmdYamlBlock matchgroup=rmdYamlBlockDelim start="^---" matchgroup=rmdYamlBlockDelim end="^---" contains=@yaml keepend fold | |
43 endif | 35 endif |
44 | 36 |
45 if !exists("g:rmd_syn_langs") | 37 let s:cpo_save = &cpo |
46 let g:rmd_syn_langs = ["r"] | 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 | |
47 else | 48 else |
48 let s:hasr = 0 | 49 let g:rmd_fenced_languages = ['r'] |
49 for s:lng in g:rmd_syn_langs | |
50 if s:lng == "r" | |
51 let s:hasr = 1 | |
52 endif | |
53 endfor | |
54 if s:hasr == 0 | |
55 let g:rmd_syn_langs += ["r"] | |
56 endif | |
57 endif | 50 endif |
58 | 51 |
59 for s:lng in g:rmd_syn_langs | 52 runtime syntax/markdown.vim |
60 exe 'syntax include @' . toupper(s:lng) . ' syntax/'. s:lng . '.vim' | 53 |
61 if exists("b:current_syntax") | 54 " Now highlight chunks: |
62 unlet b:current_syntax | 55 for s:type in g:rmd_fenced_languages |
56 if s:type =~ '=' | |
57 let s:lng = substitute(s:type, '=.*', '') | |
58 let s:nm = substitute(s:type, '.*=', '') | |
59 else | |
60 let s:lng = s:type | |
61 let s:nm = s:type | |
63 endif | 62 endif |
64 exe 'syntax region rmd' . toupper(s:lng) . 'Chunk start="^[ \t]*``` *{\(' . s:lng . '\|r.*engine\s*=\s*["' . "']" . s:lng . "['" . '"]\).*}$" end="^[ \t]*```$" contains=@' . toupper(s:lng) . ',rmd' . toupper(s:lng) . 'ChunkDelim keepend fold' | 63 unlet! b:current_syntax |
64 exe 'syn include @Rmd'.s:nm.' syntax/'.s:lng.'.vim' | |
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 | |
70 endif | |
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 | |
65 | 74 |
66 if exists("g:rmd_syn_hl_chunk") && s:lng == "r" | 75 hi def link rmdInlineDelim Delimiter |
67 " highlight R code inside chunk header | 76 hi def link rmdCodeDelim Delimiter |
68 syntax match rmdRChunkDelim "^[ \t]*```{r" contained | |
69 syntax match rmdRChunkDelim "}$" contained | |
70 else | |
71 exe 'syntax match rmd' . toupper(s:lng) . 'ChunkDelim "^[ \t]*```{\(' . s:lng . '\|r.*engine\s*=\s*["' . "']" . s:lng . "['" . '"]\).*}$" contained' | |
72 endif | |
73 exe 'syntax match rmd' . toupper(s:lng) . 'ChunkDelim "^[ \t]*```$" contained' | |
74 endfor | |
75 | 77 |
76 | 78 " You don't need this if either your markdown/syntax.vim already highlights |
77 " also match and syntax highlight in-line R code | 79 " the YAML header or you are writing standard markdown |
78 syntax region rmdrInline matchgroup=rmdInlineDelim start="`r " end="`" contains=@R containedin=pandocLaTeXRegion,yamlFlowString keepend | 80 if g:rmd_syn_hl_yaml |
79 " I was not able to highlight rmdrInline inside a pandocLaTeXCommand, although | 81 " Minimum highlighting of yaml header |
80 " highlighting works within pandocLaTeXRegion and yamlFlowString. | 82 syn match rmdYamlFieldTtl /^\s*\zs\w*\ze:/ contained |
81 syntax cluster texMathZoneGroup add=rmdrInline | 83 syn match rmdYamlFieldTtl /^\s*-\s*\zs\w*\ze:/ contained |
82 | 84 syn region yamlFlowString matchgroup=yamlFlowStringDelimiter start='"' skip='\\"' end='"' contains=yamlEscape,rmdrInline contained |
83 " match slidify special marker | 85 syn region yamlFlowString matchgroup=yamlFlowStringDelimiter start="'" skip="''" end="'" contains=yamlSingleEscape,rmdrInline contained |
84 syntax match rmdSlidifySpecial "\*\*\*" | 86 syn match yamlEscape contained '\\\%([\\"abefnrtv\^0_ NLP\n]\|x\x\x\|u\x\{4}\|U\x\{8}\)' |
85 | 87 syn match yamlSingleEscape contained "''" |
86 | 88 syn region pandocYAMLHeader matchgroup=rmdYamlBlockDelim start=/\%(\%^\|\_^\s*\n\)\@<=\_^-\{3}\ze\n.\+/ end=/^\([-.]\)\1\{2}$/ keepend contains=rmdYamlFieldTtl,yamlFlowString |
87 if rmdIsPandoc == 0 | 89 hi def link rmdYamlBlockDelim Delimiter |
88 syn match rmdBlockQuote /^\s*>.*\n\(.*\n\@<!\n\)*/ skipnl | 90 hi def link rmdYamlFieldTtl Identifier |
89 " LaTeX | 91 hi def link yamlFlowString String |
90 syntax include @LaTeX syntax/tex.vim | |
91 if exists("b:current_syntax") | |
92 unlet b:current_syntax | |
93 endif | |
94 " Inline | |
95 syntax match rmdLaTeXInlDelim "\$" | |
96 syntax match rmdLaTeXInlDelim "\\\$" | |
97 syn region texMathZoneX matchgroup=Delimiter start="\$" skip="\\\\\|\\\$" matchgroup=Delimiter end="\$" end="%stopzone\>" contains=@texMathZoneGroup | |
98 " Region | |
99 syntax match rmdLaTeXRegDelim "\$\$" contained | |
100 syntax match rmdLaTeXRegDelim "\$\$latex$" contained | |
101 syntax match rmdLaTeXSt "\\[a-zA-Z]\+" | |
102 syntax region rmdLaTeXRegion start="^\$\$" skip="\\\$" end="\$\$$" contains=@LaTeX,rmdLaTeXRegDelim keepend | |
103 syntax region rmdLaTeXRegion2 start="^\\\[" end="\\\]" contains=@LaTeX,rmdLaTeXRegDelim keepend | |
104 hi def link rmdBlockQuote Comment | |
105 hi def link rmdLaTeXSt Statement | |
106 hi def link rmdLaTeXInlDelim Special | |
107 hi def link rmdLaTeXRegDelim Special | |
108 endif | 92 endif |
109 | 93 |
110 for s:lng in g:rmd_syn_langs | 94 " You don't need this if either your markdown/syntax.vim already highlights |
111 exe 'syn sync match rmd' . toupper(s:lng) . 'SyncChunk grouphere rmd' . toupper(s:lng) . 'Chunk /^[ \t]*``` *{\(' . s:lng . '\|r.*engine\s*=\s*["' . "']" . s:lng . "['" . '"]\)/' | 95 " citations or you are writing standard markdown |
112 endfor | 96 if g:rmd_syn_hl_citations |
113 | 97 " From vim-pandoc-syntax |
114 hi def link rmdYamlBlockDelim Delim | 98 " parenthetical citations |
115 for s:lng in g:rmd_syn_langs | 99 syn match pandocPCite /\^\@<!\[[^\[\]]\{-}-\{0,1}@[[:alnum:]_][[:alnum:]à-öø-ÿÀ-ÖØ-ß_:.#$%&\-+?<>~\/]*.\{-}\]/ contains=pandocEmphasis,pandocStrong,pandocLatex,pandocCiteKey,@Spell,pandocAmpersandEscape display |
116 exe 'hi def link rmd' . toupper(s:lng) . 'ChunkDelim Special' | 100 " in-text citations with location |
117 endfor | 101 syn match pandocICite /@[[:alnum:]_][[:alnum:]à-öø-ÿÀ-ÖØ-ß_:.#$%&\-+?<>~\/]*\s\[.\{-1,}\]/ contains=pandocCiteKey,@Spell display |
118 hi def link rmdInlineDelim Special | 102 " cite keys |
119 hi def link rmdSlidifySpecial Special | 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 | |
120 | 112 |
121 let b:current_syntax = "rmd" | 113 let b:current_syntax = "rmd" |
122 | 114 |
115 let &cpo = s:cpo_save | |
116 unlet s:cpo_save | |
117 | |
123 " vim: ts=8 sw=2 | 118 " vim: ts=8 sw=2 |