[ESS] Yet another indentation question: indentation after parenthese

Mathieu Basille basille at ase-research.org
Fri Dec 16 17:39:08 CET 2011


Dear Richard,

Thanks for your answer! I didn't know about the RRR style, which was not
described in the R manual at
http://cran.r-project.org/doc/manuals/R-ints.html#R-coding-standards
(!). It seems that RRR does what I want to do. And my problem seemed to
lie in 'ess-arg-function-offset', which indents the statements at
open-parenthesis if it is not set to a number.

However, to my surprise, using RRR style did not change anything to my
problem. I then tried with an empty .emacs (which should thus use the
default style, with 'ess-arg-function-offset' set to 2), and my problem
was still not solved. I also tried to manually set every indentation
variable ('ess-indent-level', 'ess-continued-statement-offset',
'ess-brace-offset', 'ess-arg-function-offset', 'ess-expression-offset',
'ess-else-offset', 'ess-close-brace-offset') to 4, and it did not change
anything either to this problem... Of course, I checked the value of the
style and each variable with 'C-h v', and they are set up as expected.
All the time, the indentation (with C-M-q or TAB) ends up at the
open-parenthesis.

I'm more lost than ever... Is there any reason that the indentation to
the open-parenthesis of 'ess-arg-function-offset' (if this is the
correct variable) would prevail against any user setting? Or am I
missing something again?

I deeply thank you for your efforts. I wanted to achieve what I thought
to be a simple task, i.e. using R formatting style as used by the R
parser, and I realise it is not so easy.

All the best,
Mathieu.


PS: If it is of any relevance, I have the same behaviour with ESS 5.14-1
(Debian Testing) and 5.11-1 (Debian Stable).



