[ESS] Code indentation inside an Sweave chunk
Stephen Eglen
S.J.Eglen at damtp.cam.ac.uk
Tue Nov 28 11:54:18 CET 2006
>
> The TAB does indent within a code chunk. I put up my dotemacs at this
> location in case you want to try it out:
>
> http://www.ling.uni-potsdam.de/~vasishth/temp/
Great, thanks. I now see the problem.
In a regular foo.R file, RET is bound to newline-and-indent whereas
in a code chunk of an Rnw buffer, RET is bound to noweb-newline which
does not include any indent.
--- From noweb-mode.el: -----------------------------------------------
;; For some reason that I do not understand, `newline' does not do the
;; right thing in quoted code. If point is not preceded by whitespace,
;; it moves to the beginning of the current line, not the beginning of
;; the new line. `newline 1' works fine, hence the kludge. I'd love to
;; understand what's going on, though. Try running M-x newline in the
;; middle of a code quote in a doc chunk to see
;; what I mean: its odd.
(defun noweb-newline (&optional arg)
"A kludge to get round very odd behaviour of newline in quoted code."
(interactive "p")
(if arg (newline arg) (newline 1)))
----------------------------------------------------------------------
So, a simple fix in your case would be to add the following to the end
of .emacs:
(require 'noweb-mode)
(defun noweb-newline (&optional arg)
"A kludge to get round very odd behaviour of newline in quoted code."
(interactive "p")
(if arg (newline arg) (newline 1))
(noweb-indent-line))
BUT THIS IS A HACK!!! Someone who knows the noweb code better than me
can probably advise what's best...
Stephen
More information about the ESS-help
mailing list