4

Q: how can I automatically copy output from ess to the kill ring?

Background

I use ess to conduct statistical analysis. On occasion, I need to copy its raw output into another buffer (usually something like the raw output from xtable to a .tex file).

Doing it by hand

Right now, after I send code to the running process, I have to:

  1. switch to the output buffer
  2. manually mark the relevant output
  3. copy to the kill ring
  4. move on with my day

That's laborious, error prone, and breaks my train of thought. Boo hiss.

Can I do it automatically?

How can I automate the first three steps?

I want to send code to the running process (R, in my case) and copy the output to the kill ring. Does this functionality already exist in ess?

Related posts

(I could probably adapt the answer in this post if necessary, but I don't want to reinvent the wheel.)

Dan
  • 32,584
  • 6
  • 98
  • 168

1 Answers1

2

Maybe not as elegant as what you want, but there are functions for each step in your workflow:

  1. ess-switch-to-inferior-or-script-buffer, C-c C-z
  2. set-mark, C-<space>
  3. comint-previous-prompt, C-c C-p
  4. kill-ring-save, M-w
  5. ess-switch-to-inferior-or-script-buffer, C-c C-z

The elisp version would be:

(defun kill-last-output ()
  (interactive)
  (save-window-excursion
    (ess-switch-to-ESS t)
    (push-mark)
    (comint-previous-prompt 1)
    (kill-ring-save (region-beginning) (region-end))))
Tyler
  • 21,719
  • 1
  • 52
  • 92