all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#68054: [PATCH] Add tree-sitter indent rule for lexical decls in js/typescript
@ 2023-12-27  6:21 Noah Peart
  2023-12-30  4:24 ` Yuan Fu
  0 siblings, 1 reply; 20+ messages in thread
From: Noah Peart @ 2023-12-27  6:21 UTC (permalink / raw)
  To: 68054


[-- Attachment #1.1: Type: text/plain, Size: 1367 bytes --]

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 = 1,
    bar = 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.


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-12-26 built on nverno-XPS-8940
Repository revision: d376462c7183752bf44b9bd20bf5020fe7eaf75a
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: 1551 bytes --]

[-- Attachment #2: js-ts-indent-decls.patch --]
[-- Type: text/x-patch, Size: 2072 bytes --]

From 4c2793fcdb1199253396511a13c13519c76bb817 Mon Sep 17 00:00:00 2001
From: Noah Peart <noah.v.peart@gmail.com>
Date: Wed, 27 Dec 2023 00:50:46 -0500
Subject: [PATCH] Add tree-sitter indent rule for lexical decls in
 js/typescript

* lisp/progmodes/typescript-ts-mode.el
(typescript-ts-mode--indent-rules): Add indent rule for
lexical_declarations.

* lisp/progmodes/js.el (js--treesit-indent-rules): Add indent rule
for lexical_declarations.
---
 lisp/progmodes/js.el                 | 1 +
 lisp/progmodes/typescript-ts-mode.el | 1 +
 2 files changed, 2 insertions(+)

diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 61bd94222ac..935655f779f 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3449,6 +3449,7 @@ js--treesit-indent-rules
        ((parent-is "named_imports") parent-bol js-indent-level)
        ((parent-is "statement_block") parent-bol js-indent-level)
        ((parent-is "variable_declarator") parent-bol js-indent-level)
+       ((parent-is "lexical_declaration") parent-bol js-indent-level)
        ((parent-is "arguments") parent-bol js-indent-level)
        ((parent-is "array") parent-bol js-indent-level)
        ((parent-is "formal_parameters") parent-bol js-indent-level)
diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el
index 7f0b7236301..a0f6e7c9501 100644
--- a/lisp/progmodes/typescript-ts-mode.el
+++ b/lisp/progmodes/typescript-ts-mode.el
@@ -114,6 +114,7 @@ typescript-ts-mode--indent-rules
      ((parent-is "switch_default") parent-bol typescript-ts-mode-indent-offset)
      ((parent-is "type_arguments") parent-bol typescript-ts-mode-indent-offset)
      ((parent-is "variable_declarator") parent-bol typescript-ts-mode-indent-offset)
+     ((parent-is "lexical_declaration") parent-bol typescript-ts-mode-indent-offset)
      ((parent-is "arguments") parent-bol typescript-ts-mode-indent-offset)
      ((parent-is "array") parent-bol typescript-ts-mode-indent-offset)
      ((parent-is "formal_parameters") parent-bol typescript-ts-mode-indent-offset)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2024-06-09  6:15 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-27  6:21 bug#68054: [PATCH] Add tree-sitter indent rule for lexical decls in js/typescript Noah Peart
2023-12-30  4:24 ` Yuan Fu
2023-12-30 20:31   ` Yuan Fu
2023-12-31  0:31     ` Dmitry Gutov
2023-12-31  5:35       ` Noah Peart
2023-12-31 13:41         ` Dmitry Gutov
2024-01-01  4:56           ` Yuan Fu
2024-04-17 20:21             ` Noah Peart
2024-04-23  5:07               ` Yuan Fu
2024-04-24  0:15                 ` Dmitry Gutov
2024-04-24  2:36                   ` Noah Peart
2024-04-24 23:15                     ` Dmitry Gutov
2024-04-25 22:48                       ` Noah Peart
2024-04-26  1:06                         ` Dmitry Gutov
2024-05-02 13:26                           ` Noah Peart
2024-05-02 13:38                             ` Noah Peart
2024-05-18  8:29                               ` Eli Zaretskii
2024-06-09  2:52                               ` Dmitry Gutov
2024-06-09  2:48                             ` Dmitry Gutov
2024-06-09  6:15                               ` Eli Zaretskii

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.