From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs 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 Message-ID: <87y5b5ujy6.fsf@yandex.ru> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1369366714 23935 80.91.229.3 (24 May 2013 03:38:34 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 24 May 2013 03:38:34 +0000 (UTC) Cc: 14439@debbugs.gnu.org To: Shin-ichiro OGAWA Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri May 24 05:38:30 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Ufipl-00084U-9h for geb-bug-gnu-emacs@m.gmane.org; Fri, 24 May 2013 05:38:25 +0200 Original-Received: from localhost ([::1]:60217 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ufipk-0003xC-Pg for geb-bug-gnu-emacs@m.gmane.org; Thu, 23 May 2013 23:38:24 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:57418) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ufipc-0003vf-7X for bug-gnu-emacs@gnu.org; Thu, 23 May 2013 23:38:22 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UfipV-0008SM-TW for bug-gnu-emacs@gnu.org; Thu, 23 May 2013 23:38:16 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:42670) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UfipV-0008SA-QU for bug-gnu-emacs@gnu.org; Thu, 23 May 2013 23:38:09 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1UfiqM-0003TG-9u for bug-gnu-emacs@gnu.org; Thu, 23 May 2013 23:39:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 24 May 2013 03:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 14439 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 14439-submit@debbugs.gnu.org id=B14439.136936671713258 (code B ref 14439); Fri, 24 May 2013 03:39:02 +0000 Original-Received: (at 14439) by debbugs.gnu.org; 24 May 2013 03:38:37 +0000 Original-Received: from localhost ([127.0.0.1]:59261 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Ufipw-0003Ri-C2 for submit@debbugs.gnu.org; Thu, 23 May 2013 23:38:37 -0400 Original-Received: from mail-la0-f54.google.com ([209.85.215.54]:43517) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Ufipu-0003RR-O1 for 14439@debbugs.gnu.org; Thu, 23 May 2013 23:38:35 -0400 Original-Received: by mail-la0-f54.google.com with SMTP id eg20so4011248lab.13 for <14439@debbugs.gnu.org>; Thu, 23 May 2013 20:37:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type:x-antivirus:x-antivirus-status; bh=8rwAtsJDfQCRV4eT8HIAI9PD4XFX+zDkFC6pClhM24Y=; b=a/Y/rMSuZJ3HowHSVZNsd0eEsNN9eBTCfUk0dz5UveHECKbBpSleIaGKzGlS/8d7j9 wfjTpNqxLfsLOBpTLimRUtcVEf8yVm9r3wi9iVjazgQT0GQ1gpwmMyUIjRD7r1jw6Vlp dPJ8XLrxDy6arcH+2VDQq42WeJAtCc6U7Kofn8lPjHq/q6k6aedGdKgkIcodH4QHgzYy TWISb1kYUH1AEF7rAfrXFotsPEUDyViycjSEH6FFBwgsunfOXx4TLHl72CznGXmJfvPW RSwOUUuzVIlZTm+oGWJFFqQ6aZztYGXvvQZBwbkd/6UPm8so/Z+lAP3kRMt3xC0iu2WC 47yw== X-Received: by 10.112.235.102 with SMTP id ul6mr2345693lbc.10.1369366655394; Thu, 23 May 2013 20:37:35 -0700 (PDT) Original-Received: from SOL ([178.252.98.87]) by mx.google.com with ESMTPSA id g10sm5860142lag.10.2013.05.23.20.37.33 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 23 May 2013 20:37:34 -0700 (PDT) In-Reply-To: (Shin-ichiro OGAWA's message of "Wed, 22 May 2013 17:26:44 +0900") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (windows-nt) X-Antivirus: avast! (VPS 130523-1, 23.05.2013), Outbound message X-Antivirus-Status: Clean X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:74515 Archived-At: Shin-ichiro OGAWA 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.