bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#14439: 24.3; Ruby code indentation is broken at do-end block in case


From: Dmitry Gutov
Subject: bug#14439: 24.3; Ruby code indentation is broken at do-end block in case-when block
Date: Fri, 24 May 2013 07:37:37 +0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (windows-nt)

Shin-ichiro OGAWA <rust.stnard@gmail.com> writes:
> The indentation of the following Ruby code is broken
>
> return_value =
>   case type
>   when :a
>     somecode1
>     Timecop.travel do
>     somecode2
>   end
>     somecode3
>   when :b
>     somecode4
>     Timecop.travel do
>     somecode5
>   end
>     somecode6
>   else
>     somecode7
>   end
>
> In above code, the code `somecode2` in `Timecop.travel do`
> block must be indented at one more deep level.

The problem is caused by hanging off the assignment expression. This is
not a regression from any previous version of ruby-mode AFAICT, and
there's no simple fix.

Indentation adjustment for hanging expressions is handled by going to
the beginning of the current enclosing "scope" and looking backward a
little bit. That's why code directly inside "when" blocks is indented
fine, and code nested one level more (inside do-end), isn't.

Here's another example:

cookies =
  begin
    dough do
    bake!
  end
  end

One might ask, why aren't contents of do-end always indented relative to
the beginning of a block. I think the original author decided that
backtracking from "do" to the beginning of the method call expression
reliably is too hard (because, unlike many languages, Ruby allows
paren-less function calls), so the code just keeps track of the level of
nesting (to which hanging expression doesn't contribute), and then
indents relative to some reliable point far back (in these examples,
just beginning of the buffer).

We have a new "work in progress" SMIE-based indentation engine now, it
should be easier to fix this issue there, eventually.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]