Open lucaswerkmeister opened 10 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.
Okay, so here’s something that I hope is smarter:
If there are named arguments, the opening brace has no indentBefore
, and may follow 0 or 1 line breaks: You may write either
Html {
doctype = html5;
Head { title = "Ceylon home page"; };
Body {
H2("Welcome to Ceylon!")
};
}
or
Html
{
doctype = html5;
Head { title = "Ceylon home page"; };
Body
{
H2("Welcome to Ceylon!")
};
}
Note the inline Head
! We still want to allow that – even with multiple short arguments it can look good – so we won’t enforce line breaks between named arguments, or before the opening brace. (We may later add an option to disallow the {
on a new line, though.)
If there are no named arguments, but a nonempty sequential argument, the opening brace gets an indentBefore
of 1:
sum
{ -1.0, for (i in 0..10) 1.0/2^i }
A named argument list with only sequenced arguments looks exactly like an iterable literal, so we encourage it to be in one separate line. This can result in the unfortunate case of
sum
{ for (i in 1:100)
if (i % 2 == 0)
i }
where the if
clause looks like it hasn’t gained any indentation, but I don’t see how we can do even better than that.
Formatter output:
Body { H2("Welcome to Ceylon!") };
There are fully hierarchic forms composed exclusively of sequenced arguments. Dang.
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
).
Reopening and moving to next milestone for additional option.
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.
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.
Formatter currently turns
into