diff options
| author | Yuan Fu | 2025-03-29 21:15:02 -0700 |
|---|---|---|
| committer | Yuan Fu | 2025-03-29 21:18:24 -0700 |
| commit | 651418895d507001f161e2e22ca9b85647bca19b (patch) | |
| tree | 3b9a6d9cee413321c5344b14d3b04a639a3ea3b7 | |
| parent | e1b15d58b508da279162c585b6b3783f9e267427 (diff) | |
| download | emacs-651418895d507001f161e2e22ca9b85647bca19b.tar.gz emacs-651418895d507001f161e2e22ca9b85647bca19b.zip | |
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.
| -rw-r--r-- | lisp/progmodes/typescript-ts-mode.el | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el index 9051a841887..bc4b635735f 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.") | |||
| 523 | eos) | 523 | eos) |
| 524 | "Settings for `treesit-defun-type-regexp'.") | 524 | "Settings for `treesit-defun-type-regexp'.") |
| 525 | 525 | ||
| 526 | (defun typescript-ts-mode--defun-predicate (node) | ||
| 527 | "Check if NODE is a defun." | ||
| 528 | (pcase (treesit-node-type node) | ||
| 529 | ("lexical_declaration" | ||
| 530 | (treesit-node-match-p | ||
| 531 | (treesit-node-child-by-field-name | ||
| 532 | (treesit-node-child node 0 'named) | ||
| 533 | "value") | ||
| 534 | "arrow_function")) | ||
| 535 | (_ t))) | ||
| 536 | |||
| 526 | (defun typescript-ts-mode--defun-name (node) | 537 | (defun typescript-ts-mode--defun-name (node) |
| 527 | "Return the defun name of NODE. | 538 | "Return the defun name of NODE. |
| 528 | Return nil if there is no name or if NODE is not a defun node." | 539 | Return nil if there is no name or if NODE is not a defun node." |
| @@ -573,7 +584,9 @@ This mode is intended to be inherited by concrete major modes." | |||
| 573 | (setq-local electric-layout-rules | 584 | (setq-local electric-layout-rules |
| 574 | '((?\; . after) (?\{ . after) (?\} . before))) | 585 | '((?\; . after) (?\{ . after) (?\} . before))) |
| 575 | ;; Navigation. | 586 | ;; Navigation. |
| 576 | (setq-local treesit-defun-type-regexp typescript-ts-mode--defun-type-regexp) | 587 | (setq-local treesit-defun-type-regexp |
| 588 | (cons typescript-ts-mode--defun-type-regexp | ||
| 589 | #'typescript-ts-mode--defun-predicate)) | ||
| 577 | (setq-local treesit-defun-name-function #'typescript-ts-mode--defun-name) | 590 | (setq-local treesit-defun-name-function #'typescript-ts-mode--defun-name) |
| 578 | 591 | ||
| 579 | (setq-local treesit-thing-settings | 592 | (setq-local treesit-thing-settings |