Le 16/12/2011 10:38, Richard M. Heiberger a écrit :
> Mathieu,
>  
> ESS has several options on indenting code.
> Please look at ess-style-alist in file ess-custom.el and then try the
> styles out.
> My guess is that style RRR is the one you are looking for.
> If you need something else, then you can probably figure out how to set
> the parameters
> for your needs.  When you have what you want, give it a name and send it
> to us for
> inclusion in the next release.
>  
> Rich
> 
> On Fri, Dec 16, 2011 at 9:01 AM, Mathieu Basille
> <basille at ase-research.org <mailto:basille at ase-research.org>> wrote:
> 
>     Le 16/12/2011 08:49, Vitalie Spinu a écrit :
>     > Mathieu Basille <basille at ase-research.org
>     <mailto:basille at ase-research.org>> writes:
>     >
>     >> Dear Vitalie,
>     >>
>     >> Thanks for you comment. My first message was not perfectly
>     clear... Your
>     >> example with 'foo' is misleading, since foo is exactly 3
>     character long.
>     >> Take this silly example instead:
>     >>
>     >> foo <- function(aaaaaaaaaa = 1, bbbbbbbbbb = 2, cccccccccc = 3,
>     >>                 dddddddddd = 4, eeeeeeeeee = 5)
>     >> {
>     >>     return(data.frame(aaaaaaaaaa, bbbbbbbbbb, cccccccccc, dddddddddd,
>     >>                       eeeeeeeeee))
>     >> }
>     >>
>     >> The new line formatted by ESS starts just after the opening
>     parenthesis.
>     >> If I save the file in bla.R and source it with 'keep.source =
>     FALSE' to
>     >> use the R parser, here is what I get:
>     >>
>     >>> options(keep.source = FALSE)
>     >>> source("bla.R")
>     >>> foo
>     >> function (aaaaaaaaaa = 1, bbbbbbbbbb = 2, cccccccccc = 3,
>     dddddddddd = 4,
>     >>     eeeeeeeeee = 5)
>     >> {
>     >>     return(data.frame(aaaaaaaaaa, bbbbbbbbbb, cccccccccc, dddddddddd,
>     >>         eeeeeeeeee))
>     >> }
>     >
>     > Ok, I got it. Check the keep.source option:
>     >
>     > options("keep.source")
>     >
>     > If it's FALSE I am getting your output and this is the problem of
>     R, ESS
>     > cannot easily help you here. In my setup  keep.source is T, so I am
>     > getting everything ok.
> 
>     It is OK from an ESS perspective only. From a R perspective, it is not.
>     The main problem is that R and ESS do not format code the same way, and
>     I'd like to use R formatting, not ESS. The 'keep.source' option is
>     usually set to TRUE, but is generally set to FALSE for packages (which
>     makes formatting of R code consistent). Using 'keep.source = TRUE' does
>     not format at all the code; what the user wrote is totally kept as-is.
>     Basically, I'd like to write code which follows the rules of R itself.
>     In my opinion, this is a problem of ESS, not R!
> 
>     Is there really no possibility to get the R behaviour here? What I
>     normally do is 1) write my functions, 2) source them using 'keep.source
>     = FALSE' to use the R parser, and 3) paste them back in my .R/Rnw file.
>     But this is messy since it then conflicts with ESS style (e.g. every
>     time I add a new line, or hit C-M-q, the formatting gets changed back to
>     ESS rules)...
> 
>     Thanks for your answer,
>     Mathieu.
> 
> 
>     > HTH,
>     > Vitalie.
>     >
>     >>
>     >> That is, the new line simply adds 4 spaces from the left margin (not
>     >> from the opening parenthesis, which, I agree, would make no
>     sense) and
>     >> do not start after the opening parenthesis. There is two reasons
>     I would
>     >> like to have this behaviour with ESS: 1) first, it would not
>     change the
>     >> formatting of my functions if I source them with the R parser,
>     and 2) it
>     >> can be a real source of nightmares when there are many nested
>     >> parentheses, and everything gets pushed to the right.
>     >>
>     >> All the best,
>     >> Mathieu.
>     >>
>     >> Le 16/12/2011 06:32, Vitalie Spinu a écrit :
>     >>> Mathieu Basille <basille at ase-research.org
>     <mailto:basille at ase-research.org>> writes:
>     >>>
>     >>>> Dear ESS gurus,
>     >>>>
>     >>>> I feel like I'm really missing something... I searched heavily
>     on the net, in
>     >>>> the ESS manual, on this list, without finding what I'm looking
>     >> for. Basically,
>     >>>> when I try to indent some code (with M-C-q), if a line break
>     occurs in the
>     >>>> middle of parentheses or brackets, the next line will be
>     indented to the
>     >> first
>     >>>> character after the parenthesis. How can I get rid of this, and
>     get a
>     >> normal' 4
>     >>>> spaces indentation? (this is, I think, the behaviour of the R
>     parser)
>     >>>>
>     >>>
>     >>> I am not really understanding that. You mean that
>     >>>
>     >>>
>     >>>     foo(arg1 = 1, arg2 = 2,
>     >>>         arg3 = 3)
>     >>>
>     >>> Is not what you want? and you would like:
>     >>>
>     >>>
>     >>>     foo(arg1 = 1, arg2 = 2,
>     >>>             arg3 = 3)
>     >>>
>     >>> instead?
>     >>>
>     >>> Doesn't make sense to me.
>     >>>
>     >>> Vitalie.
> 
>     --
> 
>     ~$ whoami
>     Mathieu Basille, Post-Doc
> 
>     ~$ locate
>     Laboratoire d'Écologie Comportementale et de Conservation de la Faune
>     + Centre d'Étude de la Forêt
>     Département de Biologie
>     Université Laval, Québec
> 
>     ~$ info
>     http://ase-research.org/basille
> 
>     ~$ fortune
>     ``If you can't win by reason, go for volume.''
>     Calvin, by Bill Watterson.
> 
>     ______________________________________________
>     ESS-help at r-project.org <mailto:ESS-help at r-project.org> mailing list
>     https://stat.ethz.ch/mailman/listinfo/ess-help
> 
> 

-- 

~$ whoami
Mathieu Basille, Post-Doc

~$ locate
Laboratoire d'Écologie Comportementale et de Conservation de la Faune
+ Centre d'Étude de la Forêt
Département de Biologie
Université Laval, Québec

~$ info
http://ase-research.org/basille

~$ fortune
``If you can't win by reason, go for volume.''
Calvin, by Bill Watterson.



More information about the ESS-help mailing list