accelorator key for 'ESS - ESS Eval - Eval chunk'

A.J. Rossini rossini at blindglobe.net
Mon Dec 8 01:51:17 CET 2003


Stephen Eglen <stephen at inf.ed.ac.uk> writes:

> Hi,
>
>> When editing an Sweave (.Rnw) file, I can evaluate the current chunk
>> by clicking on 'ESS - ESS Eval - Eval chunk'.  Is there an
>> accelorator key that I can use to do this?  If not, can I add code
>> to my .xemacs file to create one?
>
> That's right, I think there is no accelerator, but something like the
> following should get you what you want (onto function key 5 here)
>
> (defun my-ess-hook ()
>   "Add my keybindings to ESS mode."
>   (local-set-key (kbd "<f5>") 'ess-eval-chunk))
> (add-hook 'ess-mode-hook 'my-ess-hook) 
>
>
>> As a follow-on issue, 'ESS - ESS Eval - Eval chunk' asks 'Process to
>> load into: R', something that I would like to avoid answering each
>> time I enter a new code chunk.  I asked about this before in
>> relation to submitting one line at a time (C-c C-n) and the code
>> solution suggested by Stephen Eglen works fine for C-c C-n.
>> https://stat.ethz.ch/pipermail/ess-help/2003-August/001529.html A
>> similar solution for 'ESS - ESS Eval - Eval chunk' would be ideal.
>
> Yes, I can repeat that behaviour with the latest ESS in Emacs 21.3.
> The relevant code shows the problem:
>
>
> (defun ess-eval-chunk (vis)
>   "Tangle the current chunk and send it to the inferior ESS process.
> Arg has same meaning as for `ess-eval-region'."
>   (interactive "P")
>   (let (( temp-buffer (ess-create-temp-buffer "Tangle Buffer")))
>     (noweb-tangle-chunk temp-buffer)
>     (set-buffer temp-buffer)
>     (ess-eval-region (point-min) (point-max) vis "Eval buffer")
>     (kill-buffer temp-buffer)))
>
> A new temp buffer is created to store the chunk, and then it is
> executed.  Every time you run ess-eval-chunk, you are asked to specify
> the process because the buffer local variable ess-local-process-name
> is not set in the temp buffer.  
>
> Here is a possible change to that defun, put this in your .emacs, restart:
>
> (defun ess-eval-chunk (vis)
>   "Tangle the current chunk and send it to the inferior ESS process.
> Arg has same meaning as for `ess-eval-region'."
>   (interactive "P")
>   (let ( (process-name ess-local-process-name)
> 	 (temp-buffer (ess-create-temp-buffer "Tangle Buffer")))
>     (noweb-tangle-chunk temp-buffer)
>     (set-buffer temp-buffer)
>     (set (make-local-variable 'ess-local-process-name) process-name)
>     (ess-eval-region (point-min) (point-max) vis "Eval buffer")
>     (kill-buffer temp-buffer)))
>
>
> Then, when you are in your .Rnw buffer, first try M-x ess-eval-line
> which should prompt you for the R process.  Confirm this by then
> doing "M-x describe-variable ess-local-process-name" (it should say
> "R").
>
> After that is set, you should then be able to run ess-eval-chunk, and
> it will use whatever process is stored in ess-local-process-name,
> rather than prompting you.  (If you don't run ess-eval-line, the
> ess-eval-chunk will not know what value of ess-local-process-name to
> use, and so will prompt you every time you run ess-eval-chunk, until
> ess-local-process-name is set).
>
> For ESS core: is this the right approach to take?

I think it is a good first pass; in particular, I think that most
(60%? more) will be using eval-line prior to running all chunks.  

(otherwise, if using it for writing Sweave files, one might consider
just using Sweave...).


> Also, if the value of ess-local-process-name in the .Rnw buffer is
> nil, after the chunk has been run, ess-local-process-name should have
> a value; should that value then be copied (inherited) back into the
> .Rnw buffer?

Yes, that does sound in-line with the others.  If you have time,
Stephen, please do and commit.

best,
-tony

-- 
rossini at u.washington.edu            http://www.analytics.washington.edu/ 
Biomedical and Health Informatics   University of Washington
Biostatistics, SCHARP/HVTN          Fred Hutchinson Cancer Research Center
UW (Tu/Th/F): 206-616-7630 FAX=206-543-3461 | Voicemail is unreliable
FHCRC  (M/W): 206-667-7025 FAX=206-667-4812 | use Email

CONFIDENTIALITY NOTICE: This e-mail message and any attachme...{{dropped}}




More information about the ESS-help mailing list