Mercurial > vim
annotate runtime/syntax/rmd.vim @ 32760:8eded585a4d5 v9.0.1699
patch 9.0.1699: compile warning for xdiff/xutils on MS-Windows
Commit: https://github.com/vim/vim/commit/6c313bbb043745a60a7ee30a78edb907260b764a
Author: Mike Williams <mikew@globalgraphics.com>
Date: Sat Aug 12 20:47:43 2023 +0200
patch 9.0.1699: compile warning for xdiff/xutils on MS-Windows
Problem: compile warning for xdiff/xutils on MS-Windows
Solution: add explicit type cast from size_t to long
closes: #12531
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Mike Williams <mikew@globalgraphics.com>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 12 Aug 2023 21:00:05 +0200 |
parents | b2412874362f |
children | d46f974fd69e |
rev | line source |
---|---|
32061 | 1 " Language: Markdown with chunks of R, Python and other languages |
2 " Maintainer: Jakson Aquino <jalvesaq@gmail.com> | |
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 |
32061 | 4 " Last Change: Fri Feb 24, 2023 08:28AM |
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 | |
32061 | 16 let s:cpo_save = &cpo |
17 set cpo&vim | |
18 | |
24520 | 19 " Highlight the header of the chunks as R code |
20 let g:rmd_syn_hl_chunk = get(g:, 'rmd_syn_hl_chunk', 0) | |
14637 | 21 |
22 " Pandoc-syntax has more features, but it is slower. | |
11347 | 23 " https://github.com/vim-pandoc/vim-pandoc-syntax |
32061 | 24 |
25 " Don't waste time loading syntax that will be discarded: | |
26 let s:save_pandoc_lngs = get(g:, 'pandoc#syntax#codeblocks#embeds#langs', []) | |
27 let g:pandoc#syntax#codeblocks#embeds#langs = [] | |
28 | |
29 " Step_1: Source pandoc.vim if it is installed: | |
6051 | 30 runtime syntax/pandoc.vim |
31 if exists("b:current_syntax") | |
32061 | 32 if hlexists('pandocDelimitedCodeBlock') |
33 syn clear pandocDelimitedCodeBlock | |
34 endif | |
35 | |
36 if len(s:save_pandoc_lngs) > 0 && !exists('g:rmd_fenced_languages') | |
37 let g:rmd_fenced_languages = deepcopy(s:save_pandoc_lngs) | |
38 endif | |
39 | |
24520 | 40 " Recognize inline R code |
32061 | 41 syn region rmdrInline matchgroup=rmdInlineDelim start="`r " end="`" contains=@Rmdr containedin=pandocLaTeXRegion,yamlFlowString keepend |
42 else | |
43 " Step_2: Source markdown.vim if pandoc.vim is not installed | |
44 | |
45 " Configuration if not using pandoc syntax: | |
46 " Add syntax highlighting of YAML header | |
47 let g:rmd_syn_hl_yaml = get(g:, 'rmd_syn_hl_yaml', 1) | |
48 " Add syntax highlighting of citation keys | |
49 let g:rmd_syn_hl_citations = get(g:, 'rmd_syn_hl_citations', 1) | |
50 | |
51 " R chunks will not be highlighted by syntax/markdown because their headers | |
52 " follow a non standard pattern: "```{lang" instead of "^```lang". | |
53 " Make a copy of g:markdown_fenced_languages to highlight the chunks later: | |
54 if exists('g:markdown_fenced_languages') && !exists('g:rmd_fenced_languages') | |
55 let g:rmd_fenced_languages = deepcopy(g:markdown_fenced_languages) | |
56 endif | |
57 | |
58 if exists('g:markdown_fenced_languages') && len(g:markdown_fenced_languages) > 0 | |
59 let s:save_mfl = deepcopy(g:markdown_fenced_languages) | |
60 endif | |
61 " Don't waste time loading syntax that will be discarded: | |
62 let g:markdown_fenced_languages = [] | |
63 runtime syntax/markdown.vim | |
64 if exists('s:save_mfl') > 0 | |
65 let g:markdown_fenced_languages = deepcopy(s:save_mfl) | |
66 unlet s:save_mfl | |
67 endif | |
68 syn region rmdrInline matchgroup=rmdInlineDelim start="`r " end="`" contains=@Rmdr keepend | |
69 | |
70 " Step_2a: Add highlighting for both YAML and citations which are pandoc | |
71 " specific, but also used in Rmd files | |
24520 | 72 |
32061 | 73 " You don't need this if either your markdown/syntax.vim already highlights |
74 " the YAML header or you are writing standard markdown | |
75 if g:rmd_syn_hl_yaml | |
76 " Basic highlighting of YAML header | |
77 syn match rmdYamlFieldTtl /^\s*\zs\w\%(-\|\w\)*\ze:/ contained | |
78 syn match rmdYamlFieldTtl /^\s*-\s*\zs\w\%(-\|\w\)*\ze:/ contained | |
79 syn region yamlFlowString matchgroup=yamlFlowStringDelimiter start='"' skip='\\"' end='"' contains=yamlEscape,rmdrInline contained | |
80 syn region yamlFlowString matchgroup=yamlFlowStringDelimiter start="'" skip="''" end="'" contains=yamlSingleEscape,rmdrInline contained | |
81 syn match yamlEscape contained '\\\%([\\"abefnrtv\^0_ NLP\n]\|x\x\x\|u\x\{4}\|U\x\{8}\)' | |
82 syn match yamlSingleEscape contained "''" | |
83 syn match yamlComment /#.*/ contained | |
84 " A second colon is a syntax error, unles within a string or following !expr | |
85 syn match yamlColonError /:\s*[^'^"^!]*:/ contained | |
86 if &filetype == 'quarto' | |
87 syn region pandocYAMLHeader matchgroup=rmdYamlBlockDelim start=/\%(\%^\|\_^\s*\n\)\@<=\_^-\{3}\ze\n.\+/ end=/^---$/ keepend contains=rmdYamlFieldTtl,yamlFlowString,yamlComment,yamlColonError | |
24520 | 88 else |
32061 | 89 syn region pandocYAMLHeader matchgroup=rmdYamlBlockDelim start=/\%(\%^\|\_^\s*\n\)\@<=\_^-\{3}\ze\n.\+/ end=/^\([-.]\)\1\{2}$/ keepend contains=rmdYamlFieldTtl,yamlFlowString,yamlComment,yamlColonError |
24520 | 90 endif |
32061 | 91 hi def link rmdYamlBlockDelim Delimiter |
92 hi def link rmdYamlFieldTtl Identifier | |
93 hi def link yamlFlowString String | |
94 hi def link yamlComment Comment | |
95 hi def link yamlColonError Error | |
96 endif | |
97 | |
98 " You don't need this if either your markdown/syntax.vim already highlights | |
99 " citations or you are writing standard markdown | |
100 if g:rmd_syn_hl_citations | |
101 " From vim-pandoc-syntax | |
102 " parenthetical citations | |
103 syn match pandocPCite /\^\@<!\[[^\[\]]\{-}-\{0,1}@[[:alnum:]_][[:alnum:]à-öø-ÿÀ-ÖØ-ß_:.#$%&\-+?<>~\/]*.\{-}\]/ contains=pandocEmphasis,pandocStrong,pandocLatex,pandocCiteKey,@Spell,pandocAmpersandEscape display | |
104 " in-text citations with location | |
105 syn match pandocICite /@[[:alnum:]_][[:alnum:]à-öø-ÿÀ-ÖØ-ß_:.#$%&\-+?<>~\/]*\s\[.\{-1,}\]/ contains=pandocCiteKey,@Spell display | |
106 " cite keys | |
107 syn match pandocCiteKey /\(-\=@[[:alnum:]_][[:alnum:]à-öø-ÿÀ-ÖØ-ß_:.#$%&\-+?<>~\/]*\)/ containedin=pandocPCite,pandocICite contains=@NoSpell display | |
108 syn match pandocCiteAnchor /[-@]/ contained containedin=pandocCiteKey display | |
109 syn match pandocCiteLocator /[\[\]]/ contained containedin=pandocPCite,pandocICite | |
110 hi def link pandocPCite Operator | |
111 hi def link pandocICite Operator | |
112 hi def link pandocCiteKey Label | |
113 hi def link pandocCiteAnchor Operator | |
114 hi def link pandocCiteLocator Operator | |
115 endif | |
6051 | 116 endif |
117 | |
32061 | 118 " Step_3: Highlight code blocks. |
14637 | 119 |
32061 | 120 syn region rmdCodeBlock matchgroup=rmdCodeDelim start="^\s*```\s*{.*}$" matchgroup=rmdCodeDelim end="^\s*```\ze\s*$" keepend |
121 syn region rmdCodeBlock matchgroup=rmdCodeDelim start="^\s*```.+$" matchgroup=rmdCodeDelim end="^```$" keepend | |
122 hi link rmdCodeBlock Special | |
6051 | 123 |
14637 | 124 " Now highlight chunks: |
32061 | 125 syn region knitrBodyOptions start='^#| ' end='$' contained containedin=rComment,pythonComment contains=knitrBodyVar,knitrBodyValue transparent |
126 syn match knitrBodyValue ': \zs.*\ze$' keepend contained containedin=knitrBodyOptions | |
127 syn match knitrBodyVar '| \zs\S\{-}\ze:' contained containedin=knitrBodyOptions | |
128 | |
129 let g:rmd_fenced_languages = get(g:, 'rmd_fenced_languages', ['r']) | |
14637 | 130 for s:type in g:rmd_fenced_languages |
131 if s:type =~ '=' | |
16610 | 132 let s:ft = substitute(s:type, '.*=', '', '') |
133 let s:nm = substitute(s:type, '=.*', '', '') | |
14637 | 134 else |
16610 | 135 let s:ft = s:type |
14637 | 136 let s:nm = s:type |
137 endif | |
138 unlet! b:current_syntax | |
16610 | 139 exe 'syn include @Rmd'.s:nm.' syntax/'.s:ft.'.vim' |
14637 | 140 if g:rmd_syn_hl_chunk |
32061 | 141 exe 'syn match knitrChunkDelim /```\s*{\s*'.s:nm.'/ contained containedin=knitrChunkBrace contains=knitrChunkLabel' |
142 exe 'syn match knitrChunkLabelDelim /```\s*{\s*'.s:nm.',\=\s*[-[:alnum:]]\{-1,}[,}]/ contained containedin=knitrChunkBrace' | |
143 syn match knitrChunkDelim /}\s*$/ contained containedin=knitrChunkBrace | |
144 exe 'syn match knitrChunkBrace /```\s*{\s*'.s:nm.'.*$/ contained containedin=rmd'.s:nm.'Chunk contains=knitrChunkDelim,knitrChunkLabelDelim,@Rmd'.s:nm | |
145 exe 'syn region rmd'.s:nm.'Chunk start="^\s*```\s*{\s*=\?'.s:nm.'\>.*$" matchgroup=rmdCodeDelim end="^\s*```\ze\s*$" keepend contains=knitrChunkBrace,@Rmd'.s:nm | |
146 | |
147 hi link knitrChunkLabel Identifier | |
148 hi link knitrChunkDelim rmdCodeDelim | |
149 hi link knitrChunkLabelDelim rmdCodeDelim | |
14637 | 150 else |
32061 | 151 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 | 152 endif |
14637 | 153 endfor |
154 unlet! s:type | |
155 | |
32061 | 156 " Step_4: Highlight code recognized by pandoc but not defined in pandoc.vim yet: |
157 syn match pandocDivBegin '^:::\+ {.\{-}}' contains=pandocHeaderAttr | |
158 syn match pandocDivEnd '^:::\+$' | |
24520 | 159 |
32061 | 160 hi def link knitrBodyVar PreProc |
161 hi def link knitrBodyValue Constant | |
162 hi def link knitrBodyOptions rComment | |
163 hi def link pandocDivBegin Delimiter | |
164 hi def link pandocDivEnd Delimiter | |
14637 | 165 hi def link rmdInlineDelim Delimiter |
166 hi def link rmdCodeDelim Delimiter | |
167 | |
32061 | 168 if len(s:save_pandoc_lngs) |
169 let g:pandoc#syntax#codeblocks#embeds#langs = s:save_pandoc_lngs | |
6051 | 170 endif |
32061 | 171 unlet s:save_pandoc_lngs |
172 let &cpo = s:cpo_save | |
173 unlet s:cpo_save | |
6051 | 174 |
175 let b:current_syntax = "rmd" | |
176 | |
177 " vim: ts=8 sw=2 |