aboutsummaryrefslogtreecommitdiff
path: root/runtime/syntax/rmd.vim
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-12-03 16:49:30 +0300
committerZyX <kp-pav@yandex.ru>2017-12-03 16:49:30 +0300
commitc49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57 (patch)
treeb7e59c416d1435725c65f8952b6e55c70544d97e /runtime/syntax/rmd.vim
parent62108c3b0be46936c83f6d4c98b44ceb5e6f77fd (diff)
parent27a577586eace687c47e7398845178208cae524a (diff)
downloadrneovim-c49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57.tar.gz
rneovim-c49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57.tar.bz2
rneovim-c49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57.zip
Merge branch 'master' into s-dash-stdin
Diffstat (limited to 'runtime/syntax/rmd.vim')
-rw-r--r--runtime/syntax/rmd.vim94
1 files changed, 65 insertions, 29 deletions
diff --git a/runtime/syntax/rmd.vim b/runtime/syntax/rmd.vim
index 4cde7441d3..05435354ad 100644
--- a/runtime/syntax/rmd.vim
+++ b/runtime/syntax/rmd.vim
@@ -1,17 +1,26 @@
" markdown Text with R statements
" Language: markdown with R code chunks
" Homepage: https://github.com/jalvesaq/R-Vim-runtime
-" Last Change: Sat Feb 06, 2016 06:45AM
+" Last Change: Sat Jan 28, 2017 10:06PM
"
" CONFIGURATION:
-" To highlight chunk headers as R code, put in your vimrc:
+" To highlight chunk headers as R code, put in your vimrc (e.g. .config/nvim/init.vim):
" let rmd_syn_hl_chunk = 1
+"
+" For highlighting pandoc extensions to markdown like citations and TeX and
+" many other advanced features like folding of markdown sections, it is
+" recommended to install the vim-pandoc filetype plugin as well as the
+" vim-pandoc-syntax filetype plugin from https://github.com/vim-pandoc.
+"
+" TODO:
+" - Provide highlighting for rmarkdown parameters in yaml header
if exists("b:current_syntax")
finish
endif
-" load all of pandoc info
+" load all of pandoc info, e.g. from
+" https://github.com/vim-pandoc/vim-pandoc-syntax
runtime syntax/pandoc.vim
if exists("b:current_syntax")
let rmdIsPandoc = 1
@@ -22,28 +31,54 @@ else
if exists("b:current_syntax")
unlet b:current_syntax
endif
-endif
-" load all of the r syntax highlighting rules into @R
-syntax include @R syntax/r.vim
-if exists("b:current_syntax")
- unlet b:current_syntax
+ " load all of the yaml syntax highlighting rules into @yaml
+ syntax include @yaml syntax/yaml.vim
+ if exists("b:current_syntax")
+ unlet b:current_syntax
+ endif
+
+ " highlight yaml block commonly used for front matter
+ syntax region rmdYamlBlock matchgroup=rmdYamlBlockDelim start="^---" matchgroup=rmdYamlBlockDelim end="^---" contains=@yaml keepend fold
endif
-if exists("g:rmd_syn_hl_chunk")
- " highlight R code inside chunk header
- syntax match rmdChunkDelim "^[ \t]*```{r" contained
- syntax match rmdChunkDelim "}$" contained
+if !exists("g:rmd_syn_langs")
+ let g:rmd_syn_langs = ["r"]
else
- syntax match rmdChunkDelim "^[ \t]*```{r.*}$" contained
+ let s:hasr = 0
+ for s:lng in g:rmd_syn_langs
+ if s:lng == "r"
+ let s:hasr = 1
+ endif
+ endfor
+ if s:hasr == 0
+ let g:rmd_syn_langs += ["r"]
+ endif
endif
-syntax match rmdChunkDelim "^[ \t]*```$" contained
-syntax region rmdChunk start="^[ \t]*``` *{r.*}$" end="^[ \t]*```$" contains=@R,rmdChunkDelim keepend fold
+
+for s:lng in g:rmd_syn_langs
+ exe 'syntax include @' . toupper(s:lng) . ' syntax/'. s:lng . '.vim'
+ if exists("b:current_syntax")
+ unlet b:current_syntax
+ endif
+ 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'
+
+ if exists("g:rmd_syn_hl_chunk") && s:lng == "r"
+ " highlight R code inside chunk header
+ syntax match rmdRChunkDelim "^[ \t]*```{r" contained
+ syntax match rmdRChunkDelim "}$" contained
+ else
+ exe 'syntax match rmd' . toupper(s:lng) . 'ChunkDelim "^[ \t]*```{\(' . s:lng . '\|r.*engine\s*=\s*["' . "']" . s:lng . "['" . '"]\).*}$" contained'
+ endif
+ exe 'syntax match rmd' . toupper(s:lng) . 'ChunkDelim "^[ \t]*```$" contained'
+endfor
+
" also match and syntax highlight in-line R code
-syntax match rmdEndInline "`" contained
-syntax match rmdBeginInline "`r " contained
-syntax region rmdrInline start="`r " end="`" contains=@R,rmdBeginInline,rmdEndInline keepend
+syntax region rmdrInline matchgroup=rmdInlineDelim start="`r " end="`" contains=@R containedin=pandocLaTeXRegion,yamlFlowString keepend
+" I was not able to highlight rmdrInline inside a pandocLaTeXCommand, although
+" highlighting works within pandocLaTeXRegion and yamlFlowString.
+syntax cluster texMathZoneGroup add=rmdrInline
" match slidify special marker
syntax match rmdSlidifySpecial "\*\*\*"
@@ -56,8 +91,6 @@ if rmdIsPandoc == 0
if exists("b:current_syntax")
unlet b:current_syntax
endif
- " Extend cluster
- syn cluster texMathZoneGroup add=rmdrInline
" Inline
syntax match rmdLaTeXInlDelim "\$"
syntax match rmdLaTeXInlDelim "\\\$"
@@ -65,21 +98,24 @@ if rmdIsPandoc == 0
" Region
syntax match rmdLaTeXRegDelim "\$\$" contained
syntax match rmdLaTeXRegDelim "\$\$latex$" contained
- syntax region rmdLaTeXRegion start="^\$\$" skip="\\\$" end="\$\$$" contains=@LaTeX,rmdLaTeXSt,rmdLaTeXRegDelim keepend
- syntax region rmdLaTeXRegion2 start="^\\\[" end="\\\]" contains=@LaTeX,rmdLaTeXSt,rmdLaTeXRegDelim keepend
+ syntax match rmdLaTeXSt "\\[a-zA-Z]\+"
+ syntax region rmdLaTeXRegion start="^\$\$" skip="\\\$" end="\$\$$" contains=@LaTeX,rmdLaTeXRegDelim keepend
+ syntax region rmdLaTeXRegion2 start="^\\\[" end="\\\]" contains=@LaTeX,rmdLaTeXRegDelim keepend
+ hi def link rmdBlockQuote Comment
hi def link rmdLaTeXSt Statement
hi def link rmdLaTeXInlDelim Special
hi def link rmdLaTeXRegDelim Special
endif
-setlocal iskeyword=@,48-57,_,.
-
-syn sync match rmdSyncChunk grouphere rmdChunk "^[ \t]*``` *{r"
+for s:lng in g:rmd_syn_langs
+ exe 'syn sync match rmd' . toupper(s:lng) . 'SyncChunk grouphere rmd' . toupper(s:lng) . 'Chunk /^[ \t]*``` *{\(' . s:lng . '\|r.*engine\s*=\s*["' . "']" . s:lng . "['" . '"]\)/'
+endfor
-hi def link rmdChunkDelim Special
-hi def link rmdBeginInline Special
-hi def link rmdEndInline Special
-hi def link rmdBlockQuote Comment
+hi def link rmdYamlBlockDelim Delim
+for s:lng in g:rmd_syn_langs
+ exe 'hi def link rmd' . toupper(s:lng) . 'ChunkDelim Special'
+endfor
+hi def link rmdInlineDelim Special
hi def link rmdSlidifySpecial Special
let b:current_syntax = "rmd"