2

I'm new to Emacs, and am trying to learn it for knitting LaTeX and R (using AUCTeX and ESS). In my ~/.emacs I have:

(setq-default TeX-newline-function 'reindent-then-newline-and-indent)

which means that when I press RET AUCTeX applies the proper LaTeX indentation automatically for me. However, in an .Rnw file it seems that ESS overrides the TeX-newline. In an .Rnw file C-h m returns:

RET     TeX-newline
(that binding is currently shadowed by another mode)

and C-h k RET returns:

RET (translated from <return>) runs the command ess-noweb-newline,
which is an interactive compiled Lisp function in `ess-noweb-mode.el'.

It is bound to RET.

(ess-noweb-newline &optional ARG)

A kludge to get round very odd behaviour of newline in quoted code.

Basically I only want ESS to override RET when the point is inside an R chunk (<<>> @) or the brackets of an \Sexpr{} expression. Seems to me that this should be the default behaviour, but is there any way to force it?

1

I worked this one out, you need to use polymode. After installing polymode (I added the MELPA repository for that), you then set up whatever polymode bits you need in your ~/.emacs file. This is what I had to put for .Rnw support:

; enable polymode stuff
(require 'poly-R)
(require 'poly-markdown)
(require 'poly-noweb)
; add .Rnw filetype
(add-to-list 'auto-mode-alist '("\\.Rnw" . poly-noweb+r-mode))

With that you get everything working as it should be for LaTeX and R sections of the code. In .Rnw files RET works correctly, and syntax highlighting is more accurate too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.