From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#32496: 27.0.50; Strange indentation when ruby-align-chained-calls is t Date: Wed, 08 Sep 2021 15:01:08 -0400 Message-ID: References: <87r1e8ei5v.fsf@gnus.org> <877dfzcvpl.fsf@gnus.org> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3541"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 32496@debbugs.gnu.org, Bozhidar Batsov , Artur Malabarba , Dmitry Gutov To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Sep 08 21:03:24 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mO2qy-0000iB-6T for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 08 Sep 2021 21:03:24 +0200 Original-Received: from localhost ([::1]:58922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mO2qw-0007z9-P3 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 08 Sep 2021 15:03:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51856) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mO2pe-00067y-Po for bug-gnu-emacs@gnu.org; Wed, 08 Sep 2021 15:02:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:50260) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mO2pe-0006iW-FC for bug-gnu-emacs@gnu.org; Wed, 08 Sep 2021 15:02:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mO2pe-0006sy-5f for bug-gnu-emacs@gnu.org; Wed, 08 Sep 2021 15:02:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 08 Sep 2021 19:02:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32496 X-GNU-PR-Package: emacs Original-Received: via spool by 32496-submit@debbugs.gnu.org id=B32496.163112768026408 (code B ref 32496); Wed, 08 Sep 2021 19:02:02 +0000 Original-Received: (at 32496) by debbugs.gnu.org; 8 Sep 2021 19:01:20 +0000 Original-Received: from localhost ([127.0.0.1]:33573 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mO2oy-0006rs-0h for submit@debbugs.gnu.org; Wed, 08 Sep 2021 15:01:20 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:6324) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mO2ov-0006rb-T2 for 32496@debbugs.gnu.org; Wed, 08 Sep 2021 15:01:18 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 141B9801B5; Wed, 8 Sep 2021 15:01:16 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 2AC71808DF; Wed, 8 Sep 2021 15:01:14 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1631127674; bh=jmNNMqOdUELaJKvxjMwHRLkdCX0Vy/D4esM8EKxezdA=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=hLsfP8FKYRn/wlw/K9F8p3QZfHy3ujqrVFhhEEL3kwBGvtpuujIAH12EV58goxG1o GbEIIONXvecYn8t0AiWhFzxf2EAfGZ3BRn8gRKfpRYbZI2lKEVGcrIVvLM+Vq5pnqn bx26eYALOBYClRFYaoYg0xD7V++fFncgJJWl9YHmMf77Veq6AwAU+FGTiSUdxgv05s c3yKsAZNmlJwDNYCd+klVg676cEagcII6xb4R5L8li4wMQvNT0MlpbJVQuO3oLE6aS DY/kSasNOyxcBH56GowxVWQEiF88I6pwJPV1lNXMa3HoHr0t5U5sUX48me5VrX6LVo ex1Z1lkaZSSVQ== Original-Received: from pastel (unknown [104.247.244.135]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 530E6120351; Wed, 8 Sep 2021 15:01:09 -0400 (EDT) In-Reply-To: <877dfzcvpl.fsf@gnus.org> (Lars Ingebrigtsen's message of "Thu, 02 Sep 2021 08:55:50 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:213857 Archived-At: Lars Ingebrigtsen [2021-09-02 08:55:50] wrote: > "Bozhidar Batsov" writes: > >> Ah, I finally understood the issue at hand! It's really hard to discuss >> indentation problems in e-mail. :D >> >> Yeah, I can confirm there's a bug when using (setq ruby-align-chained-calls t) >> in this example: >> >> some_variable.where.not(x: nil) >> .where(y: 2) >> >> The two `where`s should be lined up, but currently the second `where` is >> lined up with the `not`. > > So this is coming from: > > ('(:before . ".") > (if (smie-rule-sibling-p) > (and ruby-align-chained-calls 0) > (smie-backward-sexp ".") > (cons 'column (+ (current-column) > ruby-indent-level)))) > > In the aligned case, I think we should back up to the first "." in the > chain and use that as the column? But my SMIE-fu is pretty much > non-existent, so I've added Stefan to the CCs. You could try something like diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index c09f007a5ee..c681800f6a7 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el @@ -640,7 +640,15 @@ ruby-smie-rules ('(:before . "do") (ruby-smie--indent-to-stmt)) ('(:before . ".") (if (smie-rule-sibling-p) - (and ruby-align-chained-calls 0) + (when ruby-align-chained-calls + (while + (let ((pos (point)) + (parent (smie-backward-sexp "."))) + (if (not (equal (nth 2 parent) ".")) + (progn (goto-char pos) nil) + (goto-char (nth 1 parent)) + (not (smie-rule-bolp))))) + (cons 'column (current-column))) (smie-backward-sexp ".") (cons 'column (+ (current-column) ruby-indent-level)))) @@ -826,13 +834,6 @@ ruby--electric-indent-p ;; FIXME: Remove this? It's unused here, but some redefinitions of ;; `ruby-calculate-indent' in user init files still call it. -(defun ruby-current-indentation () - "Return the indentation level of current line." - (save-excursion - (beginning-of-line) - (back-to-indentation) - (current-column))) - (defun ruby-indent-line (&optional ignored) "Correct the indentation of the current Ruby line." (interactive) But please add corresponding regression tests, Stefan