bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#60186: 29.0.60; ruby-mode indentation of multi-line expressions


From: Dmitry Gutov
Subject: bug#60186: 29.0.60; ruby-mode indentation of multi-line expressions
Date: Thu, 22 Dec 2022 00:48:38 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2

On 20/12/2022 22:05, Aaron Jensen wrote:
    some_variable = some_number + some_other_number *
                                 some_third_number +
                   some_fourth_number -
                   some_fifth_number

Yeah, with this I'd probably be trying to give a name to some of the
things (what is the name of the product there?) I don't think I've
ever seen code like that in practice to be honest.

Sure, but if such complex structures are not used, it also doesn't matter that the ruby-mode indents them differently from the "community baseline".

But it could still help when prototyping code, fiddling with the implementation (to factor pieces out into named variables later), etc.

One might ask why it's lined up to 'map' only after it's moved to the
next line, but not in the first example.

It's never lined up to map, I don't think that's the right way to
think about it. It's lined up to indent level 1. It isn't until after
the `end' that the indent level returns to 0.

Line continuation (mid-expression): +1 indent level
Block opening (mid-block): +1 indent level
Paren opening (mid-arguments/params): +1 indent level
And all the closing/endings: -1 indent level

Only one indent level can be added per line, so all that matters is
where the line ends. In short, there are a set of expressions that
require indentation if they span multiple lines:

expression-start
   expression-middle
expression-end

I think I got it. Only one indent level can be added for the duration of a statement. Unless there are nested blocks or parens/brackets/braces.

I haven't tried the patch yet, but I'll give it a shot.

See this new patch instead.

The code is messier than I'd like it to be, but it seems to handle all of the cases mentioned so far and more (including the dots-at-indentation style, thanks).

Attachment: ruby-simplified-indent-v3.diff
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]