From: Dmitry Gutov <dgutov@yandex.ru>
To: Shin-ichiro OGAWA <rust.stnard@gmail.com>
Cc: 14439@debbugs.gnu.org
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 [thread overview]
Message-ID: <87y5b5ujy6.fsf@yandex.ru> (raw)
In-Reply-To: <CAO2ZnK0Nba1rqU3jS1wvVyrP=qfm1QC6jOcn7fh+Dc==HAYbAw@mail.gmail.com> (Shin-ichiro OGAWA's message of "Wed, 22 May 2013 17:26:44 +0900")
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.
next prev parent reply other threads:[~2013-05-24 3:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-22 8:26 bug#14439: 24.3; Ruby code indentation is broken at do-end block in case-when block Shin-ichiro OGAWA
2013-05-24 3:37 ` Dmitry Gutov [this message]
2013-12-04 18:23 ` Dmitry Gutov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y5b5ujy6.fsf@yandex.ru \
--to=dgutov@yandex.ru \
--cc=14439@debbugs.gnu.org \
--cc=rust.stnard@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).