From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Marius Kjeldahl Newsgroups: gmane.emacs.bugs Subject: bug#74386: Tree-sitter javascript indentation Date: Sun, 17 Nov 2024 23:21:13 +0100 Message-ID: References: <2ce8c98e-c399-46f1-a930-04f27a3d56dd@gutov.dev> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23262"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 74386@debbugs.gnu.org, Theodor Thornhill To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Nov 17 23:23:16 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tCnfo-0005tS-79 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 17 Nov 2024 23:23:16 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tCnff-0003vX-NY; Sun, 17 Nov 2024 17:23:07 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tCnfa-0003v3-8m for bug-gnu-emacs@gnu.org; Sun, 17 Nov 2024 17:23:02 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tCnfa-0005mA-0c for bug-gnu-emacs@gnu.org; Sun, 17 Nov 2024 17:23:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=Date:From:In-Reply-To:References:MIME-Version:To:Subject; bh=oz7PMhXDtit7P1Kb7Qlh3jrDR6MU4Oh+BReLjhMpnOM=; b=Vzra50fSJzcvbR0JH9+cAsjPgHiDfYH/49itpxUgkNVotMrFOExN9SQIDX0g8+gjWdugfNx28BVOENNp1yzJeNoddmzL6By4oP8OLXN8oAWuyiSu4MJx9LcwC+Tre0H0yynZQlhn/wenH98zeK+UV1P6Qr4vraIBTaxKLYqy3haQltiZn73XO4QXDappTY10ZqxpxXGlplSntBUjBAQoEBlvrET2GtDxxqU8ATTgft6mPwn6vWYjoOvZeCEp0xuHezJDoqKFeNHhs6qCbCA1/S0W9nLBLPcEp0lNs/bUmB9fEY7ZkZJ+cA/3DQat0gmYnw0tM6PjNOqnwiiG5LbXdQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tCnfZ-00020u-Rh for bug-gnu-emacs@gnu.org; Sun, 17 Nov 2024 17:23:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Marius Kjeldahl Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 17 Nov 2024 22:23:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74386 X-GNU-PR-Package: emacs Original-Received: via spool by 74386-submit@debbugs.gnu.org id=B74386.17318821527695 (code B ref 74386); Sun, 17 Nov 2024 22:23:01 +0000 Original-Received: (at 74386) by debbugs.gnu.org; 17 Nov 2024 22:22:32 +0000 Original-Received: from localhost ([127.0.0.1]:58986 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tCnf6-000200-8l for submit@debbugs.gnu.org; Sun, 17 Nov 2024 17:22:32 -0500 Original-Received: from mail-oa1-f47.google.com ([209.85.160.47]:57713) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tCnf4-0001zn-C5 for 74386@debbugs.gnu.org; Sun, 17 Nov 2024 17:22:31 -0500 Original-Received: by mail-oa1-f47.google.com with SMTP id 586e51a60fabf-29066daf9e2so1722074fac.3 for <74386@debbugs.gnu.org>; Sun, 17 Nov 2024 14:22:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731882084; x=1732486884; darn=debbugs.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=oz7PMhXDtit7P1Kb7Qlh3jrDR6MU4Oh+BReLjhMpnOM=; b=I4RFeY5EoF+qYbW1oHHTN4QzvRmEN58Bg3+9qLFGToLBfWlJJPlfnD8psobdKQpYQg F2JzwGO8wCgfE8kxU3/punYacDz1QnKtrA++SBN4jFxyu+NWhrXfTm9pepbeRYMWwJ1r xE+DFtCnKBumXor1s+iMYtpjhzecHqZfORUSBj6MKOxEqgV96kPRyf+HzO3w8gsb9f3c rxjSuLVwM8Yq15fIAX2BWAakSlFrbtINuR5N4N96hT01mFrRjalgogNEOTaY8EfO+C70 cW2foRGlcXawcAD0vy9RafInlWTMgEzN2RfB/uGEnWO4qnFidzH+T8zPpQU+dgVf/xel AFBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731882084; x=1732486884; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=oz7PMhXDtit7P1Kb7Qlh3jrDR6MU4Oh+BReLjhMpnOM=; b=cmemvtf4sNtFSpI9mFbqEqThY95eebrc3BFYIqldEubSCiGl7NTu6cjzQQY8LBnTK2 lQqBwORzY6nggDhAxDGcjiph5GzO0qF28PFbsF/kCE7iUV2N3gK9pnIqEwdld9N2Dp/U TusxbOeH4hQuJLtv7lES5KdItGTVM/I+qWIQPS1bhVYlKS6pnbZORcKuFon8l67tzUsx LXVnn3ZdNRqBrTVzSpIa2WSxEGtJ01DLPoRsgwuOmdV2QKEG7Gp2GdeFnxxAkOBE7m1+ 4DW1TbT3ilTqG4yu+ZVVGJ6k+1x3n94EMuTbhZ922Ew8vWk6oqajpe45igO2qXD4rTTH f5Jw== X-Forwarded-Encrypted: i=1; AJvYcCUlUbt3QMRs/v30PrdVmV7pFZrmSNoIVwZzX1z4GuWb7dgoifXjDy06d5yb6vlEbPdUlQFbeA==@debbugs.gnu.org X-Gm-Message-State: AOJu0YzgCcMID1ojsyi/ep7K7lu581am2jF3iAUBmvOmNDV78IwBF215 WSdT/i3awqgj3nR0+9Ea3LqLHdrgXzLAor8F582MPunKecok9gYGgt7FlZ3m+7umti94vC5bHtF r5Y33p6IgMg7DZRHdUQ/EBYf2N9U= X-Google-Smtp-Source: AGHT+IHQYUj/Mj3BgFxOh46m+T1ymgagbWQy2+LAtzT/vj4his9qTKZZvgBtH5/bg6S0Cyh0z681n3+PSwK2UpF1Bsk= X-Received: by 2002:a05:6870:414f:b0:288:570d:8fe8 with SMTP id 586e51a60fabf-2962dc91b7amr7386706fac.3.1731882084583; Sun, 17 Nov 2024 14:21:24 -0800 (PST) In-Reply-To: <2ce8c98e-c399-46f1-a930-04f27a3d56dd@gutov.dev> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:295566 Archived-At: Sounds good, will try. I'm not sure I like you other examples much, so customizability for these things would be preferable. Thanks, Marius K. On Sun, 17 Nov 2024 at 23:12, Dmitry Gutov wrote: > > On 17/11/2024 21:21, Marius Kjeldahl wrote: > > Great, thanks. > > > > Here are two examples (fingers crossed): > > > > function a(b, > > c) { > > ....d(); > > > > and > > > > if (clause1 > > && clause2) { > > ....callSomeFunc(); > > > > Notice in both cases the four dots "...." representing spaces used for > > indentation. I would like only two dots (two spaces) for those > > specific examples. > > Thank you, these two examples should be handled by the patch below. > > It's a change which could affect a fair amount of other examples too - > for example > > Foobar > .find() > .catch((err) => { > return 2; > }) > .then((num) => { > console.log(num); > }); > > turns into > > Foobar > .find() > .catch((err) => { > return 2; > }) > .then((num) => { > console.log(num); > }); > > > I'm not 100% sure if that's good or bad (maybe worse compatibility with > js-mode, that we could say), so it would be useful to go through a bunch > of other examples and decide whether what we had is a bug, or these > should be supported as different styles, or etc. > > Cc'ing the original author of js-ts-mode, Theodor, for consultation. > > BTW, to try out such a patch you need to apply it, evaluate the defvar > form (C-M-x, for example), and then re-enable the major mode in a given > buffer (M-x js-ts-mode). > > diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el > index f74b8ab1c46..17a9509dd45 100644 > --- a/lisp/progmodes/js.el > +++ b/lisp/progmodes/js.el > @@ -3453,7 +3453,7 @@ js--treesit-indent-rules > (let ((switch-case (rx "switch_" (or "case" "default")))) > `((javascript > ((parent-is "program") parent-bol 0) > - ((node-is "}") parent-bol 0) > + ((node-is "}") standalone-parent 0) > ((node-is ")") parent-bol 0) > ((node-is "]") parent-bol 0) > ((node-is ">") parent-bol 0) > @@ -3466,7 +3466,7 @@ js--treesit-indent-rules > ;; "{" on the newline. > ((node-is "statement_block") parent-bol js-indent-level) > ((parent-is "named_imports") parent-bol js-indent-level) > - ((parent-is "statement_block") parent-bol js-indent-level) > + ((parent-is "statement_block") standalone-parent js-indent-level) > ((parent-is "variable_declarator") parent-bol js-indent-level) > ((parent-is "arguments") parent-bol js-indent-level) > ((parent-is "array") parent-bol js-indent-level) > @@ -3481,7 +3481,6 @@ js--treesit-indent-rules > ((parent-is "binary_expression") parent-bol js-indent-level) > ((parent-is "class_body") parent-bol js-indent-level) > ((parent-is ,switch-case) parent-bol js-indent-level) > - ((parent-is "statement_block") parent-bol js-indent-level) > ((match "while" "do_statement") parent-bol 0) > ((match "else" "if_statement") parent-bol 0) > ((parent-is ,(rx (or (seq (or "if" "for" "for_in" "while" "do") > "_statement") >