0

I'm writing some Groovy code, and in my unit tests I have something like the following:

def testFoo(){
    given:
    //setup statement 1
    //setup statement 2
    //...

    when:
    //Execute code

    then:
    //check results
}

The problem is that emacs, by default, autoindents so that the code looks like the following:

def testFoo(){
    given:
        //setup statement 1
    //setup statement 2
    //...

    when:
        //Execute code
    //Execute code 2

    then:
        //check results
    //check results 2
}

That is to say, emacs is indenting the first statement underneath the label.

How do I prevent emacs from doing this? I've tried running M-x c-set-offset <RET> label and setting the indentation to both 0 and - to no avail. Which offset should I be customizing?

EDIT: More generally, how do I see which indent rule is in effect at the point?

0

I came up with a somewhat hacky solution by just disabling programmatic indentation for Groovy:

; Disable fancy indentation on Groovy-mode
(add-hook 'groovy-mode-hook (lambda ()
    (setq indent-line-function 'indent-relative)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.