Emacs-D-Mode-Maintainers / Emacs-D-Mode

An Emacs mode for D code.
GNU General Public License v3.0
84 stars 21 forks source link

[ENH/BUG] Support version / else version / else pattern #39

Closed mathias-lang-sociomantic closed 9 years ago

mathias-lang-sociomantic commented 9 years ago

According to the specs, the following code:

version (SomeVersion)
{
}
else
    version (SomeOtherVersion)
    {
    }
else
{
    static assert (0, "Fail");
}

Should have the last else indented at the same level as version (SomeOtherVersion).

However, one common idiom is the following:

version (SomeVersion)
{
}
else version (SomeOtherVersion)
{
}
else
{
    static assert (0, "Fail");
}

Which basically allow us to use version as if. would it been possible to get both (bug fixed when version is on a newline after an else, and right alignment of braces when we have else version) ?

dmakarov commented 9 years ago

The same problem exists for debug statements:

  debug (A)
  {
  }
  else debug (B)
       {
       }
  else
  {
  }

The syntactic analysis that determines how code to be indented is built into the cc-mode engine and doesn't allow customization, i.e. addition of custom syntactic clauses. To fix this issues it is necessary either to reimplement the syntactic analysis for D mode, or to add D mode to the built-in languages of cc-mode.

russel commented 9 years ago

Pull request duly committed. I didn't get chance to test it out fully, but took the small risk and committed it anyway. We can always back out if problems arise.