[R] [ESS] Indentation in R code

Göran Broström gb at stat.umu.se
Tue Sep 27 21:58:45 CEST 2005


On Mon, Sep 26, 2005 at 07:05:33PM +0200, Göran Broström wrote:
> On Mon, Sep 26, 2005 at 09:27:56AM +0200, Martin Maechler wrote:
> > I'm crossposting to the ESS-help mailing list which is slightly
> > more appropriate here.  [This may be a rare case where
> > crossposting seems to make much sense.]
> > 
> > >>>>> "PD" == Peter Dalgaard <p.dalgaard at biostat.ku.dk>
> > >>>>>     on 25 Sep 2005 19:40:45 +0200 writes:
> > 
> >     PD> Seth Falcon <sfalcon at fhcrc.org> writes:
> > 
> >     >> On 24 Sep 2005, goran.brostrom at gmail.com wrote:
> >     >> 
> >     >> > I am using emacs-21.3 when writing R functions on Linux debian, and
> >     >> > I am trying to follow the advice i R-exts.pdf (2.1.1) regarding
> >     >> > indentation. That is, I set 'c-default-style' to "bsd" and
> >     >> > 'c-basic-offset' to 4. However, while this gives me the intended
> >     >> > indentation in C code, it doesn't change the behavior in R code; I
> >     >> > still get an indentation of size 2. This is my .emacs file after
> >     >> > customization:
> >     >> >
> >     >> > (require 'ess-site)
> >     >> > (custom-set-variables
> >     >> >  ;; custom-set-variables was added by Custom -- don't edit or
> >     >> >  ;; cut/paste it!  Your init file should contain only one such
> >     >> >  ;; instance.
> >     >> >  '(c-basic-offset 4)
> >     >> >  '(c-default-style "bsd"))
> >     >> >  (custom-set-faces
> >     >> >  ;; custom-set-faces was added by Custom -- don't edit or cut/paste it!
> >     >> >  ;; Your init file should contain only one such instance.
> >     >> > )
> >     >> 
> >     >> Not sure if this is the best way, but I have the following after
> >     >> loading ess-site:
> >     >> 
> >     >> (setq ess-indent-level 4)
> > 
> > 
> > 
> >     PD> I have (I believe it stems from Martin M. originally):
> > 
> > yes, most probably  {IIRC, Kurt Hornik was involved too}.
> > 
> >     PD>      (add-hook 'c-mode-hook '(lambda()
> >     PD> 			       (c-set-style "stroustrup")))
> > 
> > the above is not quite what I have or did recommend, 
> > which is rather  "bsd" + "offset 4"  as Göran has above
> > 
> > In fact, Göran mentions the "R-exts" manual and that has
> > the following  *before* giving the emacs-lisp statements:
> > 
> > >> (For GNU Emacs 20: for GNU Emacs 21 use
> > >> customization to set the `c-default-style' to `"bsd"' and
> > >> `c-basic-offset' to `4'.)
> > 
> > and indeed, that's what Göran did and you should do with a
> > current emacs, either customize via GUI or,
> > in your ~/.emacs file, find the section '(custom-set-variables ...)' and add 
> >  '(c-basic-offset 4)
> >  '(c-default-style "bsd")
> > 
> > to the lines already there, or if there's no such section, add
> > 
> > (custom-set-variables
> >   ;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
> >   ;; Your init file should contain only one such instance.
> >  '(c-basic-offset 4)
> >  '(c-default-style "bsd")


> > to the end of your ~/.emacs file
> [...]
> 
> but this is not sufficient to get correct (4) indentation (ess) in R 
> functions. We need some reference to ess as well, right? Maybe another
> reference to the ESS manual is in order in 'R-exts'?

Martin, I realize that it was stupid of me to cut here; I only refer to C
indentation, and forget that the lines of lisp code referring to ESS of 
course is necessary to get indentation working in R functions.

Once again, thanks for your good help.

Göran




More information about the R-help mailing list