From: Marcin Borkowski <mbork@mbork.pl>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: Lars Ingebrigtsen <larsi@gnus.org>, 40760@debbugs.gnu.org
Subject: bug#40760: 27.0.50; An indentation problem with const and chaining in js-mode
Date: Mon, 21 Mar 2022 07:26:00 +0100 [thread overview]
Message-ID: <87czifq0sn.fsf@mbork.pl> (raw)
In-Reply-To: <0f3dfed4-f61a-87f9-6325-ca9d80e7077e@yandex.ru>
On 2022-03-18, at 02:12, Dmitry Gutov <dgutov@yandex.ru> wrote:
> On 14.03.2022 12:13, Marcin Borkowski wrote:
>> On 2022-03-14, at 10:40, Lars Ingebrigtsen <larsi@gnus.org> wrote:
>>
>>> Marcin Borkowski <mbork@mbork.pl> 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.
Interesting - I thought using spaces for indentation is a no-no nowadays
(at least in JS, Lisp is another thing, for obvious reasons). But I may
be mistaken, and I don't think tabs are inherently better - though we do
use them in our company.
>
>>> Marcin Borkowski <mbork@mbork.pl> 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.
Definitely, the name
>
> 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.
Very interesting. FWIW, I almost never have many variables in a single
let/const - I prefer to write
let a = 1;
let b = 2;
const c = 3;
const d = 4;
(and this also is a style I learned where I work).
Best,
--
Marcin Borkowski
http://mbork.pl
next prev parent reply other threads:[~2022-03-21 6:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-22 9:05 bug#40760: 27.0.50; An indentation problem with const and chaining in js-mode Marcin Borkowski
2022-03-14 5:10 ` Marcin Borkowski
2022-03-14 9:40 ` Lars Ingebrigtsen
2022-03-14 10:13 ` Marcin Borkowski
2022-03-18 1:12 ` Dmitry Gutov
2022-03-21 6:26 ` Marcin Borkowski [this message]
2022-03-23 0:46 ` Dmitry Gutov
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=87czifq0sn.fsf@mbork.pl \
--to=mbork@mbork.pl \
--cc=40760@debbugs.gnu.org \
--cc=dgutov@yandex.ru \
--cc=larsi@gnus.org \
/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).