* bug#67488: [PATCH] Fix typescript-ts-mode indentation for switch statements
@ 2023-11-27 17:07 Noah Peart
2023-11-28 0:39 ` Dmitry Gutov
0 siblings, 1 reply; 4+ messages in thread
From: Noah Peart @ 2023-11-27 17:07 UTC (permalink / raw)
To: 67488
[-- Attachment #1.1: Type: text/plain, Size: 1672 bytes --]
Tags: patch
* lisp/progmodes/typescript-ts-mode.el(typescript-ts-mode): Add indentation
rule for switch case and default keywords.
Bug: `typescript-ts-mode` is missing indentation rules for 'case' and
'default' keywords in switch statements.
Recipe to reproduce:
Copy the following code into a buffer:
const foo = (x: string) => {
switch (x) {
case "a":
console.log(x);
return 1;
case "b":
return 2;
case "c":
default:
return 0;
}
};
And call the following function to configure typescript-ts-mode and
indent the buffer
(defun my-ts-indentation ()
(interactive)
(setq indent-tabs-mode nil)
(setq typescript-ts-mode-indent-offset 2)
(typescript-ts-mode)
(indent-region (point-min) (point-max)))
The indentation for the 'case' and 'default' branches within the switch
statement should still be unchanged due to missing indent rules.
Bug applies to emacs 29 as well.
In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
3.24.33, cairo version 1.16.0) of 2023-11-27 built on noah-X580VD
Repository revision: 76cf700ecb78cb465bcd05ae2b2fb0d28e4d0aed
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101004
System Description: Ubuntu 22.04.3 LTS
Configured using:
'configure --prefix=/usr/local --with-modules --with-tree-sitter
--with-threads --with-x-toolkit=gtk3 --with-xwidgets --with-gnutls
--with-json --with-mailutils --with-jpeg --with-png --with-rsvg
--with-tiff --with-xml2 --with-xpm --with-imagemagick CC=gcc-12
CXX=gcc-12'
[-- Attachment #1.2: Type: text/html, Size: 2027 bytes --]
[-- Attachment #2: typescript-ts-mode-switch-indentation.patch --]
[-- Type: text/x-patch, Size: 2030 bytes --]
From 97cbae39562233a6eb9f2393ad6556b8409a7eaa Mon Sep 17 00:00:00 2001
From: nverno <noah.v.peart@gmail.com>
Date: Mon, 27 Nov 2023 08:55:23 -0800
Subject: [PATCH] Fix typescript-ts-mode indentation for switch statements
* lisp/progmodes/typescript-ts-mode.el(typescript-ts-mode): Add indentation
rule for switch case and default keywords.
---
lisp/progmodes/typescript-ts-mode.el | 3 +++
.../typescript-ts-mode-resources/indent.erts | 17 +++++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el
index 0503c724d36..7998b3740b6 100644
--- a/lisp/progmodes/typescript-ts-mode.el
+++ b/lisp/progmodes/typescript-ts-mode.el
@@ -107,6 +107,9 @@ typescript-ts-mode--indent-rules
((parent-is "member_expression") parent-bol typescript-ts-mode-indent-offset)
((parent-is "named_imports") parent-bol typescript-ts-mode-indent-offset)
((parent-is "statement_block") parent-bol typescript-ts-mode-indent-offset)
+ ((or (node-is "case")
+ (node-is "default"))
+ parent-bol typescript-ts-mode-indent-offset)
((parent-is "switch_case") parent-bol typescript-ts-mode-indent-offset)
((parent-is "switch_default") parent-bol typescript-ts-mode-indent-offset)
((parent-is "type_arguments") parent-bol typescript-ts-mode-indent-offset)
diff --git a/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts b/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts
index 20f423259b4..7b6185e0386 100644
--- a/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts
+++ b/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts
@@ -45,6 +45,23 @@ const foo = () => {
};
=-=-=
+Name: Switch statement
+
+=-=
+const foo = (x: string) => {
+ switch (x) {
+ case "a":
+ console.log(x);
+ return 1;
+ case "b":
+ return 2;
+ case "c":
+ default:
+ return 0;
+ }
+};
+=-=-=
+
Code:
(lambda ()
(setq indent-tabs-mode nil)
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* bug#67488: [PATCH] Fix typescript-ts-mode indentation for switch statements
2023-11-27 17:07 bug#67488: [PATCH] Fix typescript-ts-mode indentation for switch statements Noah Peart
@ 2023-11-28 0:39 ` Dmitry Gutov
2023-11-28 5:53 ` Yuan Fu
0 siblings, 1 reply; 4+ messages in thread
From: Dmitry Gutov @ 2023-11-28 0:39 UTC (permalink / raw)
To: Noah Peart, 67488
On 27/11/2023 19:07, Noah Peart wrote:
> Tags: patch
>
> * lisp/progmodes/typescript-ts-mode.el(typescript-ts-mode): Add indentation
> rule for switch case and default keywords.
>
> Bug: `typescript-ts-mode` is missing indentation rules for 'case' and
> 'default' keywords in switch statements.
>
> Recipe to reproduce:
> Copy the following code into a buffer:
>
> const foo = (x: string) => {
> switch (x) {
> case "a":
> console.log(x);
> return 1;
> case "b":
> return 2;
> case "c":
> default:
> return 0;
> }
> };
>
> And call the following function to configure typescript-ts-mode and
> indent the buffer
>
> (defun my-ts-indentation ()
> (interactive)
> (setq indent-tabs-mode nil)
> (setq typescript-ts-mode-indent-offset 2)
> (typescript-ts-mode)
> (indent-region (point-min) (point-max)))
>
> The indentation for the 'case' and 'default' branches within the switch
> statement should still be unchanged due to missing indent rules.
> Bug applies to emacs 29 as well.
Thanks! Can repro. The fix looks good as well.
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#67488: [PATCH] Fix typescript-ts-mode indentation for switch statements
2023-11-28 0:39 ` Dmitry Gutov
@ 2023-11-28 5:53 ` Yuan Fu
2023-11-29 14:35 ` Eli Zaretskii
0 siblings, 1 reply; 4+ messages in thread
From: Yuan Fu @ 2023-11-28 5:53 UTC (permalink / raw)
To: 67488; +Cc: theo
On 11/27/23 4:39 PM, Dmitry Gutov wrote:
> On 27/11/2023 19:07, Noah Peart wrote:
>> Tags: patch
>>
>> * lisp/progmodes/typescript-ts-mode.el(typescript-ts-mode): Add
>> indentation
>> rule for switch case and default keywords.
>>
>> Bug: `typescript-ts-mode` is missing indentation rules for 'case' and
>> 'default' keywords in switch statements.
>>
>> Recipe to reproduce:
>> Copy the following code into a buffer:
>>
>> const foo = (x: string) => {
>> switch (x) {
>> case "a":
>> console.log(x);
>> return 1;
>> case "b":
>> return 2;
>> case "c":
>> default:
>> return 0;
>> }
>> };
>>
>> And call the following function to configure typescript-ts-mode and
>> indent the buffer
>>
>> (defun my-ts-indentation ()
>> (interactive)
>> (setq indent-tabs-mode nil)
>> (setq typescript-ts-mode-indent-offset 2)
>> (typescript-ts-mode)
>> (indent-region (point-min) (point-max)))
>>
>> The indentation for the 'case' and 'default' branches within the switch
>> statement should still be unchanged due to missing indent rules.
>> Bug applies to emacs 29 as well.
>
> Thanks! Can repro. The fix looks good as well.
>
LGTM. The only thing I'll add is that you can probably use a single
regular expression rather than using the "or" matcher. But that's
largely personal preference.
Yuan
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#67488: [PATCH] Fix typescript-ts-mode indentation for switch statements
2023-11-28 5:53 ` Yuan Fu
@ 2023-11-29 14:35 ` Eli Zaretskii
0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2023-11-29 14:35 UTC (permalink / raw)
To: Yuan Fu, Noah Peart; +Cc: theo, 67488-done
> Cc: theo@thornhill.no
> Date: Mon, 27 Nov 2023 21:53:49 -0800
> From: Yuan Fu <casouri@gmail.com>
>
> > Thanks! Can repro. The fix looks good as well.
> >
> LGTM. The only thing I'll add is that you can probably use a single
> regular expression rather than using the "or" matcher. But that's
> largely personal preference.
Thanks, installed on the emacs-29 branch and closing the bug.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-11-29 14:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-27 17:07 bug#67488: [PATCH] Fix typescript-ts-mode indentation for switch statements Noah Peart
2023-11-28 0:39 ` Dmitry Gutov
2023-11-28 5:53 ` Yuan Fu
2023-11-29 14:35 ` Eli Zaretskii
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).