eclipse-archived / ceylon.formatter

A formatter for the Ceylon programming language, written in Ceylon.
Apache License 2.0
14 stars 11 forks source link

Give NamedArgumentList’s { a preIndent #38

Open lucaswerkmeister opened 10 years ago

lucaswerkmeister commented 10 years ago

Formatter currently turns

1->"".join
    { for (value i in 1..spacesPerLevel) " " } // todo: check speed of " ".join("", "", ...) vs "".join(" ", " ", ...)

into

1->"".join
{ for (value i in 1..spacesPerLevel) " " } // todo: check speed of " ".join("", "", ...) vs "".join(" ", " ", ...)
lucaswerkmeister commented 9 years ago

Reverted by 20ec4bd32aae293ceb7ab0be1d0b08eceeae2971. Now that I see the above code, it’s doesn’t seem so stupid anymore… I’ll need to figure out something smarter.

lucaswerkmeister commented 9 years ago

Okay, so here’s something that I hope is smarter:

lucaswerkmeister commented 9 years ago

Formatter output:

Body
    {
    H2("Welcome to Ceylon!")
};

There are fully hierarchic forms composed exclusively of sequenced arguments. Dang.

lucaswerkmeister commented 9 years ago

So without peeking at the original line breaks (which I don’t want to do… it’s difficult to define an API for it, and it doesn’t work if we don’t have the original tokens), we simply cannot distinguish between

Body
{
    H2("Welcome to Ceylon!"),
    P("Now get your code on! \{SMILING FACE WITH SMILING EYES}")
}

and

sum
    { -1.0, for (i in 0:10) 1.0 / 2^i }

For now I’ll restore the previous state with indentBefore 1 (favors sum). I’ll add an option later to change that to 0 (favors Body).

lucaswerkmeister commented 9 years ago

Reopening and moving to next milestone for additional option.

lucaswerkmeister commented 9 years ago

By the way, a multi-line sum is actually nicely formatted as

sum
    { for (i in 1:100)
        if (i % 2 == 0)
            i };

because of the indentation of the opening brace, which still applies.

gavinking commented 9 years ago

Oh that is nice.

Sent from my iPhone

On 29 Sep 2014, at 8:23 pm, Lucas Werkmeister notifications@github.com wrote:

By the way, a multi-line sum is actually nicely formatted as

sum { for (i in 1:100) if (i % 2 == 0) i }; because of the indentation of the opening brace, which still applies.

— Reply to this email directly or view it on GitHub.