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#16593: 24.3.50; ruby-mode: align chained method calls on multiple lines Date: Fri, 31 Jan 2014 05:42:14 +0200 Message-ID: <52EB1B96.4020602@yandex.ru> References: <87eh3qw0z1.fsf@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------050205030706030001090806" X-Trace: ger.gmane.org 1391139797 20161 80.91.229.3 (31 Jan 2014 03:43:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 31 Jan 2014 03:43:17 +0000 (UTC) Cc: 16593@debbugs.gnu.org, Bozhidar Batsov To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Jan 31 04:43:22 2014 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 1W950j-0002rZ-Bk for geb-bug-gnu-emacs@m.gmane.org; Fri, 31 Jan 2014 04:43:21 +0100 Original-Received: from localhost ([::1]:53138 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W950j-0007sd-12 for geb-bug-gnu-emacs@m.gmane.org; Thu, 30 Jan 2014 22:43:21 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51760) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W950Y-0007iE-9a for bug-gnu-emacs@gnu.org; Thu, 30 Jan 2014 22:43:17 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W950Q-0002al-UV for bug-gnu-emacs@gnu.org; Thu, 30 Jan 2014 22:43:10 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:56346) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W950Q-0002aA-Pr for bug-gnu-emacs@gnu.org; Thu, 30 Jan 2014 22:43:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1W950Q-0000iT-BB for bug-gnu-emacs@gnu.org; Thu, 30 Jan 2014 22:43:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 31 Jan 2014 03:43:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 16593 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 16593-submit@debbugs.gnu.org id=B16593.13911397442708 (code B ref 16593); Fri, 31 Jan 2014 03:43:02 +0000 Original-Received: (at 16593) by debbugs.gnu.org; 31 Jan 2014 03:42:24 +0000 Original-Received: from localhost ([127.0.0.1]:42132 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1W94zn-0000hc-Sm for submit@debbugs.gnu.org; Thu, 30 Jan 2014 22:42:24 -0500 Original-Received: from mail-ea0-f177.google.com ([209.85.215.177]:46020) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1W94zj-0000hQ-GR for 16593@debbugs.gnu.org; Thu, 30 Jan 2014 22:42:20 -0500 Original-Received: by mail-ea0-f177.google.com with SMTP id n15so2033226ead.8 for <16593@debbugs.gnu.org>; Thu, 30 Jan 2014 19:42:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type; bh=PntxiVwtjj90vSZ5E+fUWgeKRVvyYxsltqDPiyQjloM=; b=Z4Ywjemg+aSkP0o1A9MFg+pu6o9J36W1UREyrSWwlbGTIKIH2C/B/B6XAufh98hUiE H0m/HSocIBX2ZBcrwsDowLeNOu1/OK6lFfCaUd7ksboW4cr+6QqIhx6tKdhMicr/Fcgb 9ra9KwN19btLYAG571WbVqFfx8JYllR1JxPmo6vZeEOTmZDuguIFmMj/B05pK81rscLW vpkEwccAY/eZCzNwEQybY+Zr9cix+RT99ZocdcpU53AmPYHidFikNPpFHaRcntiT3MOZ n2AfOmAQ9uQ421inni8q2UC2BkmAL8IDqYSzhXjLNakpPn4ZaWr/LOaVKxjMoVCvg+gF dtUg== X-Received: by 10.14.223.71 with SMTP id u47mr140904eep.89.1391139738352; Thu, 30 Jan 2014 19:42:18 -0800 (PST) Original-Received: from [192.168.10.2] (62-151-136.netrun.cytanet.com.cy. [62.228.151.136]) by mx.google.com with ESMTPSA id b41sm30890383eef.16.2014.01.30.19.42.15 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 Jan 2014 19:42:16 -0800 (PST) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.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:84320 Archived-At: This is a multi-part message in MIME format. --------------050205030706030001090806 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 30.01.2014 16:35, Stefan Monnier wrote: >> Warning (smie): Conflict: . > Warning (smie): Conflict: . > The smie-precs->prec2 part of your grammar says that "." = "." (because > of the new (assoc ".") you add there). > > But the BNF part of your grammar says "." < "." (i.e. "foo . bar . baz" > is parsed as "foo . (bar . baz)" because of (id "." exp). Fantastic, thanks for the explanation. With (assoc ".") changed to (right "."), the warning is gone. I've also fixed the precedence of "." vs "? :" and modified a test case respectively. See the new patch attached. Do you think it's not too late in the feature freeze to install a change like this, or should we wait until the trunk reopens? We have a decent number of test cases, so it's not like the patch is likely to introduce major breakage. > Apparently there is no more conflict in the BNF in this respect so the > disambiguation constraint (assoc ".") that's passed to it is ignored. Without that constraint there, SMIE showed warnings about ambiguities between ".", "," and "=". It somehow ignored the associativity, though. The warnings with the previous patch also were gone when only the second one (assoc ".") were changed to (right "."). The first one, in the BNF disambiguation part, could be either. Bozhidar, would you care to test the new patch? --------------050205030706030001090806 Content-Type: text/x-patch; name="ruby-chained-calls.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="ruby-chained-calls.diff" === modified file 'lisp/progmodes/ruby-mode.el' --- lisp/progmodes/ruby-mode.el 2014-01-17 03:15:02 +0000 +++ lisp/progmodes/ruby-mode.el 2014-01-31 03:17:28 +0000 @@ -264,6 +264,13 @@ :safe 'listp :version "24.4") +(defcustom ruby-align-chained-calls nil + "If non-nil, chained method calls on multiple lines will be +aligned to the same column." + :type 'boolean + :group 'ruby + :safe 'booleanp) + (defcustom ruby-deep-arglist t "Deep indent lists in parenthesis when non-nil. Also ignores spaces after parenthesis when `space'. @@ -350,10 +357,10 @@ ;; but avoids lots of conflicts: (exp "and" exp) (exp "or" exp)) (exp (exp1) (exp "," exp) (exp "=" exp) - (id " @ " exp) - (exp "." id)) + (id " @ " exp)) (exp1 (exp2) (exp2 "?" exp1 ":" exp1)) - (exp2 ("def" insts "end") + (exp2 (exp3) (exp3 "." exp2)) + (exp3 ("def" insts "end") ("begin" insts-rescue-insts "end") ("do" insts "end") ("class" insts "end") ("module" insts "end") @@ -380,7 +387,7 @@ (ielsei (itheni) (itheni "else" insts)) (if-body (ielsei) (if-body "elsif" if-body))) '((nonassoc "in") (assoc ";") (right " @ ") - (assoc ",") (right "=") (assoc ".")) + (assoc ",") (right "=")) '((assoc "when")) '((assoc "elsif")) '((assoc "rescue" "ensure")) @@ -399,7 +406,8 @@ (nonassoc ">" ">=" "<" "<=") (nonassoc "==" "===" "!=") (nonassoc "=~" "!~") - (left "<<" ">>")))))) + (left "<<" ">>") + (right ".")))))) (defun ruby-smie--bosp () (save-excursion (skip-chars-backward " \t") @@ -609,7 +617,18 @@ ;; When after `.', let's always de-indent, ;; because when `.' is inside the line, the ;; additional indentation from it looks out of place. - ((smie-rule-parent-p ".") (smie-rule-parent (- ruby-indent-level))) + ((smie-rule-parent-p ".") + (let (smie--parent) + (save-excursion + ;; Traverse up the parents until the parent is "." at + ;; indentation, or any other token. + (while (and (progn + (goto-char (1- (cadr (smie-indent--parent)))) + (not (ruby-smie--bosp))) + (progn + (setq smie--parent nil) + (smie-rule-parent-p ".")))) + (smie-rule-parent)))) (t (smie-rule-parent)))))) (`(:after . ,(or `"(" "[" "{")) ;; FIXME: Shouldn't this be the default behavior of @@ -622,7 +641,10 @@ (unless (or (eolp) (forward-comment 1)) (cons 'column (current-column))))) (`(:before . "do") (ruby-smie--indent-to-stmt)) - (`(:before . ".") ruby-indent-level) + (`(:before . ".") + (if (smie-rule-sibling-p) + (and ruby-align-chained-calls 0) + ruby-indent-level)) (`(:after . "=>") ruby-indent-level) (`(:before . ,(or `"else" `"then" `"elsif" `"rescue" `"ensure")) (smie-rule-parent)) === modified file 'test/automated/ruby-mode-tests.el' --- test/automated/ruby-mode-tests.el 2014-01-01 07:43:34 +0000 +++ test/automated/ruby-mode-tests.el 2014-01-30 04:15:02 +0000 @@ -333,6 +333,20 @@ | 42 | end"))) +(ert-deftest ruby-align-chained-calls () + (let ((ruby-align-chained-calls t)) + (ruby-should-indent-buffer + "one.two.three + | .four + | + |my_array.select { |str| str.size > 5 } + | .map { |str| str.downcase }" + "one.two.three + | .four + | + |my_array.select { |str| str.size > 5 } + | .map { |str| str.downcase }"))) + (ert-deftest ruby-move-to-block-stops-at-indentation () (ruby-with-temp-buffer "def f\nend" (beginning-of-line) === modified file 'test/indent/ruby.rb' --- test/indent/ruby.rb 2014-01-17 03:15:02 +0000 +++ test/indent/ruby.rb 2014-01-31 02:55:31 +0000 @@ -257,8 +257,8 @@ bar foo_bar_tee(1, 2, 3) - .qux - .bar + .qux.bar + .tee foo do bar @@ -338,7 +338,7 @@ %^abc^ ddd -qux = foo ? +qux = foo.fee ? bar : tee @@ -348,7 +348,7 @@ zoo .lose( - q, p) + q, p) foo(bar: tee) --------------050205030706030001090806--