Subject: bug#67031: [PATCH] Fix typescript-ts-mode indentation in unbracketed statements

From: nvp <[email-masked]>
Date: Thu, 9 Nov 2023 17:29:21 -0800

Tags: patch

* lisp/progmodes/typescript-ts-mode.el
(typescript-ts-mode--indent-rules): fix indentation after statements
without brackets

Bug: There are no indentation rules for statement bodies following
if/for/for_in/do/while statements without brackets.

Recipe to reproduce:
In a `typescript-ts-mode` buffer with the following code,

    if (true)
    console.log('No indent here')

Try to indent the second line.

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-05 built on noah-X580VD
Repository revision: b819b8d6e90337b4cb36b35c2c6d0112c90a8e24
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'
From 2014793a7ca370f25978a3d0bd6ac6fdb2fb2ca9 Mon Sep 17 00:00:00 2001
From: nverno <[email-masked]>
Date: Thu, 9 Nov 2023 17:19:34 -0800
Subject: [PATCH] Fix typescript-ts-mode indentation in unbracketed statements

---
 lisp/progmodes/typescript-ts-mode.el | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el
index b976145dbf3..e671ad5d2d7 100644
--- a/lisp/progmodes/typescript-ts-mode.el
+++ b/lisp/progmodes/typescript-ts-mode.el
@@ -124,6 +124,10 @@ 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 (seq (or "if" "for" "for_in" "while" "do") "_statement")))
+      parent-bol typescript-ts-mode-indent-offset)
 
      ,@(when (eq language 'tsx)
 	 (append (tsx-ts-mode--indent-compatibility-b893426)
-- 
2.34.1