Mercurial > vim
annotate runtime/syntax/rmd.vim @ 27936:07aea9530e05 v8.2.4493
patch 8.2.4493: options test fails in the GUI
Commit: https://github.com/vim/vim/commit/b9c510859360595c046b8b7c1d6828125525e967
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Mar 2 20:12:03 2022 +0000
patch 8.2.4493: options test fails in the GUI
Problem: Options test fails in the GUI.
Solution: Do not save and restore 'term'.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 02 Mar 2022 21:15:03 +0100 |
parents | 5bda4653aced |
children | b2412874362f |
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 |
24520 | 4 " Last Change: Wed Apr 21, 2021 09:55AM |
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 | |
24520 | 16 " Highlight the header of the chunks as R code |
17 let g:rmd_syn_hl_chunk = get(g:, 'rmd_syn_hl_chunk', 0) | |
14637 | 18 |
19 " Pandoc-syntax has more features, but it is slower. | |
11347 | 20 " https://github.com/vim-pandoc/vim-pandoc-syntax |
14637 | 21 let g:pandoc#syntax#codeblocks#embeds#langs = get(g:, 'pandoc#syntax#codeblocks#embeds#langs', ['r']) |
6051 | 22 runtime syntax/pandoc.vim |
23 if exists("b:current_syntax") | |
24520 | 24 " Recognize inline R code |
14637 | 25 syn region rmdrInline matchgroup=rmdInlineDelim start="`r " end="`" contains=@R containedin=pandocLaTeXRegion,yamlFlowString keepend |
26 hi def link rmdInlineDelim Delimiter | |
24520 | 27 |
28 " Fix recognition of language chunks (code adapted from pandoc, 2021-03-28) | |
29 " Knitr requires braces in the block's header | |
30 for s:lng in g:pandoc#syntax#codeblocks#embeds#langs | |
31 let s:nm = matchstr(s:lng, '^[^=]*') | |
32 exe 'syn clear pandocDelimitedCodeBlock_'.s:nm | |
33 exe 'syn clear pandocDelimitedCodeBlockinBlockQuote_'.s:nm | |
34 if g:rmd_syn_hl_chunk | |
35 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=@R' | |
36 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,@'.toupper(s:nm) | |
37 else | |
38 exe 'syn region rmd'.s:nm.'Chunk matchgroup=rmdCodeDelim start="^\s*```\s*{\s*'.s:nm.'\>.*$" matchgroup=rmdCodeDelim end="^\s*```\ze\s*$" keepend contains=@'.toupper(s:nm) | |
39 endif | |
40 endfor | |
41 unlet s:lng | |
42 unlet s:nm | |
43 hi def link rmdInlineDelim Delimiter | |
44 hi def link rmdCodeDelim Delimiter | |
14637 | 45 let b:current_syntax = "rmd" |
46 finish | |
6051 | 47 endif |
48 | |
24520 | 49 " Configuration if not using pandoc syntax: |
50 " Add syntax highlighting of YAML header | |
51 let g:rmd_syn_hl_yaml = get(g:, 'rmd_syn_hl_yaml', 1) | |
52 " Add syntax highlighting of citation keys | |
53 let g:rmd_syn_hl_citations = get(g:, 'rmd_syn_hl_citations', 1) | |
54 | |
14637 | 55 let s:cpo_save = &cpo |
56 set cpo&vim | |
57 | |
58 " R chunks will not be highlighted by syntax/markdown because their headers | |
59 " follow a non standard pattern: "```{lang" instead of "^```lang". | |
60 " Make a copy of g:markdown_fenced_languages to highlight the chunks later: | |
61 if exists('g:markdown_fenced_languages') | |
62 if !exists('g:rmd_fenced_languages') | |
63 let g:rmd_fenced_languages = deepcopy(g:markdown_fenced_languages) | |
64 let g:markdown_fenced_languages = [] | |
65 endif | |
6051 | 66 else |
14637 | 67 let g:rmd_fenced_languages = ['r'] |
6051 | 68 endif |
11347 | 69 |
14637 | 70 runtime syntax/markdown.vim |
6051 | 71 |
14637 | 72 " Now highlight chunks: |
73 for s:type in g:rmd_fenced_languages | |
74 if s:type =~ '=' | |
16610 | 75 let s:ft = substitute(s:type, '.*=', '', '') |
76 let s:nm = substitute(s:type, '=.*', '', '') | |
14637 | 77 else |
16610 | 78 let s:ft = s:type |
14637 | 79 let s:nm = s:type |
80 endif | |
81 unlet! b:current_syntax | |
16610 | 82 exe 'syn include @Rmd'.s:nm.' syntax/'.s:ft.'.vim' |
14637 | 83 if g:rmd_syn_hl_chunk |
24520 | 84 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=@Rmdr' |
14637 | 85 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 |
86 else | |
87 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 | 88 endif |
14637 | 89 endfor |
90 unlet! s:type | |
91 | |
24520 | 92 " Recognize inline R code |
93 syn region rmdrInline matchgroup=rmdInlineDelim start="`r " end="`" contains=@Rmdr keepend | |
94 | |
14637 | 95 hi def link rmdInlineDelim Delimiter |
96 hi def link rmdCodeDelim Delimiter | |
97 | |
98 " You don't need this if either your markdown/syntax.vim already highlights | |
99 " the YAML header or you are writing standard markdown | |
100 if g:rmd_syn_hl_yaml | |
101 " Minimum highlighting of yaml header | |
102 syn match rmdYamlFieldTtl /^\s*\zs\w*\ze:/ contained | |
103 syn match rmdYamlFieldTtl /^\s*-\s*\zs\w*\ze:/ contained | |
104 syn region yamlFlowString matchgroup=yamlFlowStringDelimiter start='"' skip='\\"' end='"' contains=yamlEscape,rmdrInline contained | |
105 syn region yamlFlowString matchgroup=yamlFlowStringDelimiter start="'" skip="''" end="'" contains=yamlSingleEscape,rmdrInline contained | |
106 syn match yamlEscape contained '\\\%([\\"abefnrtv\^0_ NLP\n]\|x\x\x\|u\x\{4}\|U\x\{8}\)' | |
107 syn match yamlSingleEscape contained "''" | |
108 syn region pandocYAMLHeader matchgroup=rmdYamlBlockDelim start=/\%(\%^\|\_^\s*\n\)\@<=\_^-\{3}\ze\n.\+/ end=/^\([-.]\)\1\{2}$/ keepend contains=rmdYamlFieldTtl,yamlFlowString | |
109 hi def link rmdYamlBlockDelim Delimiter | |
110 hi def link rmdYamlFieldTtl Identifier | |
111 hi def link yamlFlowString String | |
6051 | 112 endif |
113 | |
14637 | 114 " You don't need this if either your markdown/syntax.vim already highlights |
115 " citations or you are writing standard markdown | |
116 if g:rmd_syn_hl_citations | |
117 " From vim-pandoc-syntax | |
118 " parenthetical citations | |
119 syn match pandocPCite /\^\@<!\[[^\[\]]\{-}-\{0,1}@[[:alnum:]_][[:alnum:]à-öø-ÿÀ-ÖØ-ß_:.#$%&\-+?<>~\/]*.\{-}\]/ contains=pandocEmphasis,pandocStrong,pandocLatex,pandocCiteKey,@Spell,pandocAmpersandEscape display | |
120 " in-text citations with location | |
121 syn match pandocICite /@[[:alnum:]_][[:alnum:]à-öø-ÿÀ-ÖØ-ß_:.#$%&\-+?<>~\/]*\s\[.\{-1,}\]/ contains=pandocCiteKey,@Spell display | |
122 " cite keys | |
123 syn match pandocCiteKey /\(-\=@[[:alnum:]_][[:alnum:]à-öø-ÿÀ-ÖØ-ß_:.#$%&\-+?<>~\/]*\)/ containedin=pandocPCite,pandocICite contains=@NoSpell display | |
124 syn match pandocCiteAnchor /[-@]/ contained containedin=pandocCiteKey display | |
125 syn match pandocCiteLocator /[\[\]]/ contained containedin=pandocPCite,pandocICite | |
126 hi def link pandocPCite Operator | |
127 hi def link pandocICite Operator | |
128 hi def link pandocCiteKey Label | |
129 hi def link pandocCiteAnchor Operator | |
130 hi def link pandocCiteLocator Operator | |
131 endif | |
6051 | 132 |
133 let b:current_syntax = "rmd" | |
134 | |
14637 | 135 let &cpo = s:cpo_save |
136 unlet s:cpo_save | |
137 | |
6051 | 138 " vim: ts=8 sw=2 |