From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Noah Peart Newsgroups: gmane.emacs.bugs Subject: bug#68054: [PATCH] Add tree-sitter indent rule for lexical decls in js/typescript Date: Sun, 31 Dec 2023 00:35:39 -0500 Message-ID: References: <797AC075-B0C8-4269-B8E3-A1F2C69FA955@gmail.com> <14DD6D3A-B9F5-4E5F-B85B-0A8DF6961723@gmail.com> <5fd5b131-962a-489d-a674-0e199cdfff25@gutov.dev> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000005c8b22060dc7a3cf" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37732"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Yuan Fu , 68054@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Dec 31 06:36:26 2023 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 1rJoUr-0009bk-UO for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 31 Dec 2023 06:36:26 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rJoUV-0005ZB-1B; Sun, 31 Dec 2023 00:36:03 -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 1rJoUT-0005Yo-FJ for bug-gnu-emacs@gnu.org; Sun, 31 Dec 2023 00:36:01 -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 1rJoUT-0001Mz-6u for bug-gnu-emacs@gnu.org; Sun, 31 Dec 2023 00:36:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rJoUT-0006X0-PC for bug-gnu-emacs@gnu.org; Sun, 31 Dec 2023 00:36:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Noah Peart Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 31 Dec 2023 05:36:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68054 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 68054-submit@debbugs.gnu.org id=B68054.170400096025098 (code B ref 68054); Sun, 31 Dec 2023 05:36:01 +0000 Original-Received: (at 68054) by debbugs.gnu.org; 31 Dec 2023 05:36:00 +0000 Original-Received: from localhost ([127.0.0.1]:45484 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rJoUR-0006Wj-IT for submit@debbugs.gnu.org; Sun, 31 Dec 2023 00:35:59 -0500 Original-Received: from mail-oa1-x2d.google.com ([2001:4860:4864:20::2d]:46362) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rJoUP-0006WT-HE for 68054@debbugs.gnu.org; Sun, 31 Dec 2023 00:35:58 -0500 Original-Received: by mail-oa1-x2d.google.com with SMTP id 586e51a60fabf-2046dee3c14so2767369fac.1 for <68054@debbugs.gnu.org>; Sat, 30 Dec 2023 21:35:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704000950; x=1704605750; 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=Tb/pqqeHDEqikCsggvSwLgOZAgdYLc8qu8OJT0K6+4k=; b=FQ5Sa+JXwJqnPgI2V8Dh0yImG22TNd+i4Bel5JBOb2kUlAyLPj38FD8s8ZAzgdWUtx j+BDQoHCiLBBbxUOUxXXvxN9/zY97EnZdyPXCmCY5K5902cQrmgVuWHgNSuwFfyoWinz Y92bT+4PSTUGqBqSmJYx2fgf+EIa5XX4DUjYurNKI9JmGgAO9jJbKIL4TPWmkZtp3X/y wPVmonZq4SEuws4Ry9ZdmLVG2mtWHBGUJGCeTkFMi5lFnt0mTnR7w9BxhLqsA1qzHOrh hUHwyUQDmJ14/LKThbEWqY3CmrFYHonuLk4IYsIUtWJMAygpAO9wt/kqJk606qYBXxGQ yTHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704000950; x=1704605750; 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=Tb/pqqeHDEqikCsggvSwLgOZAgdYLc8qu8OJT0K6+4k=; b=fDmifxwNRTp3tKebdH+tJp6i7si3P79vRS73pz5nAohhXuatkDjyl5fET5wum4jxTz jteDmdUT2tp7UHC4WGNMv/2+c/66ETyoAmTTbAlYX2tNtnEVEoVO/5UG0PN9gj1bZ8R2 gtlmQ4hEY9wvq0eT9DW7Y3G2OfOOg+FVOgGC1sQijsLlLy5WrXkz5/9ucQGg8dZ24VSS S5YVjunK8xWRVdU3/q3PH7QkpudGJ3zClISLAsGy6Rc6/mcoO6kDUaHpnk/9eAv9xzcn ZjQYJmW73+mAGwn55UrQlxaVVu2JSL8aJE9dgAdJVzZlwPEGj4zLlF1bYr005ORyu2lG kQPA== X-Gm-Message-State: AOJu0Ywi+aayH0A0iM9J9NgiJom24Rb8fP5DCMvKeYOCt46qmqyDEtU4 xNl4eaDRh0pCGkSzdoX2ilhRhs9NJ/W+zgQb9ls= X-Google-Smtp-Source: AGHT+IFvAgPCb8qsHfj+xt/uY6Hk5CGSkFkpqEP8sAQ3qCbuDjWEXZPm3rPujyGYNmWxP4gwJ+VZs+FVdXukG+qn5Mw= X-Received: by 2002:a05:6808:169e:b0:3bb:d9c9:b927 with SMTP id bb30-20020a056808169e00b003bbd9c9b927mr3671559oib.48.1704000950666; Sat, 30 Dec 2023 21:35:50 -0800 (PST) In-Reply-To: <5fd5b131-962a-489d-a674-0e199cdfff25@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:277123 Archived-At: --0000000000005c8b22060dc7a3cf Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Yea, I agree that would be better - would you align on start the variable names, or '=3D' like `c-lineup-assignments`? On Sat, Dec 30, 2023 at 7:31=E2=80=AFPM Dmitry Gutov wro= te: > On 30/12/2023 22:31, Yuan Fu wrote: > > > >> On Dec 29, 2023, at 8:24 PM, Yuan Fu wrote: > >> > >> > >> > >>> On Dec 26, 2023, at 10:21 PM, Noah Peart > wrote: > >>> > >>> Tags: patch > >>> > >>> * Bug: `js-ts-mode` and `typescript-ts-mode` are missing indentation > >>> rules for lexical declarations that span multiple lines. > >>> > >>> Recipe to reproduce: > >>> > >>> Using the following function to configure js-ts-mode and indent the > >>> buffer: > >>> > >>> (defun try-indent () > >>> (interactive) > >>> (js-ts-mode) > >>> (setq-local indent-tabs-mode nil) > >>> (setq-local js-indent-level 4) > >>> (indent-region (point-min) (point-max))) > >>> > >>> Add the following example to a buffer and call `try-indent`. > >>> > >>> let foo =3D 1, > >>> bar =3D 2; // no indent rule matches this line > >>> > >>> No indentation is applied to the second line. > >>> > >>> This patch adds a simple indentation rules for `js-ts-mode` and > >>> `typescript-ts-mode` to handle the multi-line lexical declarations. > > It seems that js-mode indents bar to align with foo, rather than > indenting one level. I feel that we should do the same, WDYT? > > Yes, please. This also makes a difference when the variables are > declared with 'const' instead of 'let'. > > We should also support 'var' declarations: the parent node type to match > against is "variable_declaration". > --0000000000005c8b22060dc7a3cf Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Yea, I agree that would be better - would you align on sta= rt the variable names, or '=3D' like
`c-lineup-assignments`?

