From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#74386: Tree-sitter javascript indentation Date: Mon, 18 Nov 2024 00:12:54 +0200 Message-ID: <2ce8c98e-c399-46f1-a930-04f27a3d56dd@gutov.dev> References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34842"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: 74386@debbugs.gnu.org To: Marius Kjeldahl , Theodor Thornhill Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Nov 17 23:14:41 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 1tCnXU-0008vf-IU for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 17 Nov 2024 23:14:41 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tCnX2-0002oi-Lb; Sun, 17 Nov 2024 17:14:12 -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 1tCnWs-0002oI-Cv for bug-gnu-emacs@gnu.org; Sun, 17 Nov 2024 17:14: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 1tCnWs-0003zZ-4N for bug-gnu-emacs@gnu.org; Sun, 17 Nov 2024 17:14:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=In-Reply-To:From:References:MIME-Version:Date:To:Subject; bh=ybNscExyFc9ogbR+OOjJLgYplx09TmQ4svd5owh+icI=; b=hiQeqxTDd/cjcu4Z29KNYEHwou0mloAls0uce/LNklVGbcjUbd1Gh/S3Bor933B8qBp2fgTfEaSdksyTaIbObHJxi4itT+tPX9TuyzQofqegJiczBcrM+XGSq7sl9xFvCq6if4JTYYiBjnMNKs20ReXm++hEtHa70QA8Vny6jSVzmdSseJIHseyT8tGP9cmXHB35pbuCBLUUlt904mpahZVgb7QyT3qiOQPcxvyNqE4I4eSYNzzPtnUstVhdbIRhkjs5gK81VHf2m8qe++47QjihqFQiC26QVlXTyRnl7o8GVeQ5ChAfnOS0uu8FwRH/27yaMTi0sVEE/PgVnaYzxA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tCnWr-0001Yx-Uo for bug-gnu-emacs@gnu.org; Sun, 17 Nov 2024 17:14:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 17 Nov 2024 22:14: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.17318815885924 (code B ref 74386); Sun, 17 Nov 2024 22:14:01 +0000 Original-Received: (at 74386) by debbugs.gnu.org; 17 Nov 2024 22:13:08 +0000 Original-Received: from localhost ([127.0.0.1]:58964 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tCnVw-0001XO-3O for submit@debbugs.gnu.org; Sun, 17 Nov 2024 17:13:07 -0500 Original-Received: from fhigh-a3-smtp.messagingengine.com ([103.168.172.154]:46299) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tCnVu-0001Ws-Fj for 74386@debbugs.gnu.org; Sun, 17 Nov 2024 17:13:03 -0500 Original-Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfhigh.phl.internal (Postfix) with ESMTP id 57BF51140127; Sun, 17 Nov 2024 17:12:57 -0500 (EST) Original-Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Sun, 17 Nov 2024 17:12:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1731881577; x=1731967977; bh=ybNscExyFc9ogbR+OOjJLgYplx09TmQ4svd5owh+icI=; b= GbS8079cuPFoVZkzYDPnDNwtZBhJ28HNDgRhVEazUXa7KzyLA8utbnL6l30GAsPm qpp16f5bt6MlAFKD/gIJYAk8sH/n460Rl7ZcbZQL5dLpe51cYCQ3PzBVOq4sywW8 U9N11yraBSXlnXaQ2bFauT/e5Z9B8ORTDb/pLpfQ6NjPGNRGEIT0I7jq5jY9chLK wu+dAIbEaDxH1H1clc+jH4TOs7PKSVjCVNG99+LXL5Al+wam4ZItKngf69NRIncI GRHhHmmBRH2m2r3avGOfrAmHOSZphiz1WXt+AtYEoqlqOMtoZS0LXTfk9r6hku69 PzM2J2hV0bRxRRynDaKfFw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1731881577; x= 1731967977; bh=ybNscExyFc9ogbR+OOjJLgYplx09TmQ4svd5owh+icI=; b=Z HweQFgY3moyJDyrFFPFL5DvBQ2+JLjpFkKg8SxPtowEjHeMWYCSiFnTIqyWRdJ8j r+ADwk+FYaWTGXB5azLVhkJ/9sT1VWcMJChEvSNbUd1s3s1tt10Z2pnxGWttqSYx FDjQcF2PXud5mJJ4vxJ1f+xfPnyde3l0QV0SW/GcWZLLOHEP76zjHs6PR7COvMw9 oTUe8MXp+72cnFgaCZFkVJ1QJ5j27tOkdFIdJoGWtrDzpZg7x6dpJP/8F8FMsk6y OsKifQTnfanob4Lnkd6xTy9NC/o6cbjxg5kSTYaSgszvBCP5kXqJQemrNoORH76k 1ZWALiyA2b5FDJNBgFSgQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrvdekgdduheejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtvdej necuhfhrohhmpeffmhhithhrhicuifhuthhovhcuoegumhhithhrhiesghhuthhovhdrug gvvheqnecuggftrfgrthhtvghrnhepteduleejgeehtefgheegjeekueehvdevieekueef tddvtdevfefhvdevgedujeehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepughmihhtrhihsehguhhtohhvrdguvghvpdhnsggprhgtphhtthho peefpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehmrghrihhushdrkhhjvghlug grhhhlsehgmhgrihhlrdgtohhmpdhrtghpthhtohepthhhvghosehthhhorhhnhhhilhhl rdhnohdprhgtphhtthhopeejgeefkeeiseguvggssghughhsrdhgnhhurdhorhhg X-ME-Proxy: Feedback-ID: i07de48aa:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 17 Nov 2024 17:12:56 -0500 (EST) Content-Language: en-US In-Reply-To: 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:295564 Archived-At: 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")