Groovy-Emacs-Modes / groovy-emacs-modes

A groovy major mode, grails minor mode, and a groovy inferior mode.
84 stars 39 forks source link

More indentation issues on 20170606.215 #61

Closed jordi-chacon closed 7 years ago

jordi-chacon commented 7 years ago

Hi, I have noticed the following indentation issues. For each issue I have specified how it works today, and how I would expect it to work based on my experience with modes of other languages.

1. Overly indented closure body

Current:

def foo() {
    def f = { ->
            "foo"
    }
}

Desired:

def foo() {
    def f = { ->
        "foo"
    }
}

2. Unaligned list items

Current:

def foo() {
    // works well
    def f = [
       1,
       2,
       3,
    ]
    // doesn't work well
    def f2 = [1,
        2,
        3,
    ]
}

Desired:

def foo() {
    def f = [
       1,
       2,
       3,
    ]
    def f2 = [1,
              2,
              3,
             ]
}

3. Unaligned map items

(same problem as for lists) Current:

def foo() {
    // works well
    def f = [
        a: 1,
        b: 2,
        c: 3
    ]
    // doesn't work well
    def f2 = [a: 1,
        b: 2,
        c: 3
    ]
}

Desired:

def foo() {
    def f = [
        a: 1,
        b: 2,
        c: 3
    ]
    def f2 = [a: 1,
              b: 2,
              c: 3
             ]
}

4. Unaligned function arguments

(Same as for lists and maps) Current:

def foo() {
    // works well
    someFunction(
        1,
        2,
        3)
    // doesn't work well
    someFunction(1,
        2,
        3)
}

Desired:

def foo() {
    someFunction(
        1,
        2,
        3)
    someFunction(1,
                 2,
                 3)
}

5. Wrongly indented arguments within method chaining

Current:

def foo() {
    someFunction()
        .anotherFunction1(
        param1,
        param2)
        .anotherFunction2()
}

Desired:

def foo() {
    // support both this:
    someFunction()
        .anotherFunction1(
            param1,
            param2)
        .anotherFunction2()
    // and this:
    someFunction()
        .anotherFunction1(param1,
                          param2)
        .anotherFunction2()
}

6. Closing curly bracket does not auto-indent

def foo() {
    if (1) {
        }
}

I have to manually press Tab on the line of the closing curly bracket for it to get indented properly. Both java and js modes indent closing curly brackets automatically.

Will keep reporting as I find more of these cases.

Thank you for your work! 🙏

Wilfred commented 7 years ago

I can't reproduce 6: I get the correct indentation on every line as far as I can see:

def foo() {
    if (1) {
    }
}
jordi-chacon commented 7 years ago

@Wilfred do you get the correct indentation immediately or do you have to actively press Tab on the closing curly bracket line?

Wilfred commented 7 years ago

What do you mean by immediately? I'm indenting by selecting the whole buffer and running M-x indent-region.

What do you have bound to TAB?

jordi-chacon commented 7 years ago

Exactly, you are indenting by selecting the whole buffer and running M-x indent-region.

What I am saying is that with java and js modes (just to name a couple), you don't need to do those two steps. Instead, as soon as you type }, the closing curly bracket gets properly indented automatically, which is the behaviour that I'd like to see in groovy mode too.

But feel free to drop this if you don't agree :+1:

Wilfred commented 7 years ago

Aha, gotcha. So the issue isn't that the indentation is wrong, it's that } isn't triggering indentation (so-called electric indent).

Would you mind filing a separate bug for that? It seems like a very reasonable feature.

Wilfred commented 7 years ago

1-4 are now fixed, 5 has moved to #83, and 6 is now a separate issue #62.

Given that, I'm going to close this issue in favour of the more specific issues we have open.