On Sat, Dec 30, 2023 at 7:31=E2=80=AFPM Dmitry Gutov <dmitry@gutov.dev> wrote:
On 30/12/2023 22:31, Yuan Fu wrote: >
>> On Dec 29, 2023, at 8:24 PM, Yuan Fu<casouri@gmail.com>=C2=A0 wrote:
>>
>>
>>
>>> On Dec 26, 2023, at 10:21 PM, Noah Peart<noah.v.peart@gmail.com>=C2= =A0 wrote:
>>>
>>> Tags: patch
>>>
>>> * Bug: `js-ts-mode` and `typescript-ts-mode` are missing inden= tation
>>> rules for lexical declarations that span multiple lines.
>>>
>>> Recipe to reproduce:
>>>
>>> Using the following function to configure js-ts-mode and inden= t the
>>> buffer:
>>>
>>>=C2=A0 =C2=A0 =C2=A0(defun try-indent ()
>>>=C2=A0 =C2=A0 =C2=A0 =C2=A0(interactive)
>>>=C2=A0 =C2=A0 =C2=A0 =C2=A0(js-ts-mode)
>>>=C2=A0 =C2=A0 =C2=A0 =C2=A0(setq-local indent-tabs-mode nil) >>>=C2=A0 =C2=A0 =C2=A0 =C2=A0(setq-local js-indent-level 4)
>>>=C2=A0 =C2=A0 =C2=A0 =C2=A0(indent-region (point-min) (point-ma= x)))
>>>
>>> Add the following example to a buffer and call `try-indent`. >>>
>>>=C2=A0 =C2=A0 =C2=A0let foo =3D 1,
>>>=C2=A0 =C2=A0 =C2=A0bar =3D 2; // no indent rule matches this l= ine
>>>
>>> No indentation is applied to the second line.
>>>
>>> This patch adds a simple indentation rules for `js-ts-mode` an= d
>>> `typescript-ts-mode` to handle the multi-line lexical declarat= ions.
> It seems that js-mode indents bar to align with foo, rather than inden= ting one level. I feel that we should do the same, WDYT?

Yes, please. This also makes a difference when the variables are
declared with 'const' instead of 'let'.

We should also support 'var' declarations: the parent node type to = match
against is "variable_declaration".
--0000000000005c8b22060dc7a3cf--