diff options
| author | Theodor Thornhill | 2023-01-21 14:47:34 +0100 |
|---|---|---|
| committer | Theodor Thornhill | 2023-01-21 14:47:34 +0100 |
| commit | 2bf0ad3be6bec22471c5b32548da99d6eb63da58 (patch) | |
| tree | bcc7ebc54e4b9f211a692eae544557f25d719e97 | |
| parent | f55bbc6898898c4b5457e6952b0ae9b5c8c42423 (diff) | |
| download | emacs-2bf0ad3be6bec22471c5b32548da99d6eb63da58.tar.gz emacs-2bf0ad3be6bec22471c5b32548da99d6eb63da58.zip | |
Add sexp navigation to js/typescript/tsx-ts-mode
* lisp/progmodes/js.el (js--treesit-sexp-nodes): Add node types.
(js-ts-mode): Set 'treesit-sexp-type-regexp'.
* lisp/progmodes/typescript-ts-mode.el
(typescript-ts-mode--sexp-nodes): Add node types.
* lisp/progmodes/typescript-ts-mode.el (typescript-ts-base-mode): Set
'treesit-sexp-type-regexp'.
(tsx-ts-mode): Add in jsx nodes.
| -rw-r--r-- | lisp/progmodes/js.el | 26 | ||||
| -rw-r--r-- | lisp/progmodes/typescript-ts-mode.el | 30 |
2 files changed, 56 insertions, 0 deletions
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index 28305a0b39b..6f3746ca72a 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el | |||
| @@ -3817,6 +3817,29 @@ Currently there are `js-mode' and `js-ts-mode'." | |||
| 3817 | "Nodes that designate sentences in JavaScript. | 3817 | "Nodes that designate sentences in JavaScript. |
| 3818 | See `treesit-sentence-type-regexp' for more information.") | 3818 | See `treesit-sentence-type-regexp' for more information.") |
| 3819 | 3819 | ||
| 3820 | (defvar js--treesit-sexp-nodes | ||
| 3821 | '("expression" | ||
| 3822 | "pattern" | ||
| 3823 | "array" | ||
| 3824 | "function" | ||
| 3825 | "string" | ||
| 3826 | "escape" | ||
| 3827 | "template" | ||
| 3828 | "regex" | ||
| 3829 | "number" | ||
| 3830 | "identifier" | ||
| 3831 | "this" | ||
| 3832 | "super" | ||
| 3833 | "true" | ||
| 3834 | "false" | ||
| 3835 | "null" | ||
| 3836 | "undefined" | ||
| 3837 | "arguments" | ||
| 3838 | "pair" | ||
| 3839 | "jsx") | ||
| 3840 | "Nodes that designate sexps in JavaScript. | ||
| 3841 | See `treesit-sexp-type-regexp' for more information.") | ||
| 3842 | |||
| 3820 | ;;;###autoload | 3843 | ;;;###autoload |
| 3821 | (define-derived-mode js-ts-mode js-base-mode "JavaScript" | 3844 | (define-derived-mode js-ts-mode js-base-mode "JavaScript" |
| 3822 | "Major mode for editing JavaScript. | 3845 | "Major mode for editing JavaScript. |
| @@ -3860,6 +3883,9 @@ See `treesit-sentence-type-regexp' for more information.") | |||
| 3860 | (setq-local treesit-sentence-type-regexp | 3883 | (setq-local treesit-sentence-type-regexp |
| 3861 | (regexp-opt js--treesit-sentence-nodes)) | 3884 | (regexp-opt js--treesit-sentence-nodes)) |
| 3862 | 3885 | ||
| 3886 | (setq-local treesit-sexp-type-regexp | ||
| 3887 | (regexp-opt js--treesit-sexp-nodes)) | ||
| 3888 | |||
| 3863 | ;; Fontification. | 3889 | ;; Fontification. |
| 3864 | (setq-local treesit-font-lock-settings js--treesit-font-lock-settings) | 3890 | (setq-local treesit-font-lock-settings js--treesit-font-lock-settings) |
| 3865 | (setq-local treesit-font-lock-feature-list | 3891 | (setq-local treesit-font-lock-feature-list |
diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el index f7bf7ed7e42..69e4746bcc4 100644 --- a/lisp/progmodes/typescript-ts-mode.el +++ b/lisp/progmodes/typescript-ts-mode.el | |||
| @@ -338,6 +338,28 @@ Argument LANGUAGE is either `typescript' or `tsx'." | |||
| 338 | "Nodes that designate sentences in TypeScript. | 338 | "Nodes that designate sentences in TypeScript. |
| 339 | See `treesit-sentence-type-regexp' for more information.") | 339 | See `treesit-sentence-type-regexp' for more information.") |
| 340 | 340 | ||
| 341 | (defvar typescript-ts-mode--sexp-nodes | ||
| 342 | '("expression" | ||
| 343 | "pattern" | ||
| 344 | "array" | ||
| 345 | "function" | ||
| 346 | "string" | ||
| 347 | "escape" | ||
| 348 | "template" | ||
| 349 | "regex" | ||
| 350 | "number" | ||
| 351 | "identifier" | ||
| 352 | "this" | ||
| 353 | "super" | ||
| 354 | "true" | ||
| 355 | "false" | ||
| 356 | "null" | ||
| 357 | "undefined" | ||
| 358 | "arguments" | ||
| 359 | "pair") | ||
| 360 | "Nodes that designate sexps in TypeScript. | ||
| 361 | See `treesit-sexp-type-regexp' for more information.") | ||
| 362 | |||
| 341 | ;;;###autoload | 363 | ;;;###autoload |
| 342 | (add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-ts-mode)) | 364 | (add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-ts-mode)) |
| 343 | 365 | ||
| @@ -373,6 +395,9 @@ See `treesit-sentence-type-regexp' for more information.") | |||
| 373 | (setq-local treesit-sentence-type-regexp | 395 | (setq-local treesit-sentence-type-regexp |
| 374 | (regexp-opt typescript-ts-mode--sentence-nodes)) | 396 | (regexp-opt typescript-ts-mode--sentence-nodes)) |
| 375 | 397 | ||
| 398 | (setq-local treesit-sexp-type-regexp | ||
| 399 | (regexp-opt typescript-ts-mode--sexp-nodes)) | ||
| 400 | |||
| 376 | ;; Imenu (same as in `js-ts-mode'). | 401 | ;; Imenu (same as in `js-ts-mode'). |
| 377 | (setq-local treesit-simple-imenu-settings | 402 | (setq-local treesit-simple-imenu-settings |
| 378 | `(("Function" "\\`function_declaration\\'" nil nil) | 403 | `(("Function" "\\`function_declaration\\'" nil nil) |
| @@ -438,6 +463,11 @@ See `treesit-sentence-type-regexp' for more information.") | |||
| 438 | '("jsx_element" | 463 | '("jsx_element" |
| 439 | "jsx_self_closing_element")))) | 464 | "jsx_self_closing_element")))) |
| 440 | 465 | ||
| 466 | (setq-local treesit-sexp-type-regexp | ||
| 467 | (regexp-opt (append | ||
| 468 | typescript-ts-mode--sexp-nodes | ||
| 469 | '("jsx")))) | ||
| 470 | |||
| 441 | ;; Font-lock. | 471 | ;; Font-lock. |
| 442 | (setq-local treesit-font-lock-settings | 472 | (setq-local treesit-font-lock-settings |
| 443 | (typescript-ts-mode--font-lock-settings 'tsx)) | 473 | (typescript-ts-mode--font-lock-settings 'tsx)) |