unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 32496@debbugs.gnu.org, Bozhidar Batsov <bozhidar@batsov.dev>,
	Artur Malabarba <bruce.connor.am@gmail.com>,
	Dmitry Gutov <dgutov@yandex.ru>
Subject: bug#32496: 27.0.50; Strange indentation when ruby-align-chained-calls is t
Date: Wed, 08 Sep 2021 15:01:08 -0400	[thread overview]
Message-ID: <jwv1r5yyjsb.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <877dfzcvpl.fsf@gnus.org> (Lars Ingebrigtsen's message of "Thu, 02 Sep 2021 08:55:50 +0200")

Lars Ingebrigtsen [2021-09-02 08:55:50] wrote:

> "Bozhidar Batsov" <bozhidar@batsov.dev> 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






  reply	other threads:[~2021-09-08 19:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-22 11:36 bug#32496: 27.0.50; Strange indentation when ruby-align-chained-calls is t Artur Malabarba
2018-08-22 12:50 ` Dmitry Gutov
2018-10-27 22:22   ` Artur Malabarba
2018-11-18  8:36     ` Bozhidar Batsov
2021-09-01  9:53       ` Lars Ingebrigtsen
2021-09-01 10:02         ` Bozhidar Batsov
2021-09-02  6:55           ` Lars Ingebrigtsen
2021-09-08 19:01             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2021-09-09 14:25               ` Lars Ingebrigtsen
2020-09-11 17:16 ` Wendel Scardua

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwv1r5yyjsb.fsf-monnier+emacs@gnu.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=32496@debbugs.gnu.org \
    --cc=bozhidar@batsov.dev \
    --cc=bruce.connor.am@gmail.com \
    --cc=dgutov@yandex.ru \
    --cc=larsi@gnus.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).