eclipse-archived / ceylon.formatter

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

Make the indentation in comprehensions configurable #134

Closed bjansen closed 7 years ago

bjansen commented 7 years ago

Some people prefer this:

void testDestructureComprehensions() {
    value v = {
        for ([a, b, c] in [[1, 2.0, '3']])
        for ([Integer x, Float y, Character z] in [[a, b, c]])
        for ([init, *others] in [[0, *(1..runtime.maxIntegerValue)]])
        for ([String first, String *rest] in [["executableName", *process.arguments]])
        for (m->n in [true->"true"])
        for (Boolean o -> String p in [m->n])
        if (exists [ai, bi, ci] = { [1, 2.0, '3'] }.cycled.rest.first)
        if (exists [Integer xi, Float yi, Character zi] = { [ai, bi, ci] }.cycled.rest.first)
        if (exists [initi, *othersi] = [0, *(1..runtime.maxIntegerValue)])
        if (exists [String firsti, String *resti] = ["executableName", *process.arguments])
        if (exists mi->ni = { true->"true" }.cycled.rest.first)
        if (exists Boolean oi -> String pi = { mi->ni }.cycled.rest.first)
        nothing
    };
}

over this:

void testDestructureComprehensions() {
    value v = {
        for ([a, b, c] in [[1, 2.0, '3']])
            for ([Integer x, Float y, Character z] in [[a, b, c]])
                for ([init, *others] in [[0, *(1..runtime.maxIntegerValue)]])
                    for ([String first, String *rest] in [["executableName", *process.arguments]])
                        for (m->n in [true->"true"])
                            for (Boolean o -> String p in [m->n])
                                if (exists [ai, bi, ci] = { [1, 2.0, '3'] }.cycled.rest.first)
                                    if (exists [Integer xi, Float yi, Character zi] = { [ai, bi, ci] }.cycled.rest.first)
                                        if (exists [initi, *othersi] = [0, *(1..runtime.maxIntegerValue)])
                                            if (exists [String firsti, String *resti] = ["executableName", *process.arguments])
                                                if (exists mi->ni = { true->"true" }.cycled.rest.first)
                                                    if (exists Boolean oi -> String pi = { mi->ni }.cycled.rest.first)
                                                        nothing
    };
}

It would be nice if the indentation was configurable.

lucaswerkmeister commented 7 years ago

Should this be an Integer comprehensionIndentationLevels (default 1, @bjansen 0) or a Boolean indentComprehensions (default true, @bjansen false)? Integer is more general, but I assume almost nobody would use any values but 0 and 1, and a Boolean is friendlier to the IDE settings dialog (checkbox instead of number entry field).

bjansen commented 7 years ago

I vote in favor of a Boolean, people are not crazy enough to want double indents for this ;)

jvasileff commented 7 years ago

Boolean | Integer indentationEnabledOrSpaces :)

I've seen 1-space indenting on gitter.

bjansen commented 7 years ago

🙄

jvasileff commented 7 years ago

They should add that emoji to the standard list

bjansen commented 7 years ago

I got it from macOS' emoji keyboard! http://emojipedia.org/face-with-rolling-eyes/

lucaswerkmeister commented 7 years ago

I really don’t want to support indentation independent of indentMode… let’s keep it to levels, at least.