runtime(r): Update R runtime files and docs (#13757)
* Update R runtime files
- Fix indentation issue with ggplot().
- Setlocal autoindent in indent/r.vim.
- New syntax option: rmd_include_latex.
- Clear syn iskeyword to recognize _ as keyword.
- Document some options.
- remove the test has("patch-7.4.1142")
- Update changed date of doc files
Signed-off-by: Jakson Alves de Aquino <jalvesaq@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org
diff --git a/runtime/syntax/r.vim b/runtime/syntax/r.vim
index 9b3754a..1932d24 100644
--- a/runtime/syntax/r.vim
+++ b/runtime/syntax/r.vim
@@ -5,7 +5,7 @@
" Tom Payne <tom@tompayne.org>
" Contributor: Johannes Ranke <jranke@uni-bremen.de>
" Homepage: https://github.com/jalvesaq/R-Vim-runtime
-" Last Change: Thu Nov 17, 2022 10:13PM
+" Last Change: Sun Dec 24, 2023 08:05AM
" Filenames: *.R *.r *.Rhistory *.Rt
"
" NOTE: The highlighting of R functions might be defined in
@@ -26,11 +26,7 @@
finish
endif
-if has("patch-7.4.1142")
- syn iskeyword @,48-57,_,.
-else
- setlocal iskeyword=@,48-57,_,.
-endif
+syn iskeyword @,48-57,_,.
" The variables g:r_hl_roxygen and g:r_syn_minlines were renamed on April 8, 2017.
if exists("g:r_hl_roxygen")
diff --git a/runtime/syntax/rmd.vim b/runtime/syntax/rmd.vim
index 93343dd..7b8b7fe 100644
--- a/runtime/syntax/rmd.vim
+++ b/runtime/syntax/rmd.vim
@@ -1,7 +1,7 @@
" Language: Markdown with chunks of R, Python and other languages
" Maintainer: Jakson Aquino <jalvesaq@gmail.com>
" Homepage: https://github.com/jalvesaq/R-Vim-runtime
-" Last Change: Wed May 17, 2023 06:34AM
+" Last Change: Sun Dec 24, 2023 07:21AM
"
" For highlighting pandoc extensions to markdown like citations and TeX and
" many other advanced features like folding of markdown sections, it is
@@ -16,6 +16,13 @@
let s:cpo_save = &cpo
set cpo&vim
+let g:rmd_include_latex = get(g:, 'rmd_include_latex', 1)
+if g:rmd_include_latex == 0 || g:rmd_include_latex == 1
+ let b:rmd_has_LaTeX = v:false
+elseif g:rmd_include_latex == 2
+ let b:rmd_has_LaTeX = v:true
+endif
+
" Highlight the header of the chunks as R code
let g:rmd_syn_hl_chunk = get(g:, 'rmd_syn_hl_chunk', 0)
@@ -136,7 +143,7 @@
let g:rmd_fenced_languages = get(g:, 'rmd_fenced_languages', ['r'])
let s:no_syntax_vim = []
-function IncludeLanguage(lng)
+function s:IncludeLanguage(lng)
if a:lng =~ '='
let ftpy = substitute(a:lng, '.*=', '', '')
let lnm = substitute(a:lng, '=.*', '', '')
@@ -171,11 +178,23 @@
endfunction
for s:type in g:rmd_fenced_languages
- call IncludeLanguage(s:type)
+ call s:IncludeLanguage(s:type)
endfor
unlet! s:type
-function CheckRmdFencedLanguages()
+let s:LaTeX_included = v:false
+function s:IncludeLaTeX()
+ let s:LaTeX_included = v:true
+ unlet! b:current_syntax
+ syn include @RmdLaTeX syntax/tex.vim
+ " From vim-pandoc-syntax
+ syn region rmdLaTeXInlineMath start=/\v\\@<!\$\S@=/ end=/\v\\@<!\$\d@!/ keepend contains=@RmdLaTeX
+ syn match rmdLaTeXCmd /\\[[:alpha:]]\+\(\({.\{-}}\)\=\(\[.\{-}\]\)\=\)*/ contains=@RmdLaTeX
+ syn region rmdLaTeX start='\$\$' end='\$\$' keepend contains=@RmdLaTeX
+ syn region rmdLaTeX start=/\\begin{\z(.\{-}\)}/ end=/\\end{\z1}/ keepend contains=@RmdLaTeX
+endfunction
+
+function s:CheckRmdFencedLanguages()
let alines = getline(1, '$')
call filter(alines, "v:val =~ '^```{'")
call map(alines, "substitute(v:val, '^```{', '', '')")
@@ -193,16 +212,31 @@
endfor
if has_lng == 0
let g:rmd_fenced_languages += [tpy]
- call IncludeLanguage(tpy)
+ call s:IncludeLanguage(tpy)
endif
endfor
+
+ if hlexists('pandocLaTeXCommand')
+ return
+ endif
+ if g:rmd_include_latex
+ if !b:rmd_has_LaTeX && (search('\$\$', 'wn') > 0 ||
+ \ search('\\begin{', 'wn') > 0) ||
+ \ search('\\[[:alpha:]]\+', 'wn') ||
+ \ search('\$[^\$]\+\$', 'wn')
+ let b:rmd_has_LaTeX = v:true
+ endif
+ if b:rmd_has_LaTeX && !s:LaTeX_included
+ call s:IncludeLaTeX()
+ endif
+ endif
endfunction
if g:rmd_dynamic_fenced_languages
- call CheckRmdFencedLanguages()
+ call s:CheckRmdFencedLanguages()
augroup RmdSyntax
autocmd!
- autocmd BufWritePost <buffer> call CheckRmdFencedLanguages()
+ autocmd BufWritePost <buffer> call s:CheckRmdFencedLanguages()
augroup END
endif
@@ -225,6 +259,8 @@
let &cpo = s:cpo_save
unlet s:cpo_save
+syntax iskeyword clear
+
let b:current_syntax = "rmd"
" vim: ts=8 sw=2