remacsorg-modeessnoweb

Emacs, R, Org-mode: how to enable automatic switch to ESS-mode within R code blocks?


When using R code chunks in an .Rnw document, the emacs buffer automatically detects that the cursor is within a code chunk (i.e. within <<>> and @), and switches to ESS-mode -- this is very valuable because one can get ESS-based code-formatting within the code-chunk, and more-usefully, one can send code lines/regions to the inferior *R* process-buffer.

How do I get the same functionality in an org-mode file within R code blocks (i.e. between #+begin_src R and #+end_src) -- I'd like emacs to automatically recognize it's within an R code code block, and turn on ESS-mode so I can send snippets of code to the *R* process. I am aware that I can do Ctl-C ' and switch to a different ESS-mode buffer where I can edit the code and get all the other ESS-mode conveniences (including sending code to R). However I'd like to not have to do this, i.e. I want to be able to send code-snippets from the R code block in the same org-mode buffer.


Solution

  • A year ago or so, I asked the same question on the org-mode-list. @cm2 has already mentioned, that it is not possible to use ESS functionality within org-mode; as far as I know Emacs cannot handle two major modes and even with mmm-mode there seem to be some difficulties.

    Dan Davison kindly posted some elisp-code which mimics some of the ESS features. So, you might want to check Dan's replies to my question.