Subject: bug#40760: 27.0.50; An indentation problem with const and chaining in js-mode

From: Dmitry Gutov <[email-masked]>
Date: Fri, 18 Mar 2022 03:12:01 +0200

On 14.03.2022 12:13, Marcin Borkowski wrote:
> 
> On 2022-03-14, at 10:40, Lars Ingebrigtsen <[email-masked]> wrote:
> 
>> Marcin Borkowski <[email-masked]> writes:
>>
>>> When declaring a const variable which is assigned a value of a long,
>>> chained expression, the default indentation is wrong (compared to a let
>>> declaration):
>>>
>>> let a = /regex/
>>>      .test('regex hello');
>>>
>>> const a = /regex/
>>>        .test('regex hello');
>>
>> I think this is the intended indentation?  That is, they indent to where
>> the "a" is.
> 
> Well, in a tab-only indentation style (used by many people, me included)
> this is _very_ wrong, e.g. because it results in Emacs using both tabs
> and spaces here.

I'm fairly certain it's not a very popular style, but we should try to 
cater to it as well, of course.

>> Marcin Borkowski <[email-masked]> writes:
>>
>>> This is the temporary solution I employed:
>>>
>>> (setq js--declaration-keyword-re "\\<\\(let\\|var\\)\\>")
>>>
>>> I would suggest turning this variable into a user option.
>>
>> This isn't just used for indentation, so altering this const will lead
>> to other breakages (and so it shouldn't be customiseable, either).
> 
> Grep apparently disagrees - I found 5 occurrences of
> `js--declaration-keyword-re' in Emacs sources, and all of them seem to
> be related to indentation.  So, I don't see any danger here.  (Anyway,
> I changed it in my init.el; we'll see how that works.)

I think it would be better to add a more semantically-named user option.

This indentation feature was ported from js2-mode at some point, where 
it is guarded by the (on by default) user option 
js2-pretty-multiline-declarations. The option itself was lost in transition.

See js2-old-indent.el for more info.