Skip to content

Commit 9042bd8

Browse files
authored
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
1 parent 377372e commit 9042bd8

7 files changed

Lines changed: 108 additions & 62 deletions

File tree

runtime/doc/filetype.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*filetype.txt* For Vim version 9.0. Last change: 2023 Dec 05
1+
*filetype.txt* For Vim version 9.0. Last change: 2023 Dec 23
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -779,6 +779,14 @@ To enable this behavior, set the following variable in your vimrc: >
779779
let g:rst_style = 1
780780
781781
782+
RNOWEB *ft-rnoweb-plugin*
783+
784+
The 'formatexpr' option is set dynamically with different values for R code
785+
and for LaTeX code. If you prefer that 'formatexpr' is not set, add to your
786+
|vimrc|: >
787+
let rnw_dynamic_comments = 0
788+
789+
782790
RPM SPEC *ft-spec-plugin*
783791

784792
Since the text for this plugin is rather long it has been put in a separate

runtime/doc/indent.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*indent.txt* For Vim version 9.0. Last change: 2023 Dec 09
1+
*indent.txt* For Vim version 9.0. Last change: 2023 Dec 23
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1040,8 +1040,8 @@ r_indent_comment_column, as in the example below:
10401040
let r_indent_comment_column = 30
10411041
<
10421042
Any code after a line that ends with "<-" is indented. Emacs/ESS does not
1043-
indent the code if it is a top level function. If you prefer that the
1044-
Vim-R-plugin behaves like Emacs/ESS in this regard, put in your |vimrc|:
1043+
indent the code if it is a top-level function. If you prefer a behavior like
1044+
Emacs/ESS one in this regard, put in your |vimrc|:
10451045
>
10461046
let r_indent_ess_compatible = 1
10471047
<

runtime/doc/syntax.txt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*syntax.txt* For Vim version 9.0. Last change: 2023 Dec 20
1+
*syntax.txt* For Vim version 9.0. Last change: 2023 Dec 23
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -2842,10 +2842,20 @@ To highlight R code in knitr chunk headers: >
28422842
let rmd_syn_hl_chunk = 1
28432843
28442844
By default, chunks of R code will be highlighted following the rules of R
2845-
language. If you want proper syntax highlighting of chunks of other languages,
2846-
you should add them to either `markdown_fenced_languages` or
2847-
`rmd_fenced_languages`. For example to properly highlight both R and Python,
2848-
you may add this to your |vimrc|: >
2845+
language. Moreover, whenever the buffer is saved, Vim scans the buffer and
2846+
highlights other languages if they are present in new chunks. LaTeX code also
2847+
is automatically recognized and highlighted when the buffer is saved. This
2848+
behavior can be controlled with the variables `rmd_dynamic_fenced_languages`,
2849+
and `rmd_include_latex` whose valid values are: >
2850+
let rmd_dynamic_fenced_languages = 0 " No autodetection of languages
2851+
let rmd_dynamic_fenced_languages = 1 " Autodetection of languages
2852+
let rmd_include_latex = 0 " Don't highlight LaTeX code
2853+
let rmd_include_latex = 1 " Autodetect LaTeX code
2854+
let rmd_include_latex = 2 " Always include LaTeX highlighting
2855+
2856+
If the value of `rmd_dynamic_fenced_languages` is 0, you still can set the
2857+
list of languages whose chunks of code should be properly highlighted, as in
2858+
the example: >
28492859
let rmd_fenced_languages = ['r', 'python']
28502860
28512861

