unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#14439: 24.3; Ruby code indentation is broken at do-end block in case-when block
@ 2013-05-22  8:26 Shin-ichiro OGAWA
  2013-05-24  3:37 ` Dmitry Gutov
  0 siblings, 1 reply; 3+ messages in thread
From: Shin-ichiro OGAWA @ 2013-05-22  8:26 UTC (permalink / raw)
  To: 14439

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.stnard@gmail.com / ogawa@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/





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#14439: 24.3; Ruby code indentation is broken at do-end block in case-when block
  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
  2013-12-04 18:23   ` Dmitry Gutov
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Gutov @ 2013-05-24  3:37 UTC (permalink / raw)
  To: Shin-ichiro OGAWA; +Cc: 14439

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.





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#14439: 24.3; Ruby code indentation is broken at do-end block in case-when block
  2013-05-24  3:37 ` Dmitry Gutov
@ 2013-12-04 18:23   ` Dmitry Gutov
  0 siblings, 0 replies; 3+ messages in thread
From: Dmitry Gutov @ 2013-12-04 18:23 UTC (permalink / raw)
  To: Shin-ichiro OGAWA; +Cc: 14439-done

Version: 24.4

Dmitry Gutov <dgutov@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.





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-12-04 18:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2013-12-04 18:23   ` Dmitry Gutov

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).