From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.bugs Subject: bug#74386: Tree-sitter javascript indentation Date: Sun, 1 Dec 2024 18:31:02 -0800 Message-ID: <8A7428E6-50EE-4783-82FF-3A62C4756C56@gmail.com> References: <2ce8c98e-c399-46f1-a930-04f27a3d56dd@gutov.dev> <389b6090-6ae9-433a-85cc-a2d2eb84751f@gutov.dev> <86r06t82gl.fsf@gnu.org> <4B4B99E7-C4A1-4124-BC85-2AD66EF0871B@gmail.com> <35B61F44-C551-44DB-A334-A893991BC799@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_94AE5EBC-C795-4E1C-9FBF-A773A0606255" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21525"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 74386@debbugs.gnu.org, Eli Zaretskii , Theodor Thornhill , marius.kjeldahl@gmail.com To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Dec 02 03:33:22 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 1tHwFV-0005QL-Vq for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 02 Dec 2024 03:33:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tHwFF-0006mv-D4; Sun, 01 Dec 2024 21:33:05 -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 1tHwFD-0006mO-QB for bug-gnu-emacs@gnu.org; Sun, 01 Dec 2024 21:33:03 -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 1tHwFD-000467-35 for bug-gnu-emacs@gnu.org; Sun, 01 Dec 2024 21:33:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=References:In-Reply-To:Date:Mime-Version:From:To:Subject; bh=RL1O9VPXXseprmRnQHuj3yu8LsvtrC/tx4AxQhshjgA=; b=JJGVfkNg6MZTi7PHE6LwFZiP3QLDHPjIBCf3HcxP/CH8thqOdJajdqr//J8dw+GEw/1dIX0QdN0p5ysqPI6rzVxj37tZS/NRiJVo4+ZcKmme/2X9uAecZIg4UB6ZgduGryqdr2dlZDsxWHEyPK07ycmMuiIo3daQYGmmM/Cm5Psj5QaixbQwNl2yyv50NNKibMcaSQTRetG9UamIejcsSCeGJTgcT7aXWARIdJNH/OUko9JxhKaoaMnCB5Z9uk34Z1CNmh/qdQMh7v4bP+XUYfw4X9Zz9o9m+u9D8ELaJD0+iP0RhTysAgf2pGEzSbXfMZJjaDexz7QPhq1RSzv4OA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tHwFB-0008NO-V5 for bug-gnu-emacs@gnu.org; Sun, 01 Dec 2024 21:33:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 02 Dec 2024 02:33: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.173310674432139 (code B ref 74386); Mon, 02 Dec 2024 02:33:01 +0000 Original-Received: (at 74386) by debbugs.gnu.org; 2 Dec 2024 02:32:24 +0000 Original-Received: from localhost ([127.0.0.1]:53698 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tHwEZ-0008MI-GE for submit@debbugs.gnu.org; Sun, 01 Dec 2024 21:32:23 -0500 Original-Received: from mail-pl1-f170.google.com ([209.85.214.170]:50464) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tHwEW-0008M3-P5 for 74386@debbugs.gnu.org; Sun, 01 Dec 2024 21:32:22 -0500 Original-Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-21200c749bfso30425725ad.1 for <74386@debbugs.gnu.org>; Sun, 01 Dec 2024 18:32:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733106675; x=1733711475; darn=debbugs.gnu.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=RL1O9VPXXseprmRnQHuj3yu8LsvtrC/tx4AxQhshjgA=; b=MAf17q1aztMiACFFjAP/kjkq2kBr78rzEXlJyYBNnV87btAhBby43MaQ7gaueLzJfQ SnlKVk8nYD43JDR4UDGMcR2aE24XvYgW1KoPKGPrF3istITfhkNr+vpzqT8MscHyEPVP M5PHlIKz1sTY2XBq0O6ZPjkhV+Uf64FiTyBdoKL+2a/ZCSJMLz7/xvVhXah6L5d/ggoU hGBu/z4Qy7egMgveOB8gLuP1ammZOwLhQ9uNSKFt+yuD5unUWbtGhh6LkvQVe6sUYCoT hkfcsfjmh5OFxrZsYFlvEiQWrj2V+kfTp4LJr5gaB5sjs+BArlT/cfZJFnku7PmanYbx Lnzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733106675; x=1733711475; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RL1O9VPXXseprmRnQHuj3yu8LsvtrC/tx4AxQhshjgA=; b=rMjEYpLtuLzxXX9s8iI1ooPidLjb3uX+PMyWXWsZri9M+eB27Gt4lMHqTekpvYezEh FHKFAJ4TlFW/PElqSfzzXw6cLKzY11ML8lEhhlc9cSdPL6b/SHbIv3fTksN4DedMTU49 +eUZndeE1owkR/FDWfWUGNyNceSijYvEmLhmsiHHFcUlAU89GlwYFpOVIgOyDnUjjYYo ko0mlVVoL8JwELO7I4InTzs+Zg8Z+b4oMFFHofcN+Fl++eIKctV9J2fo2Ru3R1E9WpN0 dYBvJMy6hpdwJNco6od9N20Z1hltlyFlwQnMg7ZJDy7f0zsYlZXuWa+wxFugMT4XqDll e/+w== X-Forwarded-Encrypted: i=1; AJvYcCV1a0HfWVALVmFFKbgcSU2Ag0y1hn3lkE4ssHVJnAe4Eh/fiJFaNMhkbYV9r8iuQZp/yMNBaw==@debbugs.gnu.org X-Gm-Message-State: AOJu0Yz3n3/Zj4MMtZp/vWAJ/Z7sskRzxJyDU+wqxYu4p/lT0f/uVrHh 6wqiMh3EQTzpE8XzDDZlUaLm1/8YHSMDgXHMjrQSJinYWffaZdiL X-Gm-Gg: ASbGncvW1DZA9LrIXzmoVZBS1oZ3uV9Xt2SiblNHT5d9IUuJAQsZAzg6TaroyghlZb4 AowfsGQX97B0g8QmsdJvnvFxOsoTjseTTo9TE9ekHp8eBJ+sV/K/R6e5XrE4vIfzyhN8oCUTY7A QaD+x39oWDlfX1Y2qhA82PZzSeGxeF9ihMP0PxoxYJi8tKmoGrxUKKAGAOSPQ+Oyj4Vkz9X+a0d vi3KqCYR633tmHwVfGVmh5SF0Y9f9iS3WxORP/oVzsO5n2hZDpxe95525LaDnhzr3z8Spz+DQ== X-Google-Smtp-Source: AGHT+IGFSB1kTM9bdlE9OTcENf6he7ywDi3bySGVZkD4grz7UqWeYS72O4t7ECv8aMCCEeNzrWv+JQ== X-Received: by 2002:a17:902:e549:b0:215:5637:447 with SMTP id d9443c01a7336-2155637073amr106422995ad.51.1733106674991; Sun, 01 Dec 2024 18:31:14 -0800 (PST) Original-Received: from smtpclient.apple ([2601:646:8f81:6120:71b7:718f:7faa:8436]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21544fd9b4dsm45703415ad.223.2024.12.01.18.31.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Dec 2024 18:31:14 -0800 (PST) In-Reply-To: X-Mailer: Apple Mail (2.3776.700.51) 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:296293 Archived-At: --Apple-Mail=_94AE5EBC-C795-4E1C-9FBF-A773A0606255 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Dec 1, 2024, at 2:33=E2=80=AFPM, Dmitry Gutov = wrote: >=20 > On 01/12/2024 21:10, Yuan Fu wrote: >> Ah, I see. That=E2=80=99s a good point, and I definitely prefer the = indentation result of parent-bol here. The one produced by = standalone-parent is just wrong. What we can do is make = standalone-parent ignore =E2=80=9C.=E2=80=9D when checking for = =E2=80=9Cstandaloneness=E2=80=9D. And perhaps make it configurable so = it=E2=80=99s enabled only for modes that this waiver makes sense (C-like = languages excluding C and C++). >=20 > Maybe not by hardcoding this in inside the 'standalone-parent' = matcher, but writing this in the indentation rules? Different languages = might have differing ASTs for such construct. >=20 > Or if you meant to do a text search, a period might start a method = call, but it could also continue a "range" literal in some other = language, or some struct initializer (I think?) in C/C++. Also, some = languages allow (and style guides suggest) to have the previous at the = end of the line, then followed by newline and then the method name. Not hard-coded, but customizable, like this: Yuan --Apple-Mail=_94AE5EBC-C795-4E1C-9FBF-A773A0606255 Content-Disposition: attachment; filename=standalone-predicate-poc.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="standalone-predicate-poc.patch" Content-Transfer-Encoding: quoted-printable =46rom=20301e8a55a14f61258c505a48a973379ac3156079=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Yuan=20Fu=20=0ADate:=20Sun,=20= 1=20Dec=202024=2018:26:40=20-0800=0ASubject:=20[PATCH]=20Standalone=20= predicate=20POC=0A=0A---=0A=20lisp/treesit.el=20|=2037=20= +++++++++++++++++++++++++++++++++++--=0A=201=20file=20changed,=2035=20= insertions(+),=202=20deletions(-)=0A=0Adiff=20--git=20a/lisp/treesit.el=20= b/lisp/treesit.el=0Aindex=202acb46ab105..513f58eeffd=20100644=0A---=20= a/lisp/treesit.el=0A+++=20b/lisp/treesit.el=0A@@=20-1597,6=20+1597,37=20= @@=20treesit--indent-prev-line-node=0A=20=20=20=20=20=20=20= (back-to-indentation)=0A=20=20=20=20=20=20=20= (treesit--indent-largest-node-at=20(point)))))=0A=20=0A+(defvar=20= treesit-simple-indent-standalone-predicate=20nil=0A+=20=20"Function=20= used=20to=20determine=20if=20a=20node=20is=20\"standalone\".=0A+=0A= +\"Standalone\"=20means=20the=20node=20starts=20on=20a=20new=20line.=20=20= For=20example,=20if=20we=0A+look=20at=20the=20opening=20bracket,=20then=20= it's=20standalone=20in=20this=20case:=0A+=0A+=20=20=20=20{=20=20=20=20=20= =20=20=20=20=20=20=20<--=20Standalone.=0A+=20=20=20=20=20=20return=201;=0A= +=20=20=20=20}=0A+=0A+but=20not=20in=20this=20case:=0A+=0A+=20=20=20=20= if=20(true)=20{=20=20<--=20Not=20standalone.=0A+=20=20=20=20=20=20return=20= 1;=0A+=20=20=20=20}=0A+=0A+The=20value=20of=20this=20variable=20affects=20= the=20`standalone-parent'=20indent=20preset=0A+for=20= treesit-simple-indent.=20=20If=20the=20value=20is=20nil,=20the=20= standlone=20condition=0A+is=20as=20described.=20=20Some=20major=20mode=20= might=20want=20to=20relax=20the=20condition=20a=0A+little=20bit,=20so=20= that=20it=20ignores=20some=20punctuation=20like=20\".\".=20=20For=0A= +example,=20a=20Javascript=20mode=20might=20want=20to=20consider=20the=20= method=20call=20below=0A+to=20be=20standalone=20too:=0A+=0A+=20=20=20=20= obj=0A+=20=20=20=20.method(()=20=3D>=20{=20=20=20<--=20Consider=20= \".method\"=20to=20be=20standalone,=0A+=20=20=20=20=20=20return=201;=20=20= =20=20=20=20=20<--=20so=20this=20line=20anchors=20on=20\".method\".=0A+=20= =20=20=20});=0A+=0A+The=20value=20should=20be=20a=20function=20that=20= takes=20a=20node,=20and=20return=20t=20if=20it's=0A+standalone.")=0A+=0A=20= (defvar=20treesit-simple-indent-presets=0A=20=20=20(list=20(cons=20= 'match=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(lambda=0A@@=20= -1736,8=20+1767,10=20@@=20treesit-simple-indent-presets=0A=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20(catch=20'term=0A=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(while=20parent=0A=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(goto-char=20= (treesit-node-start=20parent))=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20(when=20(looking-back=20(rx=20bol=20(*=20= whitespace))=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (line-beginning-position))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20(when=20(if=20(null=20= treesit-simple-indent-standalone-predicate)=0A+=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (looking-back=20(rx=20bol=20(*=20whitespace))=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20(line-beginning-position))=0A+=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20(funcall=20parent))=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20(throw=20'term=20(point)))=0A=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(setq=20parent=20= (treesit-node-parent=20parent)))))))=0A=20=20=20=20=20=20=20=20=20(cons=20= 'prev-sibling=20(lambda=20(node=20parent=20bol=20&rest=20_)=0A--=20=0A= 2.39.5=20(Apple=20Git-151)=0A=0A= --Apple-Mail=_94AE5EBC-C795-4E1C-9FBF-A773A0606255--