[ESS] Indentation questions
Andreas Leha
andreas.leha at med.uni-goettingen.de
Tue Nov 4 22:54:42 CET 2014
Hi all,
Ista Zahn <istazahn at gmail.com> writes:
> Hi again,
>
> In the light of day I see my post from last night was rambling and
> probably not clear or easy to answer. Sorry about that.
>
> After sleeping on it I've got most of what I want with the following settings:
>
> (setq ess-first-continued-statement-offset 2)
> (setq ess-continued-statement-offset 0)
> (setq ess-arg-function-offset-new-line 0)
> (setq ess-arg-function-offset nil)
>
> The final thing that I can't seem to nail down is this: I would really
> like both "2's" in the following to be indented to the same level:
>
> 1 +
> mean(rnorm(100), na.rm=TRUE) +
> 2 +
> mean(rnorm(100),
> na.rm=TRUE) +
> 2
>
> I really don't see what relevance putting the second argument to
> "mean" on a separate line has for the way the subsequent continuation
> line should be indented. Please, if you know how to get this to indent
> as
>
> 1 +
> mean(rnorm(100), na.rm=TRUE) +
> 2 +
> mean(rnorm(100),
> na.rm=TRUE) +
> 2
>
> I would be very grateful.
Me too. Thanks for asking this.
Andreas
>
> Thanks,
> Ista
>
> On Mon, Nov 3, 2014 at 10:36 PM, Ista Zahn <istazahn at gmail.com> wrote:
>> Hi all,
>>
>> I've been unhappy with ESS indention for some time, and finally got
>> around to trying to adjust it to my taste. It didn't go well, and so
>> I'm turning to the collective wisdom of this list for help. NOTE: this is
>> a long post, due mostly to my inability to state my issue clearly. A shorter
>> version is at https://github.com/emacs-ess/ESS/issues/120
>>
>> OK, here goes; basically I like how Rstudio
>> indents things, which mostly means lining up things up by reference to
>> the calling function. Here are some examples (these examples also
>> available at http://pastebin.com/y7UERhv6 in case your email client
>> doesn't like to use a fixed-width font):
>>
>> #Rstudio:
>> mean(rnorm(100,
>> mean = runif(1,
>> 1,
>> 10)),
>> na.rm=TRUE
>> )
>>
>> # ESS
>> mean(rnorm(100,
>> mean = runif(1,
>> 1,
>> 10)),
>> na.rm=TRUE
>> )
>>
>> The Rstudio version makes it easy to see which lines are arguments to
>> which functions, and I'd like to set ESS to use a similar indentation
>> style. I've fiddled with all the ess.*offset variables I can find, but
>> I can't seem to find a satisfactory setting.
>>
>> The biggest annoyance is the indentation of continuation lines. There
>> have been several posts about this including
>> http://emacs.1067599.n5.nabble.com/indentation-of-ggplot-code-and-ess-13-09-02-td322315.html
>> which suggests the following setting:
>>
>> (add-to-list 'ess-style-alist
>> '(my-style
>> (ess-indent-level . 4)
>> (ess-first-continued-statement-offset . 2)
>> (ess-continued-statement-offset . 0)
>> (ess-brace-offset . -4)
>> (ess-expression-offset . 4)
>> (ess-else-offset . 0)
>> (ess-close-brace-offset . 0)
>> (ess-brace-imaginary-offset . 0)
>> (ess-continued-brace-offset . 0)
>> (ess-arg-function-offset . 4)
>> (ess-arg-function-offset-new-line . '(4))
>> ))
>>
>>
>> This does improve simple examples such as turning this:
>>
>> 1 +
>> 2 +
>> 3 +
>> 4
>>
>> into
>>
>> 1 +
>> 2 +
>> 3 +
>> 4
>>
>> though I would really like
>>
>> 1 +
>> 2 +
>> 3 +
>> 4
>>
>> But it still leave more complicated things like
>>
>> mean(rnorm(100)) +
>> 2 +
>> mean(rnorm(100,
>> mean = runif(1, 1, 10)), na.rm=TRUE) +
>> 2 +
>> 2
>>
>> I really don't understand why it makes sense to indent the "2's"
>> differently depending on whether they come before or after the second
>> "mean(rnorm(...". Compare this to the Rstudio indentation:
>>
>> mean(rnorm(100)) +
>> 2 +
>> mean(rnorm(100,
>> mean = runif(1, 1, 10)), na.rm=TRUE) +
>> 2 +
>> 2
>>
>> Right. So I hate to be that guy, but seriously, how can I make ESS
>> indentation behave more like Rstudio?
>>
>> Thanks,
>> Ista
>
> ______________________________________________
> ESS-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/ess-help
More information about the ESS-help
mailing list