From: Noah Peart <noah.v.peart@gmail.com>
To: Dmitry Gutov <dmitry@gutov.dev>
Cc: Eli Zaretskii <eliz@gnu.org>, 67031@debbugs.gnu.org, casouri@gmail.com
Subject: bug#67031: [PATCH] Fix typescript-ts-mode indentation in unbracketed statements
Date: Mon, 20 Nov 2023 10:13:23 -0800 [thread overview]
Message-ID: <CAPVBTSfdRrjtayk8q0kRHob_a3rBFaX6yjzSbi16nw3kp75vyw@mail.gmail.com> (raw)
In-Reply-To: <CAPVBTScnQFEvhiSc5Thp3ApRQzUgKyupHBMKEbgUoFAEitoFmA@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 1670 bytes --]
Sorry, ignore the previous patch. A couple additional rules were needed to
handle
"while" and "else".
On Mon, Nov 20, 2023 at 10:07 AM Noah Peart <noah.v.peart@gmail.com> wrote:
> Here is an updated patch with the added "else_clause" and indentation test
> for
> statements without braces.
>
> On Mon, Nov 20, 2023 at 4:55 AM Noah Peart <noah.v.peart@gmail.com> wrote:
>
>> Yea, I'm using the same. But, would it be useful to have a way to set
>> that when
>> running tests without needing to temporarily add set
>> `treesit-extra-load-path` in
>> the test file?
>>
>> On Sun, Nov 19, 2023 at 5:38 AM Dmitry Gutov <dmitry@gutov.dev> wrote:
>>
>>> On 19/11/2023 08:08, Eli Zaretskii wrote:
>>> >> Date: Sun, 19 Nov 2023 03:24:49 +0200
>>> >> Cc:casouri@gmail.com,67031@debbugs.gnu.org
>>> >> From: Dmitry Gutov<dmitry@gutov.dev>
>>> >>
>>> >> On 19/11/2023 02:12, Noah Peart wrote:
>>> >>> Yea, I can do that.
>>> >>>
>>> >>> Is there a recipe for running the tests with a tree-sitter library
>>> path?
>>> >> You mean with the default tree-sitter librayr path overridden? I'm
>>> not sure.
>>> > Why would an ERT test need that? We are supposed to test Emacs with
>>> > the otherwise installed system features. As tree-sitter grammars are
>>> > not part of Emacs, there should be no need to tell Emacs to use a
>>> > grammar library other than the one installed on the system. Right?
>>>
>>> We have a way to override that with the variable
>>> treesit-extra-load-path, so it follows that some users will take
>>> advantage of it to add extra directories.
>>>
>>> I'm using ~/.emacs.d/tree-sitter/ myself.
>>>
>>
[-- Attachment #1.2: Type: text/html, Size: 2825 bytes --]
[-- Attachment #2: typescript-ts-mode-indentation.patch --]
[-- Type: text/x-patch, Size: 2188 bytes --]
From 2628e92f6c55fb69d9f504caee1e1b105e30e01a Mon Sep 17 00:00:00 2001
From: nverno <noah.v.peart@gmail.com>
Date: Mon, 20 Nov 2023 10:04:51 -0800
Subject: [PATCH] Fix typescript-ts-mode indentation in statements without
braces
---
lisp/progmodes/typescript-ts-mode.el | 5 +++++
.../typescript-ts-mode-resources/indent.erts | 22 +++++++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el
index b976145dbf3..b6d5495adbb 100644
--- a/lisp/progmodes/typescript-ts-mode.el
+++ b/lisp/progmodes/typescript-ts-mode.el
@@ -124,6 +124,11 @@ typescript-ts-mode--indent-rules
((parent-is "arrow_function") parent-bol typescript-ts-mode-indent-offset)
((parent-is "parenthesized_expression") parent-bol typescript-ts-mode-indent-offset)
((parent-is "binary_expression") parent-bol typescript-ts-mode-indent-offset)
+ ((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")
+ "else_clause")))
+ parent-bol typescript-ts-mode-indent-offset)
,@(when (eq language 'tsx)
(append (tsx-ts-mode--indent-compatibility-b893426)
diff --git a/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts b/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts
index 146ee76574e..20f423259b4 100644
--- a/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts
+++ b/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts
@@ -23,6 +23,28 @@ const foo = () => {
}
=-=-=
+Name: Statement indentation without braces
+
+=-=
+const foo = () => {
+ if (true)
+ console.log("if_statement");
+ else if (false)
+ console.log("if_statement");
+ else
+ console.log("else_clause");
+ for (let i = 0; i < 1; i++)
+ console.log("for_statement");
+ for (let i of [true])
+ console.log("for_in_statement");
+ while (false)
+ console.log("while_statement");
+ do
+ console.log("do_statement");
+ while (false)
+};
+=-=-=
+
Code:
(lambda ()
(setq indent-tabs-mode nil)
--
2.34.1
next prev parent reply other threads:[~2023-11-20 18:13 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-10 1:29 bug#67031: [PATCH] Fix typescript-ts-mode indentation in unbracketed statements nvp
2023-11-15 13:40 ` Eli Zaretskii
2023-11-16 1:18 ` Dmitry Gutov
2023-11-18 10:05 ` Eli Zaretskii
2023-11-19 0:12 ` Noah Peart
2023-11-19 1:24 ` Dmitry Gutov
2023-11-19 6:08 ` Eli Zaretskii
2023-11-19 7:19 ` Noah Peart
2023-11-19 13:38 ` Dmitry Gutov
2023-11-20 12:55 ` Noah Peart
2023-11-20 18:07 ` Noah Peart
2023-11-20 18:13 ` Noah Peart [this message]
2023-11-20 22:28 ` Dmitry Gutov
2023-11-21 3:27 ` Eli Zaretskii
2023-11-21 4:41 ` Noah Peart
2023-11-21 11:44 ` Eli Zaretskii
2023-11-21 14:09 ` Dmitry Gutov
2023-11-21 14:23 ` Eli Zaretskii
2023-11-21 14:27 ` Dmitry Gutov
2023-11-25 3:46 ` Yuan Fu
2023-11-25 3:48 ` Yuan Fu
2023-11-19 4:26 ` Yuan Fu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAPVBTSfdRrjtayk8q0kRHob_a3rBFaX6yjzSbi16nw3kp75vyw@mail.gmail.com \
--to=noah.v.peart@gmail.com \
--cc=67031@debbugs.gnu.org \
--cc=casouri@gmail.com \
--cc=dmitry@gutov.dev \
--cc=eliz@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.