zenspider/enhanced-ruby-mode — pull request #48 by vzvu3k6k (2014-04-06 07:28:36+00:00)
Title: Fix `while do` double indents (#37)

This fixes #37. Sorry for the wait!

In this change, `@cond_stack` is used to detect if a `do` is optional or not.

```rb
while true do # <- This `do` is optional, and does not
# increment the level of indentation.
end
```

`@cond_stack` is basically equivalent to `cond_stack` in parse.y of MRI, but my implementation mistakes when `until`, `while` or `for ... in` appear in a condition of `until` and the rest, like this:

```rb
while until 1 do
:until_body
end do # <- ERM thinks this `do` is not optional.
:while_body
end
```

I've once fixed this in https://github.com/vzvu3k6k/enhanced-ruby-mode/commit/6e6dc90d2808513232d82807dde7f93b456ab60f, but I postponed merging this because
* I think few want to write such a code, and I'm afraid that
it adds bigger complexity than the problem it solves.
* As ERM thinks the `until` in the second sample code is modifier,
the second sample is not indented properly
whether optional `do`s are correctly detected or not.

FYI: To understand how MRI handles with `while do`, "The `do` conflict" section in [chapter 11 of Ruby Hacking Guide](http://ruby-hacking-guide.github.io/contextual.html) is helpful.