[ESS] Sweave indentation gotchas; do you see them too?
Paul Johnson
pauljohn32 at gmail.com
Thu May 20 18:05:22 CEST 2010
I'm running Emacs 23.1.1 on Ubuntu 10.04. The version of ess is 5.8.
I have a bunch of crap in my startup files (pasted below), but I get
the same trouble if I move those out of the way when I restart emacs.
I don' t know all of the magic Emacs words, so please be patient.
1. <<>> inside code scraps are mistakenly indented.
In Sweave, the << must be flush left. ESS knows that because you get
the automatically completed
<<>>=
@
only if cursor is far left.
However, If you start a code chunk and include another reference, it
gets indented, but should not.
<<other>>=
x <- rnorm(100)
@
<<what>>=
<<other>>
hist(x)
@
<<other>> needs to be flush left, otherwise job fails. However, ESS
wants to indent <<other>> by two spaces.
2. The indentation of items in a list or within a beamer frame is
"broken" by the insertion of scraps. Everything gets indented as
flush left after the scrap is done.
See what I mean? No indent after @.
\begin{frame}
\frametitle{Output Devices.}
\begin{itemize}
\item You make a nice plot and view it on the screen.
Send it to the default printer
<<eval=F,echo=T>>=
dev.print(paper="letter")
@
\item Gamble on a resizing of the image:
<<eval=F, echo=T>>=
dev.print(paper="letter", height=4, width=4)
@
\end{itemize}
\end{frame}
I've not used Emacs with Sweave and ESS very much before, and
certainly not on Beamer slides.
I noticed recently that items are not indented inside the itemize
environment, that seems to be a new-ish problem as well.
When I'm editing a file, Emacs automatically switches mode, between
LaTeX mode and ESS/R mode, depending on where the cursor is. That's
interesting. It has one bad effect, however. When I insert a " in
LaTeX mode, it creates a different character than an " in the ESS/R
mode. So it is not possible to copy and paste between R and LaTeX
without manually changing the ".
That is inconvenient.
pj
My .emacs file has:
==============================================================
$ cat .emacs
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(column-number-mode t)
'(cua-mode t nil (cua-base))
'(inhibit-startup-screen t)
'(show-paren-mode t)
'(text-mode-hook (quote (turn-on-auto-fill text-mode-hook-identify))))
(setq ess-fancy-comments nil)
(setq-default TeX-master nil)
(setq TeX-parse-self t)
(setq TeX-auto-save t)
(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"))
;; suggested by
;; http://www.terminally-incoherent.com/blog/2007/12/13/emacs-with-auctex-as-a-latex-ide/
;; Math mode for LaTex
(add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)
;; mouse scrolling
(mouse-wheel-mode t)
;; turns on flyspell
(add-hook 'text-mode-hook
(lambda () (flyspell-mode 1)))
;; spellcheck in LaTex mode
(add-hook `latex-mode-hook `flyspell-mode)
(add-hook `tex-mode-hook `flyspell-mode)
(add-hook `bibtex-mode-hook `flyspell-mode)
;; Show line-number and column-number in the mode line
(line-number-mode 1)
(column-number-mode 1)
=============================================================
And the only other non-default startup options are specified in my
custom ess file:
$ cat /etc/emacs/site-start.d/50emacs-ess-ku.el
;; -*-emacs-lisp-*-
;;
;; Emacs startup file for the Debian GNU/Linux ess package
;;
;; Originally contributed by Nils Naumann <naumann at unileoben.ac.at>
;; Modified by Dirk Eddelbuettel <edd at debian.org>
;; Adapted for dh-make by Jim Van Zandt <jrv at vanzandt.mv.com>
;;Set up emacs-ess for Emacs with other things we like at KU.
;;;;;
;;;;;; This file is automatically loaded by emacs's site-start.el
;;;;;; when you start a new emacs session.
;;;
;; Windows users may need to adjust this first line
;; if emacs can't find rterm.exe
;; (setq inferior-R-program-name "c:/progra~1/R/R-2.10/bin/Rterm.exe")
;; Yes, I know, windows guys don't like /, but use them.
;; Trying to find out if the progra~1 thing is needed inWin7
(setq use-file-dialog nil)
(require 'pc-select)
(pc-selection-mode)
(custom-set-variables
'(cua-mode t nil (cua-base))
'(show-paren-mode t)
'(text-mode-hook (quote (turn-on-auto-fill text-mode-hook-identify)))
'(transient-mark-mode t))
;;;
(setq inferior-ess-own-frame t)
(setq inferior-ess-same-window nil)
;;;
;;;;;create a new frame for each help instance
;;;
(setq ess-help-own-frame t)
;;;;;If you want all help
;;;;; buffers to go into one frame do:
;;;
(setq ess-help-own-frame 'one)
(setq ess-ask-for-ess-directory nil)
(setq ess-local-process-name "R")
(setq split-window-preferred-function nil)
(setq ansi-color-for-comint-mode 'filter)
(setq comint-prompt-read-only t)
(setq comint-scroll-to-bottom-on-input t)
(setq comint-scroll-to-bottom-on-output t)
(setq comint-move-point-for-output t)
(defun my-ess-eval ()
(interactive)
(if (and transient-mark-mode mark-active)
(call-interactively 'ess-eval-region)
(call-interactively 'ess-eval-line-and-step)))
(add-hook 'ess-mode-hook
'(lambda()
(local-set-key [(shift return)] 'my-ess-eval)))
--
Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas
More information about the ESS-help
mailing list