jalvesaq / R-Vim-runtime

Vim runtime scripts of file types that include R code
GNU General Public License v2.0
24 stars 28 forks source link

don't warn about `[` missing a matching ] #41

Closed aavogt closed 1 year ago

aavogt commented 4 years ago

Code like this doesn't need a matching ]:

map_chr( `[`(2))

My change won't warn about this:

(
[
)

But I think nobody puts [ at the start of the line.

jalvesaq commented 4 years ago

Could you please post an example of code that will be better highlighted if your pull request is merged?

aavogt commented 4 years ago
c('data/b/c', 'data/b2/c') %>%
   strsplit('/') %>%
  map_chr( `[`(2) )

Screenshot_2020-04-04_13-24-19 Screenshot_2020-04-04_13-23-23

The problem is with .Rmd, not .R. I'm not sure what color the [ should be -- probably it should be the same as %>%. Anyways, the ) is what's annoying me, but fixing the [ might fix the ) too.

aavogt commented 4 years ago

The previous code marked the final ] in xs[[ length(xs) ]] as an error.

jalvesaq commented 4 years ago

The syntax/r.vim has some lines that are not evaluated if the filetype is rmd:

https://github.com/jalvesaq/R-Vim-runtime/blob/master/syntax/r.vim#L235-L239

and

https://github.com/jalvesaq/R-Vim-runtime/blob/master/syntax/r.vim#L311-L313

Could you, please, try removing the condition? That is, syntax/r.vim would be exactly the same for both r and rmd. I know that this will fix the issue, but does it create new problems? We have to try the changes for some time to be sure.

aavogt commented 4 years ago

I've settled on just adding

    syn match rFunction "`\[\+`"

With .Rmd it looks like:

image

But with .R, the https://github.com/jalvesaq/R-Vim-runtime/blob/master/syntax/r.vim#L311-L313 interferes, leading to: image

We can't have https://github.com/jalvesaq/R-Vim-runtime/blob/a9b6ac04a9aea0a369f5e52a9475c71e4ad6adf4/syntax/r.vim#L311-L313 enabled in .Rmd because code blocks start with ```, which matches that pattern. That leads to no highlighting at all.

Changing the pattern to exclude ```{ :

 syn region rNameWSpace start="`\(``{\)\@!" end="`" contains=rSpaceFun

makes Rmd highlighting look like .R

image

with

syn match rOperator    "[|!<>^~`/:]"

And slightly better:

image

except with

syn match rOperator    "[|!<>^~/:]"

Though perhaps the ``` be treated as before (brown/gold). But I can't figure that out. The best I can do is:

image

with

syn match rOperator "```"
jalvesaq commented 4 years ago

It is preferable if the vim script to highlight R code is exactly the same in .R and .Rmd files. So, could you check the branch rmd_backtick, please? I deleted the "rmd" condition from syntax/r.vim and the chunk highlighting is still normal to me, as you can see in the image below:

image

jalvesaq commented 1 year ago

Sorry for taking so long to look at this carefully.