Domanda

I am trying to run a command from Emacs using ESS, to send code to the R buffer (though I have stumbled onto this problem in python as well).

I can't figure out though how to use:

(ess-send-string PROCESS STRING)

I do not understand how I can, while calling this function from the script buffer, send a string to the associated *R* buffer.

I have tried using comint and process-send-string, but I guess I do not understand how to send a process. A buffer name did not do it, what will?

Example:

(defun create-rtags () 
  (interactive)
  (ess-send-string PROCESS "rtags(ofile=paste0(getwd(), \"TAGS\"))")
È stato utile?

Soluzione

You can use get-process to have the right process or ess-get-process if you use the latest of ESS version on github.

(ess-send-string (get-process "R") "a <- 1:10;a")

Result in

[1]  1  2  3  4  5  6  7  8  9 10

So for your function, something like this should work

(defun create-rtags () 
  (interactive)
  (ess-send-string (get-process "R") "rtags(ofile = file.path(getwd(), \"TAGS\"))"))

Altri suggerimenti

To add to @dickoa answer. ESS handles multiple processes and they are all listed in ess-proces-name-list. "R" is the name of the first open R process. In ESS buffers there is local vairable ess-local-process-name which links the buffer with the process.

FWIW, C-c C-e C-t is bound to ess-build-tags-for-directory in ESS. It is smart enough to send rtags command from R buffers and a regexp etag request (based on current imenu regexp) from other buffers.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top