Groovy-Emacs-Modes / groovy-emacs-modes

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

case keywords inside switch is not indenting correctly #40

Closed fouvry closed 7 years ago

fouvry commented 7 years ago

The case and default keywords are not indented correctly (they are moved to the same column as the containing switch keyword). Also, the block inside a case is started at that column, and not in a further indentation as I would expect. (But perhaps my expectations are wrong?)

I'm using groovy-mode-20170323.817

russel commented 7 years ago

With the current Groovy Mode (based on CC Mode) all of these indents are programmable, what you are seeing is the effect of the default C patterns. You will need to lookup c-cleanup-list, c-offsets-alist, and all the other CC Mode style specification features.

Because there are some insoluble problems trying to deal with Groovy with a C/C++/Java based mode, development has stopped on this version. Instead there is now a develop branch in the repository with a mode that is not dependent on anything else, and so is not bound by the constraints of CC Mode. It is hoped that people will use this mode from the Git repository whilst it goes through alpha and beta phases. This mode has a very different way of setting indents etc. Much more focused on Groovy. If there are no problem in the next few weeks, we will replace the old CC Mode based code with the new code.

In the interim we clearly take pull requests on master, but we are hoping people will use and report back on the new standalone branch version.

Wilfred commented 7 years ago

@fouvry could you share an example that's indented incorrectly, along with how you'd expect it to be highlighted?

fouvry commented 7 years ago

@russel thanks for your answer. I'll give the new branch a go.

@Wilfred, here's an example:

myList.each {
  switch (it.getClass()) {
  case Class1:
  doSomething1()
  break
  case Class2:
  doSomething2()
  break
  default:
  println('No implementation for class')
  }
}

The indentation is as created when pressing tab. I'd expect more something like

myList.each {
  switch (it.getClass()) {
    case Class1:
      doSomething1()
      break
    case Class2:
      doSomething2()
      break
    default:
      println('No implementation for class')
  }
}
Wilfred commented 7 years ago

The new version of groovy-mode (on the standalone_mode branch) does a little better:

myList.each {
    switch (it.getClass()) {
        case Class1:
        doSomething1()
        break
        case Class2:
        doSomething2()
        break
        default:
        println('No implementation for class')
    }
}

It's just based on curly parens currently. We should increase the indentation under switch cases.

russel commented 7 years ago

@Wilfred The advantage of CC-Mode was that it has a framework for defining styles which included these indent issues. Should we consider doing something similar?

Wilfred commented 7 years ago

I don't think this is a style issue, it's a bug. We're not looking at different ways of indenting the code sample, we just need to ensure we handle case labels.