GNU bug report logs - #67488
[PATCH] Fix typescript-ts-mode indentation for switch statements

Previous Next

Package: emacs;

Reported by: Noah Peart <noah.v.peart <at> gmail.com>

Date: Mon, 27 Nov 2023 17:09:01 UTC

Severity: normal

Tags: patch

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 67488 in the body.
You can then email your comments to 67488 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#67488; Package emacs. (Mon, 27 Nov 2023 17:09:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Noah Peart <noah.v.peart <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 27 Nov 2023 17:09:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Noah Peart <noah.v.peart <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] Fix typescript-ts-mode indentation for switch statements
Date: Mon, 27 Nov 2023 09:07:51 -0800
[Message part 1 (text/plain, inline)]
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'
[Message part 2 (text/html, inline)]
[typescript-ts-mode-switch-indentation.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#67488; Package emacs. (Tue, 28 Nov 2023 00:40:02 GMT) Full text and rfc822 format available.

Message #8 received at 67488 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dmitry <at> gutov.dev>
To: Noah Peart <noah.v.peart <at> gmail.com>, 67488 <at> debbugs.gnu.org
Subject: Re: bug#67488: [PATCH] Fix typescript-ts-mode indentation for switch
 statements
Date: Tue, 28 Nov 2023 02:39:02 +0200
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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#67488; Package emacs. (Tue, 28 Nov 2023 05:55:01 GMT) Full text and rfc822 format available.

Message #11 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Cc: theo <at> thornhill.no
Subject: Re: bug#67488: [PATCH] Fix typescript-ts-mode indentation for switch
 statements
Date: Mon, 27 Nov 2023 21:53:49 -0800

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




Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Wed, 29 Nov 2023 14:36:02 GMT) Full text and rfc822 format available.

Notification sent to Noah Peart <noah.v.peart <at> gmail.com>:
bug acknowledged by developer. (Wed, 29 Nov 2023 14:36:02 GMT) Full text and rfc822 format available.

Message #16 received at 67488-done <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Yuan Fu <casouri <at> gmail.com>, Noah Peart <noah.v.peart <at> gmail.com>
Cc: theo <at> thornhill.no, 67488-done <at> debbugs.gnu.org
Subject: Re: bug#67488: [PATCH] Fix typescript-ts-mode indentation for switch
 statements
Date: Wed, 29 Nov 2023 16:35:06 +0200
> Cc: theo <at> thornhill.no
> Date: Mon, 27 Nov 2023 21:53:49 -0800
> From: Yuan Fu <casouri <at> 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.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 28 Dec 2023 12:24:08 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 135 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.