Subject: bug#75422: 30.0.93; [PATCH] forward-sexp and backward-sexp jump outside of comments in tsx-ts-mode

From: Kohei Tsuruta <[email-masked]>
Date: Tue, 07 Jan 2025 08:02:02 -0800

Steps to reproduce
- emacs -Q test.tsx
- (tsx-ts-mode)
- Move point at the end of the comment at line 3
- (backward-sexp)

The expected point position after (backward-sexp) is "treesit-thing-|settings"
or at least stay inside of the comment line, however, point moves to the
beginning of "Hello".
Likewise, if you C-x C-e at the end of the comment line, it evaluates "Hello".

--- test.tsx (| is point) ---
export const App = () => {
  const greeting = "Hello"
  // treesit-thing-settings|
  return <>{greeting}</>
}
--- END test.tsx ---

It happens because tsx-ts-mode doesn't recognize comments. In
typescript-ts-base-mode, treesit-thing-settings is set to have "text" as
a thing for typescript but it's missing in tsx-ts-mode when it's set for
tsx.

>From d1c5aa45213e4011dfb641edb0d064e5d02e370d Mon Sep 17 00:00:00 2001
From: Kohei Tsuruta <[email-masked]>
Date: Tue, 7 Jan 2025 07:36:14 -0800
Subject: [PATCH] Add "text" as a thing in tsx-ts-mode

* lisp/progmodes/typescript-ts-mode.el (tsx-ts-mode):
Add definition of "text"
---
 lisp/progmodes/typescript-ts-mode.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el
index 4a38d1da596..0ffcb144771 100644
--- a/lisp/progmodes/typescript-ts-mode.el
+++ b/lisp/progmodes/typescript-ts-mode.el
@@ -564,7 +564,9 @@ tsx-ts-mode
                    (sentence ,(regexp-opt
                                (append typescript-ts-mode--sentence-nodes
                                        '("jsx_element"
-                                         "jsx_self_closing_element")))))))
+                                         "jsx_self_closing_element"))))
+                   (text ,(regexp-opt '("comment"
+                                        "template_string"))))))
 
     ;; Font-lock.
     (setq-local treesit-font-lock-settings
-- 
2.39.5 (Apple Git-154)

In GNU Emacs 30.0.93 (build 3, aarch64-apple-darwin24.1.0, NS
 appkit-2575.20 Version 15.1.1 (Build 24B91)) of 2025-01-05 built on
 mac.lan
Repository revision: 505c1123e18a8a710fc60e05a4c870497bf580f4
Repository branch: emacs-30
System Description:  macOS 15.1.1

Configured using:
 'configure --with-native-compilation --disable-ns-self-contained
 --with-tree-sitter'

Configured features:
ACL GNUTLS LIBXML2 MODULES NATIVE_COMP NOTIFY KQUEUE NS PDUMPER SQLITE3
THREADS TOOLKIT_SCROLL_BARS TREE_SITTER ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: ELisp/l

Minor modes in effect:
  bug-reference-prog-mode: t
  paredit-mode: t
  rainbow-delimiters-mode: t
  whitespace-mode: t
  which-function-mode: t
  corfu-terminal-mode: t
  corfu-history-mode: t
  global-corfu-mode: t
  corfu-mode: t
  marginalia-mode: t
  vertico-mode: t
  savehist-mode: t
  recentf-mode: t
  winner-mode: t
  repeat-mode: t
  save-place-mode: t
  delete-selection-mode: t
  electric-pair-mode: t
  minibuffer-depth-indicate-mode: t
  override-global-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  minibuffer-regexp-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort emacsbug mail-extr ispell log-edit message sendmail
yank-media puny dired dired-loaddefs rfc822 mml mml-sec epa derived epg
rfc6068 epg-config gnus-util mm-decode mm-bodies mm-encode mail-parse
rfc2231 rfc2047 rfc2045 mm-util ietf-drums mail-prsvr mailabbrev
mail-utils gmm-utils mailheader pcvs-util vc consult-imenu help-fns
radix-tree cl-print debug backtrace find-func dabbrev vertico-directory
c++-ts-mode c-ts-mode js c-ts-common treesit cc-mode cc-fonts cc-guess
cc-menus cc-cmds cc-styles cc-align cc-engine cc-vars cc-defs time-date
misearch multi-isearch vc-git diff-mode track-changes vc-dispatcher
bug-reference descr-text grep embark-consult embark ffap texinfo
texinfo-loaddefs files-x consult bookmark pp add-log term/xterm xterm
paredit cape rainbow-delimiters disp-table whitespace merge-n-save
flymake project compile text-property-search comint ansi-osc ansi-color
thingatpt which-func imenu corfu-terminal popon corfu-history corfu
orderless marginalia vertico compat savehist recentf tree-widget
wid-edit winner ring repeat saveplace delsel elec-pair finder-inf
solarized-light-theme solarized-theme solarized solarized-faces color
edmacro kmacro mb-depth delight comp comp-cstr warnings comp-run
comp-common rx cl-extra help-mode use-package use-package-ensure
use-package-delight use-package-diminish use-package-bind-key bind-key
easy-mmode use-package-core avy-autoloads cape-autoloads
corfu-terminal-autoloads corfu-autoloads delight-autoloads
dumb-jump-autoloads dash-autoloads embark-consult-autoloads
consult-autoloads embark-autoloads exec-path-from-shell-autoloads
expand-region-autoloads marginalia-autoloads markdown-mode-autoloads
info orderless-autoloads paredit-autoloads popon-autoloads
popup-autoloads rainbow-delimiters-autoloads s-autoloads
solarized-theme-autoloads vertico-autoloads package browse-url url
url-proxy url-privacy url-expand url-methods url-history url-cookie
generate-lisp-file url-domsuf url-util mailcap url-handlers url-parse
auth-source cl-seq eieio eieio-core cl-macs icons password-cache json
subr-x map byte-opt gv bytecomp byte-compile url-vars cl-loaddefs cl-lib
rmc iso-transl tooltip cconv eldoc paren electric uniquify ediff-hook
vc-hooks lisp-float-type elisp-mode mwheel term/ns-win ns-win
ucs-normalize mule-util term/common-win tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu
timer select scroll-bar mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads kqueue cocoa ns multi-tty
make-network-process native-compile emacs)

Memory information:
((conses 16 334937 64735) (symbols 48 32870 14)
 (strings 32 126791 4029) (string-bytes 1 4022076) (vectors 16 34459)
 (vector-slots 8 436900 32986) (floats 8 362 7583)
 (intervals 56 3954 480) (buffers 992 27))