[ESS] Code indentation inside an Sweave chunk
Martin Maechler
maechler at stat.math.ethz.ch
Tue Nov 28 15:01:25 CET 2006
>>>>> "StEgl" == Stephen Eglen <S.J.Eglen at damtp.cam.ac.uk>
>>>>> on Tue, 28 Nov 2006 10:54:18 +0000 writes:
>>
>> 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/
StEgl> Great, thanks. I now see the problem.
StEgl> In a regular foo.R file, RET is bound to newline-and-indent whereas
StEgl> in a code chunk of an Rnw buffer, RET is bound to noweb-newline which
StEgl> does not include any indent.
StEgl> --- From noweb-mode.el: -----------------------------------------------
StEgl> ;; For some reason that I do not understand, `newline' does not do the
StEgl> ;; right thing in quoted code. If point is not preceded by whitespace,
StEgl> ;; it moves to the beginning of the current line, not the beginning of
StEgl> ;; the new line. `newline 1' works fine, hence the kludge. I'd love to
StEgl> ;; understand what's going on, though. Try running M-x newline in the
StEgl> ;; middle of a code quote in a doc chunk to see
StEgl> ;; what I mean: its odd.
StEgl> (defun noweb-newline (&optional arg)
StEgl> "A kludge to get round very odd behaviour of newline in quoted code."
StEgl> (interactive "p")
StEgl> (if arg (newline arg) (newline 1)))
StEgl> ----------------------------------------------------------------------
StEgl> So, a simple fix in your case would be to add the following to the end
StEgl> of .emacs:
StEgl> (require 'noweb-mode)
StEgl> (defun noweb-newline (&optional arg)
StEgl> "A kludge to get round very odd behaviour of newline in quoted code."
StEgl> (interactive "p")
StEgl> (if arg (newline arg) (newline 1))
StEgl> (noweb-indent-line))
StEgl> BUT THIS IS A HACK!!! Someone who knows the noweb code better than me
StEgl> can probably advise what's best...
That must be Tony Rossoni (and noone else among ESS-core, since
he wrote 99% according to "svn"),
or then people listed here
;; Copyright (C) 1995 by Thorsten.Ohl @ Physik.TH-Darmstadt.de
;; with a little help from Norman Ramsey <norman at bellcore.com>
;; and Mark Lunt <mark.lunt at mrc-bsu.cam.ac.uk>
;; and A.J. Rossini <rossini at biostat.washington.edu>
though I doubt they still remember much details after 11 years,
and if they do, the problem may relate to an emacs bug from back
then which is no longer relevant today.
I'd like to encourage you to add the extra
(noweb-indent-line)
there; does seem harmless and provide desired functionality.
Martin
More information about the ESS-help
mailing list