[ESS] shortcut to send a multi-line expression?

Martin Maechler maechler at stat.math.ethz.ch
Fri Jul 27 11:11:07 CEST 2007


>>>>> "JB" == Jenny Bryan <jenny at stat.ubc.ca>
>>>>>     on Thu, 26 Jul 2007 13:41:26 -0700 writes:

    JB> Is there an ESS command to quickly send a multi-line
    JB> expression to the R process?  Without C-c C-n'ing your
    JB> way through all of them, i.e. stringing together many
    JB> ess-eval-line-and-step commands?

    JB> I know how to use C-c C-r (ess-eval-region) to to send a
    JB> region, but that is predicated on setting the point and
    JB> mark appropriately, which is a step I would love to
    JB> skip.  And I know how to use C-c C-f (ess-eval-function)
    JB> to send the function definition that contains point.

    JB> Is there something deserving the name
    JB> "ess-eval-expression-and-step" that says "please send
    JB> the syntactically complete multi-line command that
    JB> contains point and (maybe?) put point at the end of it"?

Hi Jenny,
as Ross just said, that does not exist and
the C-c C-c he mentioned is 
    ess-eval-function-or-paragraph-and-step
is not quite what you want
-- but it is still worth knowing and we have put it on C-c C-c 
for a good reason.

Now if we take your question rather as a feature
suggestion/request, it's a very interesting one, that we should
seriously consider.
It has all to do with how well defined the S Syntax is in ESS
and emacs.

Here are some R-code snippets, modified from example(plot.default),
to experiment with; single line and mult-line statements all
inside the same paragraph:

##----------------------------------------------------------
## From 'example(plot.default):

Speed <- cars$speed
Distance <- cars$dist
plot(Speed, Distance, panel.first = grid(8,8),
     pch = 0, cex = 1.2, col = "blue")
pp <- plot(Speed, Distance, panel.first = grid(8,8),
           pch = 0, cex = 1.2, col = "blue")
plot(Speed, Distance,
     panel.first = lines(lowess(Speed, Distance), lty = "dashed"),
     pch = 0, cex = 1.2, col = "blue")

##----------------------------------------------------------

I've tried a few things, using
  1)   ( forward|backward-sentence )  -- not ok: 'sentence' ~= 'paragraph'
      				     	for the S syntax
and 

  2)   ( forward|backward-sexp )     which is not quite enough
       			     	   
but looks like the basis for a function that at least should 
"work most of the time".
E.g., if we assumed that you are (well, rather your 'point' is) on
the first line of such a multiline statement,
it seems to me that it shouldn't be hard -- but take an hour or
two make such a function,
e.g. taking the current (defun ess-next-code-line .....)
as an example.

Interestingly the Lisp code for it has

----------------------------------------
;; Contributed by  Stephen Eglen <stephen at anc.ed.ac.uk> {idea from octave int.}
(defun ess-next-code-line (&optional arg)
.....................
----------------------------------------

and when I look at its history, I see

------------------------------------------------------------------------
r1271 | maechler | 2000-03-31 19:00:05 +0200 (Fri, 31 Mar 2000) | 2 lines
------------------------------------------------------------------------

which has been a while (I think) before Stephen has become a
full (and very active and proficient!) member of ESS-core.

    JB> Thanks, Jenny

Thank you, Jenny, for the interesting suggestion!
Martin




More information about the ESS-help mailing list