[ESS] Code indentation inside an Sweave chunk

Stephen Eglen S.J.Eglen at damtp.cam.ac.uk
Mon Nov 27 14:08:03 CET 2006


 > In Emacs+ESS, code files with the extension .R are auto-formatted, which
 > makes everything much more readable; e.g., if I hit enter after starting a
 > for loop, I get a nicely indented new line. However, this does not happen
 > when I write a code chunk inside an .Rnw document. How can I get auto
 > indenting inside a
 > 
 > <<>>=
 > 
 > @
 > 
 > escape sequence?

I have the following in my .emacs, does that work for you?

Stephen

(defun Rnw-mode ()
  (require 'ess-noweb)
  (noweb-mode)
  (if (fboundp 'R-mode)
      (setq noweb-default-code-mode 'R-mode)))
(add-to-list 'auto-mode-alist '("\\.Rnw\\'" . Rnw-mode))
(add-to-list 'auto-mode-alist '("\\.Snw\\'" . Rnw-mode))

(setq reftex-file-extensions
      '(("Snw" "Rnw" "nw" "tex" ".tex" ".ltx") ("bib" ".bib")))
(setq TeX-file-extensions
      '("Snw" "Rnw" "nw" "tex" "sty" "cls" "ltx" "texi" "texinfo"))




More information about the ESS-help mailing list