Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

1 view
Skip to first unread message

Shin-ichiro OGAWA

unread,
May 22, 2013, 4:26:44 AM5/22/13
to 14...@debbugs.gnu.org
Hi there,

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.

Please check it.

In GNU Emacs 24.3.1 (x86_64-apple-darwin12.3.0, NS apple-appkit-1187.37)
of 2013-05-17 on P409.local
Windowing system distributor `Apple', version 10.3.1187
Configured using:
`configure '--prefix=/usr/local/Cellar/emacs/24.3' '--without-dbus'
'--enable-locallisppath=/usr/local/share/emacs/site-lisp'
'--infodir=/usr/local/Cellar/emacs/24.3/share/info/emacs' '--with-ns'
'--disable-ns-self-contained' 'CC=/usr/bin/clang' 'CFLAGS=-Os -w -pipe
-march=native -Qunused-arguments -mmacosx-version-min=10.8'
'LDFLAGS=-L/usr/local/lib''

Important settings:
value of $LANG: ja_JP.UTF-8
locale-coding-system: utf-8-unix
default enable-multibyte-characters: t

Major mode: Ruby

Minor modes in effect:
tooltip-mode: t
mouse-wheel-mode: t
tool-bar-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
line-number-mode: t
transient-mark-mode: t

Recent input:
ESC [ > 0 ; 9 5 ; c C-x C-p ESC C-\ C-x C-p ESC w ESC
x r e DEL DEL r e p o r t - e m a c s - b u TAB RE
T

Recent messages:
("/usr/local/Cellar/emacs/24.3/Emacs.app/Contents/MacOS/Emacs"
"/Users/shinichiro-ogawa/ruby-mode-style.rb")
For information about GNU Emacs and the GNU system, type C-h C-a.
user-error: Beginning of history; no preceding item

Load-path shadows:
None found.

Features:
(shadow sort gnus-util mail-extr emacsbug message format-spec rfc822 mml
easymenu mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util mail-prsvr mail-utils ruby-mode time-date japan-util tooltip
ediff-hook vc-hooks lisp-float-type mwheel ns-win tool-bar dnd fontset
image regexp-opt fringe tabulated-list newcomment lisp-mode register
page menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock
font-lock syntax facemenu font-core frame cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese hebrew
greek romanian slovak czech european ethiopic indian cyrillic chinese
case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer loaddefs
button faces cus-face macroexp files text-properties overlay sha1 md5
base64 format env code-pages mule custom widget hashtable-print-readable
backquote make-network-process ns multi-tty emacs)

--------
Shin-ichiro OGAWA
rust....@gmail.com / og...@tokyurb.org
GPG ID 94B70E36 / 75360751
fingerprint: {C64E 9826 8A75 723E DE54 / 70A8 F623 220C 94B7 0E36}
http://stnard.jp/
http://twitter.com/conceal_rs/
http://iddy.jp/profile/rust/



Dmitry Gutov

unread,
May 23, 2013, 11:37:37 PM5/23/13
to Shin-ichiro OGAWA, 14...@debbugs.gnu.org
Shin-ichiro OGAWA <rust....@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.



Dmitry Gutov

unread,
Dec 4, 2013, 1:23:06 PM12/4/13
to Shin-ichiro OGAWA, 14439...@debbugs.gnu.org
Version: 24.4

Dmitry Gutov <dgu...@yandex.ru> writes:

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

And it's been fixed there, a little while ago. To make sure you're using
SMIE, check that the value of `ruby-use-smie' is t.



0 new messages