[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 2bf0ad3be6b: Add sexp navigation to js/typescript/tsx-ts-mode
From: |
Theodor Thornhill |
Subject: |
master 2bf0ad3be6b: Add sexp navigation to js/typescript/tsx-ts-mode |
Date: |
Sat, 21 Jan 2023 08:55:14 -0500 (EST) |
branch: master
commit 2bf0ad3be6bec22471c5b32548da99d6eb63da58
Author: Theodor Thornhill <theo@thornhill.no>
Commit: Theodor Thornhill <theo@thornhill.no>
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.
---
lisp/progmodes/js.el | 26 ++++++++++++++++++++++++++
lisp/progmodes/typescript-ts-mode.el | 30 ++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+)
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'."
"Nodes that designate sentences in JavaScript.
See `treesit-sentence-type-regexp' for more information.")
+(defvar js--treesit-sexp-nodes
+ '("expression"
+ "pattern"
+ "array"
+ "function"
+ "string"
+ "escape"
+ "template"
+ "regex"
+ "number"
+ "identifier"
+ "this"
+ "super"
+ "true"
+ "false"
+ "null"
+ "undefined"
+ "arguments"
+ "pair"
+ "jsx")
+ "Nodes that designate sexps in JavaScript.
+See `treesit-sexp-type-regexp' for more information.")
+
;;;###autoload
(define-derived-mode js-ts-mode js-base-mode "JavaScript"
"Major mode for editing JavaScript.
@@ -3860,6 +3883,9 @@ See `treesit-sentence-type-regexp' for more information.")
(setq-local treesit-sentence-type-regexp
(regexp-opt js--treesit-sentence-nodes))
+ (setq-local treesit-sexp-type-regexp
+ (regexp-opt js--treesit-sexp-nodes))
+
;; Fontification.
(setq-local treesit-font-lock-settings js--treesit-font-lock-settings)
(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'."
"Nodes that designate sentences in TypeScript.
See `treesit-sentence-type-regexp' for more information.")
+(defvar typescript-ts-mode--sexp-nodes
+ '("expression"
+ "pattern"
+ "array"
+ "function"
+ "string"
+ "escape"
+ "template"
+ "regex"
+ "number"
+ "identifier"
+ "this"
+ "super"
+ "true"
+ "false"
+ "null"
+ "undefined"
+ "arguments"
+ "pair")
+ "Nodes that designate sexps in TypeScript.
+See `treesit-sexp-type-regexp' for more information.")
+
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-ts-mode))
@@ -373,6 +395,9 @@ See `treesit-sentence-type-regexp' for more information.")
(setq-local treesit-sentence-type-regexp
(regexp-opt typescript-ts-mode--sentence-nodes))
+ (setq-local treesit-sexp-type-regexp
+ (regexp-opt typescript-ts-mode--sexp-nodes))
+
;; Imenu (same as in `js-ts-mode').
(setq-local treesit-simple-imenu-settings
`(("Function" "\\`function_declaration\\'" nil nil)
@@ -438,6 +463,11 @@ See `treesit-sentence-type-regexp' for more information.")
'("jsx_element"
"jsx_self_closing_element"))))
+ (setq-local treesit-sexp-type-regexp
+ (regexp-opt (append
+ typescript-ts-mode--sexp-nodes
+ '("jsx"))))
+
;; Font-lock.
(setq-local treesit-font-lock-settings
(typescript-ts-mode--font-lock-settings 'tsx))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 2bf0ad3be6b: Add sexp navigation to js/typescript/tsx-ts-mode,
Theodor Thornhill <=