Function: js-ts-mode
js-ts-mode is an autoloaded, interactive and byte-compiled function
defined in js.el.gz.
Signature
(js-ts-mode)
Documentation
Major mode for editing JavaScript.
In addition to any hooks its parent mode js-base-mode might have run,
this mode runs the hook js-ts-mode-hook, as the final or penultimate
step during initialization.
Probably introduced at or before Emacs version 30.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/js.el.gz
;;;###autoload
(define-derived-mode js-ts-mode js-base-mode "JavaScript"
"Major mode for editing JavaScript.
\\<js-ts-mode-map>"
:group 'js
:syntax-table js-mode-syntax-table
(when (treesit-ensure-installed 'javascript)
;; Borrowed from `js-mode'.
(setq-local prettify-symbols-alist js--prettify-symbols-alist)
(setq-local parse-sexp-ignore-comments t)
;; Which-func.
(setq-local which-func-imenu-joiner-function #'js--which-func-joiner)
;; Comment.
(c-ts-common-comment-setup)
(setq-local comment-setup-function #'js--treesit-comment-setup)
(setq-local comment-multi-line t)
;; Electric-indent.
(setq-local electric-indent-chars
(append "{}():;,<>/" electric-indent-chars)) ;FIXME: js2-mode adds "[]*".
(setq-local electric-layout-rules
'((?\; . after) (?\{ . after) (?\} . before)))
(setq-local syntax-propertize-function #'js-ts--syntax-propertize)
;; Tree-sitter setup.
(setq-local treesit-primary-parser (treesit-parser-create 'javascript))
;; Indent.
(setq-local treesit-simple-indent-rules (js--treesit-indent-rules))
;; Navigation.
(setq-local treesit-defun-type-regexp js--treesit-defun-type-regexp)
(setq-local treesit-defun-name-function #'js--treesit-defun-name)
(setq-local treesit-thing-settings js--treesit-thing-settings)
;; Fontification.
(setq-local treesit-font-lock-settings (js--treesit-font-lock-settings))
(setq-local treesit-font-lock-feature-list js--treesit-font-lock-feature-list)
(when (treesit-ensure-installed 'jsdoc)
(setq-local treesit-range-settings
(treesit-range-rules
:embed 'jsdoc
:host 'javascript
:local t
`(((comment) @capture (:match ,js--treesit-jsdoc-beginning-regexp @capture)))))
(setq c-ts-common--comment-regexp js--treesit-jsdoc-comment-regexp))
;; Imenu
(setq-local treesit-simple-imenu-settings js--treesit-simple-imenu-settings)
;; Outline minor mode
(setq-local treesit-outline-predicate js-ts-mode--outline-predicate)
(treesit-major-mode-setup)))