]> git.eshelyaron.com Git - emacs.git/commitdiff
Add sexp navigation to js/typescript/tsx-ts-mode
authorTheodor Thornhill <theo@thornhill.no>
Sat, 21 Jan 2023 13:47:34 +0000 (14:47 +0100)
committerTheodor Thornhill <theo@thornhill.no>
Sat, 21 Jan 2023 13:47:34 +0000 (14:47 +0100)
* 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
lisp/progmodes/typescript-ts-mode.el

index 28305a0b39b769862c9e4b9e06942128d37a23dd..6f3746ca72a03f391047d5d6fb7b1bf166e9d0da 100644 (file)
@@ -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
index f7bf7ed7e427079265114084ef565fd0f1142975..69e4746bcc4d9603cdc3eeb91c54f191ef390916 100644 (file)
@@ -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))