bug#60321: 29.0.60; ruby-mode indentation of hash or array as first arg in multiline method call
Updated patch with more precise variables in the new test. Aaron On Sat, Aug 31, 2024 at 7:41 PM, Aaron Jensen wrote: > I made an attempt at this (attached). It introduces a new variable: > > ruby-bracketed-args-indent > > It is set to t by default and the behavior will be as it was before this > patch. > > If it is something other than t, it will cause enable indentation like > this: > > update({ > key => value, > other_key: > }, { > key => value, > other_key: > }) > > update([ > 1, > 2 > ], [ > 3, > 4 > ]) > > It does not handle cases such as: > > some_method({ > key: :value > }, > other_argument) > > It will indent other_argument to be aligned with the (. This could be > elaborated further, but I contend that if people are formatting their code > this way that they likely have rather idiosyncratic formatting requirements > and they would be best left to do what they want manually. > > Thanks, > > > Aaron > > > On Mon, Dec 26, 2022 at 8:38 PM, Aaron Jensen > wrote: > > On Mon, Dec 26, 2022 at 8:16 PM Dmitry Gutov wrote: > > Vim's choice looks saner to my eye. Probably comes down to the choice of > indentation algorithm, though. > > Agreed, though it's hard to pick which is more sane when all the options > start with insanity. > > If I had to type it as above, I would probably indent it like this: > > and_in_a_method_call({ > no: :difference > }, > foo, > bar) > > But I can't imagine that would be easy to implement at all, so I wouldn't > bother. > > The indentation logic itself might be not that difficult to write, but the > fact that the expression will have to be reindented as soon as the method > call grows a second argument (after the user types the comma?), makes it a > hard sell usability-wise. > > Right, I think that's just more of the same thing... We are looking at > ways of writing code that are out of the realm of reason. It's a challenge > to define behavior when the behavior could very well be undefined. But, if > we must define it, then what are our guiding principles? Not having to > reindent preceding lines when adding a new line may be a very reasonable > one. In that case, the only two options I could think of would be: > > and_in_a_method_call({ > no: :difference > }, > foo, > bar) > > or > > and_in_a_method_call({ > no: :difference > }, > foo, > bar) > > The difference being if we decide to dedent upon the last closing > indent-requiring-token or the first. > > I think a reasonable rule of thumb for a human might be: "If you open N > indents on one line, you must close N indents on one line". Any time you > stray away from this, behavior becomes... not ideal. > > Aaron > > 0001-Add-ruby-bracketed-argument-indentation-option.patch Description: Binary data
bug#60321: 29.0.60; ruby-mode indentation of hash or array as first arg in multiline method call
Hi Dmitry, Here's a corrected patch for that particular example. Thank you for finding that. I think I missed it because as long as you type the code in, it indents fine. I still have a lot to understand about SMIE, so if anything looks off in my patch, please let me know. I didn't change the default. I wasn't sure if you wanted to change the defaults of all of the variables you added in the last round or just this one, so I'll let you handle that the way you want to. Thanks, Aaron On Sun, Sep 01, 2024 at 12:36 PM, Dmitry Gutov wrote: > Hi Aaron! > > On 01/09/2024 03:54, Aaron Jensen wrote: > > Updated patch with more precise variables in the new test. > > Thanks for taking the initiative. > > Here's an example which seems to get worse with the new variable set to > nil: > > def foo > foo.update( > { > key => value, > other_key: foo > } > ) > end > > I'd like to flip the default value (now or in Emacs 31), so it would be > great to deal with examples like this. > 0001-Add-ruby-bracketed-argument-indentation-option.patch Description: Binary data
bug#60321: 29.0.60; ruby-mode indentation of hash or array as first arg in multiline method call
On Sun, Sep 1, 2024 at 8:19 PM Dmitry Gutov wrote: > > On 01/09/2024 22:28, Aaron Jensen wrote: > > > Here's a corrected patch for that particular example. Thank you for > > finding that. I think I missed it because as long as you type the code > > in, it indents fine. I still have a lot to understand about SMIE, so if > > anything looks off in my patch, please let me know. > > Thanks! Just being thorough. We can add this example to the args-indent > test file, too. > > Here's a bonus example which looks off but would be more difficult to > fix (and it's not urgent, given the expression is in mixed styles): > > foo([{ >a: 2 > }, > { > b: 3 > }, > 4 > ]) Yes, that's connected to the case I mentioned... how do you think it should be indented? I wonder if it should just be 2 spaces in (rather than aligned with the opening bracket) > It would be nice to at least handle the last arg correctly - maybe we'll > just get that supported in the ts mode at some later date. > > > I didn't change the default. I wasn't sure if you wanted to change the > > defaults of all of the variables you added in the last round or just > > this one, so I'll let you handle that the way you want to. > > Sure. I think we can add this into Emacs 30 too, while the change is off > by default. Sounds good. > A few other things: > > * I think the docstring should say "Set it to nil to align to the line > with the open bracket" - it doesn't necessarily align to the beginning > of the statement (seems like a good thing). Good call. > * Let's change the first example to this, for less ambiguity? > >foo > .update({ >key => value, >other_key: > }, { >key => value, >other_key: > }) > Done > * Support for the new option in ruby-ts-mode (it's good to have parity). > Could you take the attached patch for a spin? Seems to work here, but > I'd like to have an extra confirmation. I don't have the treesitter stuff installed at the moment, will try this out shortly. Thanks, Aaron 0001-Add-ruby-bracketed-argument-indentation-option.patch Description: Binary data
bug#60321: 29.0.60; ruby-mode indentation of hash or array as first arg in multiline method call
> It seems to me that anything other than 0 spaces would look inconsistent > with the first element (the hash), and its closing brace in particular. Yeah, that's my sense as well, even if it looks awful, but you get what you get. > >> * Support for the new option in ruby-ts-mode (it's good to have parity). > >> Could you take the attached patch for a spin? Seems to work here, but > >> I'd like to have an extra confirmation. > > > > I don't have the treesitter stuff installed at the moment, will try > > this out shortly. > > Thanks in advance. I installed it and gave it a run on a few things. I didn't observe any issues with it. Aaron
bug#60321: 29.0.60; ruby-mode indentation of hash or array as first arg in multiline method call
I made an attempt at this (attached). It introduces a new variable: ruby-bracketed-args-indent It is set to t by default and the behavior will be as it was before this patch. If it is something other than t, it will cause enable indentation like this: update({ key => value, other_key: }, { key => value, other_key: }) update([ 1, 2 ], [ 3, 4 ]) It does not handle cases such as: some_method({ key: :value }, other_argument) It will indent other_argument to be aligned with the (. This could be elaborated further, but I contend that if people are formatting their code this way that they likely have rather idiosyncratic formatting requirements and they would be best left to do what they want manually. Thanks, Aaron On Mon, Dec 26, 2022 at 8:38 PM, Aaron Jensen wrote: > On Mon, Dec 26, 2022 at 8:16 PM Dmitry Gutov wrote: > > Vim's choice looks saner to my eye. Probably comes down to the choice of > indentation algorithm, though. > > Agreed, though it's hard to pick which is more sane when all the options > start with insanity. > > If I had to type it as above, I would probably indent it like this: > > and_in_a_method_call({ > no: :difference > }, > foo, > bar) > > But I can't imagine that would be easy to implement at all, so I wouldn't > bother. > > The indentation logic itself might be not that difficult to write, but the > fact that the expression will have to be reindented as soon as the method > call grows a second argument (after the user types the comma?), makes it a > hard sell usability-wise. > > Right, I think that's just more of the same thing... We are looking at > ways of writing code that are out of the realm of reason. It's a challenge > to define behavior when the behavior could very well be undefined. But, if > we must define it, then what are our guiding principles? Not having to > reindent preceding lines when adding a new line may be a very reasonable > one. In that case, the only two options I could think of would be: > > and_in_a_method_call({ > no: :difference > }, > foo, > bar) > > or > > and_in_a_method_call({ > no: :difference > }, > foo, > bar) > > The difference being if we decide to dedent upon the last closing > indent-requiring-token or the first. > > I think a reasonable rule of thumb for a human might be: "If you open N > indents on one line, you must close N indents on one line". Any time you > stray away from this, behavior becomes... not ideal. > > Aaron > 0001-Add-ruby-bracketed-argument-indentation-option.patch Description: Binary data
bug#60321: 29.0.60; ruby-mode indentation of hash or array as first arg in multiline method call
Thank you, and thanks for your help. Aaron On Mon, Sep 2 2024 at 3:01 PM, Dmitry Gutov wrote: > On 02/09/2024 04:56, Aaron Jensen wrote: > > It seems to me that anything other than 0 spaces would look inconsistent > with the first element (the hash), and its closing brace in particular. > > Yeah, that's my sense as well, even if it looks awful, but you get what > you get. > > * Support for the new option in ruby-ts-mode (it's good to have parity). > Could you take the attached patch for a spin? Seems to work here, but I'd > like to have an extra confirmation. > > I don't have the treesitter stuff installed at the moment, will try this > out shortly. > > Thanks in advance. > > I installed it and gave it a run on a few things. I didn't observe any > issues with it. > > Great! > > I've pushed both patches to emacs-30 (6c15b7710d4 and 24f12bdd77e) and now > marking the issue as done. Thanks again for the patch. > > To summarize for future readers: the default behavior doesn't change - at > least not now - you need to customize the option for different indentation. >