Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve support for \ff #94

Open
2 tasks
klmr opened this issue May 1, 2014 · 2 comments
Open
2 tasks

Improve support for \ff #94

klmr opened this issue May 1, 2014 · 2 comments
Labels

Comments

@klmr
Copy link

klmr commented May 1, 2014

I particularly like the </kbd>rf command to load a function and jump to the next. However, there are two issues with Vim-R’s implementation which means that I cannot use the feature to its full strength:

  1. Functions need to have a function body enclosed by { … }. Functions consisting of a single statement – e.g. id <- function (x) x – are not supported. This is a shame, since {s in R is unlike braces in C-like languages: they are literally just another R function which groups multiple expressions, and using single expressions unbraced is well in line with R’s functional philosophy.
  2. Functions need to be assigned with <-, using = does not work (the error message “The function assign operator <- was not found.” is displayed).

Both of these things should be fixed, i.e.

  • Support single-expression function bodies
  • Support function assignment via =.
@jalvesaq
Copy link

jalvesaq commented May 2, 2014

I agree that to be consistent with its name the plugin's function “SendFunctionToR” should be able to send single line functions and functions assigned via =. The algorithm used to find the function body is very simple:

  1. Look backwards for the string "function".
  2. Check if in the same line or in the previous line there is the string "<-".
  3. Find the opening brace.
  4. Find the closing brace.

In fact, to be perfect, the SendFunctionToR function should be more sophisticated than that, and it should deal with ->, <<- and ->>. However, I think that the trouble of making the required changes isn't worthwhile for some reasons:

  • There are already shortcuts to send a single line, be it a function or not: <LocalLeader>d and <LocalLeader>l. These shortcuts can be used to send single line functions.
  • The assignment operator that most people recommend to use is <-.
  • The plugin has a shortcut to make it easier to type " <- ", and this is what I use.

I'll replace the SendFunctionToR when I have a lot of spare time to rewrite it (may never happen), or when someone writes a patch improving it. In the meanwhile, we can let this issue open.

Note: The default command to send a function to R Console is <LocalLeader>ff.

@klmr
Copy link
Author

klmr commented May 2, 2014

The assignment operator that most people recommend to use is <-.

And that’s what I did as well, until fairly recently, but then I noticed that the arguments for using <- are actually quite poor, and there are at least two arguments against it (confuses new programmers because virtually every other mainstream language uses =; potentially introduces bugs, such as x < -5).

Note: The default command to send a function to R Console is <LocalLeader>ff.

Ah yeah, of course.

I’ll see whether I can contribute a patch some time; my Vim script skills are quite poor, unfortunately.

@jalvesaq jalvesaq changed the title Improve support for \rf Improve support for \ff May 2, 2014
@jalvesaq jalvesaq added the Bug label Nov 8, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants