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

Support function highlighting not dependent on external plugin #21

Closed michaelmalick closed 7 years ago

michaelmalick commented 7 years ago

It appears the current behavior of the R syntax highlighting is to not highlight R function names unless an external plugin is installed. Because these are the runtime files distributed with vim, it seems to make sense to support the ability to highlight R function names that isn't dependent on an external plugin (i.e., either as the default behavior or by setting a variable). This is particularly true for those of us that don't use the Nvim-R plugin.

Highlighting text that precedes an open ( as a function in an R file seems like a reasonable starting point:

syn match rFunction '[0-9a-zA-Z_\.]\+\s*\ze('

The above regex would provide the highlighting of myfunction in myfunction() and when spaces are used prior to the (, e.g., myfunction ().

jalvesaq commented 7 years ago

My goal when highlighting functions is to let users know that the function was correctly spelled. However, you are right because what I am doing is not syntax highlight. It is more a reflex of loaded packages in R's workspace.

I added your code to syntax/r.vim in https://github.com/jalvesaq/R-Vim-runtime/tree/r_fun_pattern It is executed conditionally. The value of r_syntax_fun_pattern will be 0 if Nvim-R is installed and 1 otherwise, but it can be changed by users in the vimrc. If nobody complains in the next days, I will merge the code into the master branch.

michaelmalick commented 7 years ago

Awesome! Thanks for implementing this so quickly. I just tested it out and it appears to be working as intended on my end.