Groovy-Emacs-Modes / groovy-emacs-modes

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

Indentation after labels is inconsistent #133

Closed quanticle closed 5 years ago

quanticle commented 5 years ago

Hello everyone,

I've noticed an issue with groovy-mode and I'm not sure if it's a problem with my setup or if it's a problem with groovy-mode. The auto-indent behaves inconsistently, in my opinion, around labels, as seen with the following example:

def foo(){
    label1:
        bar()
    baz()

    label2:
        test()
    other_function_call()
}

I would expect the indentation to be as follows:

def foo(){
    label1:
    bar()
    baz()

    label2:
    test()
    other_function_call()
}

Why is groovy-mode indenting the first statement after the label, but not subsequent statements? Is there a way to turn this off? This makes writing Spock unit tests pretty annoying, since I have to go back and fix the indentation of the first statement after the label every time.

quanticle commented 5 years ago

For the moment I've worked around this issue by adding the following to my .emacs:

(add-hook 'groovy-mode-hook (lambda ()
  (setq-local indent-line-function 'indent-relative)))

What this does is replace the Groovy indent function with the default indent-relative which indents each line to the same indentation as the previous line. It's not as smart, but it is at least predictable.

Wilfred commented 5 years ago

This should now be fixed, feel free to reopen if not :)