runtime/doc/tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7302,6 +7302,7 @@ ft-rego-syntax syntax.txt /*ft-rego-syntax*
73027302
ft-rexx-syntax syntax.txt /*ft-rexx-syntax*
73037303
ft-rmd-plugin filetype.txt /*ft-rmd-plugin*
73047304
ft-rmd-syntax syntax.txt /*ft-rmd-syntax*
7305+
ft-rnoweb-plugin filetype.txt /*ft-rnoweb-plugin*
73057306
ft-rrst-plugin filetype.txt /*ft-rrst-plugin*
73067307
ft-rrst-syntax syntax.txt /*ft-rrst-syntax*
73077308
ft-rst-plugin filetype.txt /*ft-rst-plugin*

runtime/indent/r.vim

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
" Language: R
33
" Author: Jakson Alves de Aquino <jalvesaq@gmail.com>
44
" Homepage: https://github.com/jalvesaq/R-Vim-runtime
5-
" Last Change: Mon Feb 27, 2023 07:16PM
5+
" Last Change: Sun Oct 08, 2023 10:45AM
66

77

88
" Only load this indent file when no other was loaded.
@@ -13,6 +13,7 @@ let b:did_indent = 1
1313

1414
setlocal indentkeys=0{,0},:,!^F,o,O,e
1515
setlocal indentexpr=GetRIndent()
16+
setlocal autoindent
1617

1718
let b:undo_indent = "setl inde< indk<"
1819

@@ -47,27 +48,23 @@ function s:RDelete_quotes(line)
4748
if a:line[i] == '"'
4849
let i += 1
4950
endif
50-
else
51+
elseif a:line[i] == "'"
52+
let i += 1
53+
let line1 = line1 . 's'
54+
while !(a:line[i] == "'" && ((i > 1 && a:line[i-1] == '\' && a:line[i-2] == '\') || a:line[i-1] != '\')) && i < llen
55+
let i += 1
56+
endwhile
5157
if a:line[i] == "'"
5258
let i += 1
53-
let line1 = line1 . 's'
54-
while !(a:line[i] == "'" && ((i > 1 && a:line[i-1] == '\' && a:line[i-2] == '\') || a:line[i-1] != '\')) && i < llen
55-
let i += 1
56-
endwhile
57-
if a:line[i] == "'"
58-
let i += 1
59-
endif
60-
else
61-
if a:line[i] == "`"
62-
let i += 1
63-
let line1 = line1 . 's'
64-
while a:line[i] != "`" && i < llen
65-
let i += 1
66-
endwhile
67-
if a:line[i] == "`"
68-
let i += 1
69-
endif
70-
endif
59+
endif
60+
elseif a:line[i] == "`"
61+
let i += 1
62+
let line1 = line1 . 's'
63+
while a:line[i] != "`" && i < llen
64+
let i += 1
65+
endwhile
66+
if a:line[i] == "`"
67+
let i += 1
7168
endif
7269
endif
7370
if i == llen
@@ -97,10 +94,8 @@ function s:RDelete_parens(line)
9794
let i += 1
9895
if a:line[i] == ')'
9996
let nop -= 1
100-
else
101-
if a:line[i] == '('
102-
let nop += 1
103-
endif
97+
elseif a:line[i] == '('
98+
let nop += 1
10499
endif
105100
endwhile
106101
let line1 = line1 . a:line[i]
@@ -174,10 +169,8 @@ function s:Get_last_paren_idx(line, o, c, pb)
174169
if blc == 0
175170
let theidx = idx
176171
endif
177-
else
178-
if line[idx] == a:c
179-
let blc += 1
180-
endif
172+
elseif line[idx] == a:c
173+
let blc += 1
181174
endif
182175
let idx += 1
183176
endwhile
@@ -316,6 +309,11 @@ function GetRIndent()
316309
endif
317310

318311
if pb < 0 && line =~ '.*[,&|\-\*+<>]$'
312+
if line =~ '.*[\-\*+>]$'
313+
let is_op = v:true
314+
else
315+
let is_op = v:false
316+
endif
319317
let lnum = s:Get_prev_line(lnum)
320318
while pb < 1 && lnum > 0
321319
let line = SanitizeRLine(getline(lnum))
@@ -324,9 +322,10 @@ function GetRIndent()
324322
while ind > 0
325323
if line[ind] == ')'
326324
let pb -= 1
327-
else
328-
if line[ind] == '('
329-
let pb += 1
325+
elseif line[ind] == '('
326+
let pb += 1
327+
if is_op && pb == 0
328+
return indent(lnum)
330329
endif
331330
endif
332331
if pb == 1
@@ -367,10 +366,8 @@ function GetRIndent()
367366
else
368367
return indent(lnum) + shiftwidth()
369368
endif
370-
else
371-
if substitute(oline, '#.*', '', '') =~ g:r_indent_op_pattern && s:Get_paren_balance(line, "(", ")") == 0
372-
return indent(lnum) - shiftwidth()
373-
endif
369+
elseif substitute(oline, '#.*', '', '') =~ g:r_indent_op_pattern && s:Get_paren_balance(line, "(", ")") == 0
370+
return indent(lnum) - shiftwidth()
374371
endif
375372
elseif substitute(line, '#.*', '', '') =~ g:r_indent_op_pattern && s:Get_paren_balance(line, "(", ")") == 0
376373
return indent(lnum) + shiftwidth()
@@ -404,12 +401,10 @@ function GetRIndent()
404401
if cline =~ '^\s*else'
405402
if line =~ '<-\s*if\s*()'
406403
return indent(lnum) + shiftwidth()
404+
elseif line =~ '\<if\s*()'
405+
return indent(lnum)
407406
else
408-
if line =~ '\<if\s*()'
409-
return indent(lnum)
410-
else
411-
return indent(lnum) - shiftwidth()
412-
endif
407+
return indent(lnum) - shiftwidth()
413408
endif
414409
endif
415410

runtime/syntax/r.vim

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
" Tom Payne <tom@tompayne.org>
66
" Contributor: Johannes Ranke <jranke@uni-bremen.de>
77
" Homepage: https://github.com/jalvesaq/R-Vim-runtime
8-
" Last Change: Thu Nov 17, 2022 10:13PM
8+
" Last Change: Sun Dec 24, 2023 08:05AM
99
" Filenames: *.R *.r *.Rhistory *.Rt
1010
"
1111
" NOTE: The highlighting of R functions might be defined in
@@ -26,11 +26,7 @@ if exists("b:current_syntax")
2626
finish
2727
endif
2828

29-
if has("patch-7.4.1142")
30-
syn iskeyword @,48-57,_,.
31-
else
32-
setlocal iskeyword=@,48-57,_,.
33-
endif
29+
syn iskeyword @,48-57,_,.
3430

3531
" The variables g:r_hl_roxygen and g:r_syn_minlines were renamed on April 8, 2017.
3632
if exists("g:r_hl_roxygen")

runtime/syntax/rmd.vim

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" Language: Markdown with chunks of R, Python and other languages
22
" Maintainer: Jakson Aquino <jalvesaq@gmail.com>
33
" Homepage: https://github.com/jalvesaq/R-Vim-runtime
4-
" Last Change: Wed May 17, 2023 06:34AM
4+
" Last Change: Sun Dec 24, 2023 07:21AM
55
"
66
" For highlighting pandoc extensions to markdown like citations and TeX and
77
" many other advanced features like folding of markdown sections, it is
@@ -16,6 +16,13 @@ endif
1616
let s:cpo_save = &cpo
1717
set cpo&vim
1818

19+
let g:rmd_include_latex = get(g:, 'rmd_include_latex', 1)
20+
if g:rmd_include_latex == 0 || g:rmd_include_latex == 1
21+
let b:rmd_has_LaTeX = v:false
22+
elseif g:rmd_include_latex == 2
23+
let b:rmd_has_LaTeX = v:true
24+
endif
25+
1926
" Highlight the header of the chunks as R code
2027
let g:rmd_syn_hl_chunk = get(g:, 'rmd_syn_hl_chunk', 0)
2128

@@ -136,7 +143,7 @@ syn match knitrBodyVar '| \zs\S\{-}\ze:' contained containedin=knitrBodyOptions
136143
let g:rmd_fenced_languages = get(g:, 'rmd_fenced_languages', ['r'])
137144

138145
let s:no_syntax_vim = []
139-
function IncludeLanguage(lng)
146+
function s:IncludeLanguage(lng)
140147
if a:lng =~ '='
141148
let ftpy = substitute(a:lng, '.*=', '', '')
142149
let lnm = substitute(a:lng, '=.*', '', '')
@@ -171,11 +178,23 @@ function IncludeLanguage(lng)
171178
endfunction
172179

173180
for s:type in g:rmd_fenced_languages
174-
call IncludeLanguage(s:type)
181+
call s:IncludeLanguage(s:type)
175182
endfor
176183
unlet! s:type
177184

178-
function CheckRmdFencedLanguages()
185+
let s:LaTeX_included = v:false
186+
function s:IncludeLaTeX()
187+
let s:LaTeX_included = v:true
188+
unlet! b:current_syntax
189+
syn include @RmdLaTeX syntax/tex.vim
190+
" From vim-pandoc-syntax
191+
syn region rmdLaTeXInlineMath start=/\v\\@<!\$\S@=/ end=/\v\\@<!\$\d@!/ keepend contains=@RmdLaTeX
192+
syn match rmdLaTeXCmd /\\[[:alpha:]]\+\(\({.\{-}}\)\=\(\[.\{-}\]\)\=\)*/ contains=@RmdLaTeX
193+
syn region rmdLaTeX start='\$\$' end='\$\$' keepend contains=@RmdLaTeX
194+
syn region rmdLaTeX start=/\\begin{\z(.\{-}\)}/ end=/\\end{\z1}/ keepend contains=@RmdLaTeX
195+
endfunction
196+
197+
function s:CheckRmdFencedLanguages()
179198
let alines = getline(1, '$')
180199
call filter(alines, "v:val =~ '^```{'")
181200
call map(alines, "substitute(v:val, '^```{', '', '')")
@@ -193,16 +212,31 @@ function CheckRmdFencedLanguages()
193212
endfor
194213
if has_lng == 0
195214
let g:rmd_fenced_languages += [tpy]
196-
call IncludeLanguage(tpy)
215+
call s:IncludeLanguage(tpy)
197216
endif
198217
endfor
218+
219+
if hlexists('pandocLaTeXCommand')
220+
return
221+
endif
222+
if g:rmd_include_latex
223+
if !b:rmd_has_LaTeX && (search('\$\$', 'wn') > 0 ||
224+
\ search('\\begin{', 'wn') > 0) ||
225+
\ search('\\[[:alpha:]]\+', 'wn') ||
226+
\ search('\$[^\$]\+\$', 'wn')
227+
let b:rmd_has_LaTeX = v:true
228+
endif
229+
if b:rmd_has_LaTeX && !s:LaTeX_included
230+
call s:IncludeLaTeX()
231+
endif
232+
endif
199233
endfunction
200234

201235
if g:rmd_dynamic_fenced_languages
202-
call CheckRmdFencedLanguages()
236+
call s:CheckRmdFencedLanguages()
203237
augroup RmdSyntax
204238
autocmd!
205-
autocmd BufWritePost <buffer> call CheckRmdFencedLanguages()
239+
autocmd BufWritePost <buffer> call s:CheckRmdFencedLanguages()
206240
augroup END
207241
endif
208242

@@ -225,6 +259,8 @@ unlet s:save_pandoc_lngs
225259
let &cpo = s:cpo_save
226260
unlet s:cpo_save
227261

262+
syntax iskeyword clear
263+
228264
let b:current_syntax = "rmd"
229265

230266
" vim: ts=8 sw=2

0 commit comments

Comments
 (0)