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

Stephen Eglen stephen at
Sun Dec 7 17:56:10 CET 2003


> 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.
> 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

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?

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?


More information about the ESS-help mailing list