emacs-ess / ESS

Emacs Speaks Statistics: ESS
https://ess.r-project.org/
GNU General Public License v3.0
623 stars 162 forks source link

Rstudio Style Eval Function #1176

Open jsilve24 opened 2 years ago

jsilve24 commented 2 years ago

Loving ESS, one thing I miss from Rstudio is their DWIM-style eval bound to C-RET. Wondering if something like this already exists in ESS.

Notably, the Rstudio C-RET function evals an entire outer form (e.g., an entire for loop) if called from the line defining the form or the line containing the closing brace. If called form within the outer form on a simple line like f <- 9 it just evaluates the line. If called on a line with a pipe, it executes until the end of the piped sequence.

Any ideas? If something like this does not already exist, I could take a crack at implementing it.

lionel- commented 2 years ago

Evaluation is currently line-based, paragraph-based, selection-based, or defun-based. There has been some discussions about improving things in other issues (e.g. #51 and #52, there was some discussion about nested blocks in #251), but nothing concrete has emerged. A DWIM-style eval is dependent on workflow conceptions. I guess an RStudio replication would have the advantage of side-stepping UI discussions.

jsilve24 commented 2 years ago

Thanks for pointing to those issues.

When I have some time I will try to implement a draft of this function. At the very least I will put it in this issue so perhaps other may find it helpful in the future.

Thanks.

mmaechler commented 2 years ago

Evaluation is currently line-based, paragraph-based, selection-based, or defun-based.

the last one defun really meaning function in R-like languages. Note that even that is often failing when working inside a complex function body, notably when other local helper functions are defined inside that body.

The reason of this deficiency is really the deficiency of correctly finding "the beginning of the current function" in such cases. This has been an open bug #820 for three years now ... and I'd be really really grateful if that could be fixed (or at least be made to fail much less frequently).

jsilve24 commented 2 years ago

Interesting, thanks @mmaechler (when current grant is done :) I will try to build this function off of those beginning/end of function functions, perhaps I can track down the error.

lionel- commented 2 years ago

A great place to start working on this would be to add a comprehensive set of unit tests for beginning/end of functions.

These tests could use point and mark characters (¶ and ×) to check that the correct region is marked. See the documentation in https://github.com/emacs-ess/ESS/tree/master/test/etest. Here is an example usage: https://github.com/emacs-ess/ESS/blob/5ec55b95940ac63ef6209c76035a13d02a3248cd/test/ess-test-r.el#L238-L247.