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: Mon, 18 Nov 2024 09:35:41 +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="11956"; 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 Mon Nov 18 09:38:12 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 1tCxGu-0002wY-7I for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 18 Nov 2024 09:38:12 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tCxGO-0001X4-Pp; Mon, 18 Nov 2024 03:37:41 -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 1tCxFo-0001Ux-8L for bug-gnu-emacs@gnu.org; Mon, 18 Nov 2024 03:37:05 -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 1tCxFm-00044M-5U for bug-gnu-emacs@gnu.org; Mon, 18 Nov 2024 03:37: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=qmFj1gkFSRQKaCvjv/2gQgQWBgS/VctP4ixI68F6vwo=; b=sA37TzQe0eUE6wbV9UJ1rFU3MuvC6chKvsVgOFDtwNv81ZB/KMlzHRYl162QEngPwHMeEwxMid/czUN8QlubQiBDmxFua4/e6+hhV0/VRr0HGIsM61VHUeC4PpyCQwM7Rn6NKPXsUgatap3GX4Z1749ALMR+ZEG2whG29/oeZEik3ftO61mCrfE3OgX/Bfl364H+UgQMa1EWizl1831yseEcIrSovuItNytPvhLc3wz4ZNA91YdPvkXebbLQWWc1eQoe+WAdN30UD27WWFU6QMrOotFoVm8ErLUclkmP++qmrMZrRh3yqfwomrlTGiRdT9mM1CBiz5v6bxtWeU6BgA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tCxFl-0005Gq-OG for bug-gnu-emacs@gnu.org; Mon, 18 Nov 2024 03:37: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: Mon, 18 Nov 2024 08:37: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.173191902120257 (code B ref 74386); Mon, 18 Nov 2024 08:37:01 +0000 Original-Received: (at 74386) by debbugs.gnu.org; 18 Nov 2024 08:37:01 +0000 Original-Received: from localhost ([127.0.0.1]:59836 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tCxFk-0005Gb-OE for submit@debbugs.gnu.org; Mon, 18 Nov 2024 03:37:01 -0500 Original-Received: from mail-oo1-f48.google.com ([209.85.161.48]:50251) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tCxFi-0005GL-8c for 74386@debbugs.gnu.org; Mon, 18 Nov 2024 03:37:00 -0500 Original-Received: by mail-oo1-f48.google.com with SMTP id 006d021491bc7-5ebc9bda8c8so561123eaf.0 for <74386@debbugs.gnu.org>; Mon, 18 Nov 2024 00:36:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731918952; x=1732523752; 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=qmFj1gkFSRQKaCvjv/2gQgQWBgS/VctP4ixI68F6vwo=; b=klvqL6RPyaFYGSLZlThUycZIazwyf24ZNBqNtXluteZF52aipgJcARP9ukDZY4H/DR dGt8K8tfRA1X03kleUhcm2+9Y2k8u8n27L4vwuE6yzhb3wTiofZEVWHPDb3C8gON9p1s yuUxmO7dclOjM8ZkG7PcC23ecPyXpx1AMIjSKzjT63b6lOF+mC4gnw0jF4t6qTQx8Fwq GQ15miMAy7lLnwOhb2pU0Mrn4VkVOQukaLsX4TziR4PFh1Dy3OKPLVt4ADIGdZqsDGUD 1BAcYKXVrnEfEHUD/5nAcfURzCmu/JqvNjor+cnMkHyGSbHxEtq9hV/6TrsIM0i4X9Gb kDBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731918952; x=1732523752; 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=qmFj1gkFSRQKaCvjv/2gQgQWBgS/VctP4ixI68F6vwo=; b=uMgUO4rrxjN4ZEYZYXLZKPv3fg+bJUdzLxbxZkrPUu4r+svk4rJa25UYJFENIzDOeZ 2jBEnL7ObD2qqSOfFid+aUHMahxTEcFKK5NnvJxamQm0+Ti/Uagv3Q3CAY7p7tE3cCM8 mlpdNiWuEB59RwaxmPcw6Fw/Bc0t1+6VHkYdjKZ53dTjQ9f2QmyZeq2UJrjhp7YqiUwX E4e1e9SE2jG4a5TkYebCaIZhR/lal4WorA0J9GuYwlYtOuuV89C6iO5ledL2AVbunz9m BkYrI/QWFTU+hLv24g7i/OdBCAoCUiELR4sPB3ZijldC3BnwvNFXMaURE/qGlu3XkJWq vvhg== X-Forwarded-Encrypted: i=1; AJvYcCUjd7nhkXOocjBtC0MM5fHSqsvfRjer7gf/SbUUSeS0LNr+uuzW6Xb2n6k5fhMxJl7o+VA8Ng==@debbugs.gnu.org X-Gm-Message-State: AOJu0YwUAcOMWYqgOulMe3aIAhP3DLniGNEaYD02jqLtzLpAtGFfu4ui ZRh32BmK/IDJ1jdR55RmKWhyLXHUFMalFJyl+17JHF1TQbdJu5wZTOjvs6XqCThIwjZ3DMcMKtC 0nOseeawGgwx6Jr3kLRwmAQN1L6Y= X-Google-Smtp-Source: AGHT+IHcAe0op6sHC1zLPrTYOb6o0hYwR58cwSikl8rSXMhH+def4BkfIpOsCr354iXYw546SJkiWEFmHvAiErWzr68= X-Received: by 2002:a05:6870:de15:b0:259:88b4:976 with SMTP id 586e51a60fabf-2962e0d1ed4mr8203483fac.43.1731918952243; Mon, 18 Nov 2024 00:35:52 -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:295583 Archived-At: Can confirm your patch solves both the variants I showed. This will also help me to dig into and understand more of what is going on, and allows me to experiment more with my preferences (and tree-sitter in general). So thank you very much. When I get a clue, or when someone with a clue comes up with it, a patch which make these things configurable with easy settings would probably be. a good idea (instead of diving into "tree-sitter internals"). 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") >