From 9fda4eb2738587ba9f94f56c8f07a493d73b87b1 Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Sat, 29 Mar 2025 21:15:02 -0700 Subject: [PATCH] Tighten the criteria for a defun in typescript-ts-mode (bug#77369) * lisp/progmodes/typescript-ts-mode.el: (typescript-ts-mode--defun-predicate): New function. (typescript-ts-base-mode): Use new predicate. (cherry picked from commit 651418895d507001f161e2e22ca9b85647bca19b) --- lisp/progmodes/typescript-ts-mode.el | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el index 94a854a1c8f..3162bf66500 100644 --- a/lisp/progmodes/typescript-ts-mode.el +++ b/lisp/progmodes/typescript-ts-mode.el @@ -523,6 +523,17 @@ See `treesit-thing-settings' for more information.") eos) "Settings for `treesit-defun-type-regexp'.") +(defun typescript-ts-mode--defun-predicate (node) + "Check if NODE is a defun." + (pcase (treesit-node-type node) + ("lexical_declaration" + (treesit-node-match-p + (treesit-node-child-by-field-name + (treesit-node-child node 0 'named) + "value") + "arrow_function")) + (_ t))) + (defun typescript-ts-mode--defun-name (node) "Return the defun name of NODE. Return nil if there is no name or if NODE is not a defun node." @@ -571,7 +582,9 @@ This mode is intended to be inherited by concrete major modes." (setq-local electric-indent-chars (append "{}():;,<>/" electric-indent-chars)) ;; Navigation. - (setq-local treesit-defun-type-regexp typescript-ts-mode--defun-type-regexp) + (setq-local treesit-defun-type-regexp + (cons typescript-ts-mode--defun-type-regexp + #'typescript-ts-mode--defun-predicate)) (setq-local treesit-defun-name-function #'typescript-ts-mode--defun-name) (setq-local treesit-thing-settings -- 2.39.5