Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

indentation of case with dafny-mode in emacs #9

Open
robstewart57 opened this issue Sep 8, 2016 · 1 comment
Open

indentation of case with dafny-mode in emacs #9

robstewart57 opened this issue Sep 8, 2016 · 1 comment

Comments

@robstewart57
Copy link

When I write a sequence of case statements, my expectation is that Tab to re-indent dafny code would line up all case occurrences vertically with the same number of space characters from the left of each line. However, each case is lined up with the statements inside of the case above:

method Baz(x:int) returns (y:int)
{
  if {
  case x == 0 =>
    y := 0;
    case 0 < x =>
      y := y + 1;
      case x < 0 =>
        y := y - 1;
  }
}
@cpitclaudel
Copy link
Member

Correct. It's tricky to detect these statements; the usual convention is to write them in any of the following forms:

  if {
  case x == 0 => y := 0;
  case 0 < x  => y := y + 1;
  case x < 0  => y := y - 1;
  }

  if {
  case x == 0 => {
    y := 0;
  }
  case 0 < x => {
    y := y + 1;
  }
  case x < 0  => {
    y := y - 1;
  }
  }

  if {
  case x == 0 =>
  { y := 0; }
  case 0 < x =>
  { y := y + 1; }
  case x < 0 =>
  { y := y - 1; }
  }

  if {
  case x == 0 => {
    y := 0;
  } case 0 < x => {
    y := y + 1;
  } case x < 0  => {
    y := y - 1;
  }
  }

The idea being that single-line bodies should either get braces, or be on the same line as the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants