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.
This commit is contained in:
parent
f55bbc6898
commit
2bf0ad3be6
2 changed files with 56 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Add table
Reference in a new issue