1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-24 21:41:48 -08:00

Use JSX comments on jsx treesit nodes in js-ts-mode and tsx-ts-mode

* lisp/progmodes/js.el (js--treesit-comment-jsx): New internal variable.
(js--treesit-comment-setup): New function.
(js-ts-mode): Set buffer-local 'comment-setup-function' to
'js--treesit-comment-setup'.

* lisp/progmodes/typescript-ts-mode.el (typescript-ts-base-mode):
Set buffer-local 'comment-setup-function' to 'js--treesit-comment-setup'.
This commit is contained in:
Juri Linkov 2025-05-14 09:57:40 +03:00
parent 81cbff70f2
commit 8bccccedb6
2 changed files with 13 additions and 2 deletions

View file

@ -4038,6 +4038,17 @@ See `treesit-thing-settings' for more information.")
(rx bos (or "comment" "line_comment" "block_comment" "description") eos)
"Regexp for `c-ts-common--comment-regexp'.")
(defvar-local js--treesit-comment-jsx 'undefined)
(defun js--treesit-comment-setup ()
(let ((jsx (not (null (treesit-parent-until
(treesit-node-at (point)) "jsx")))))
(unless (eq js--treesit-comment-jsx jsx)
(setq js--treesit-comment-jsx jsx)
(cond (jsx (setq-local comment-start "{/* ")
(setq-local comment-end " */}"))
(t (c-ts-common-comment-setup))))))
;;;###autoload
(define-derived-mode js-ts-mode js-base-mode "JavaScript"
"Major mode for editing JavaScript.
@ -4052,7 +4063,7 @@ See `treesit-thing-settings' for more information.")
;; 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.

View file

@ -610,7 +610,7 @@ This mode is intended to be inherited by concrete major modes."
:syntax-table typescript-ts-mode--syntax-table
;; Comments.
(c-ts-common-comment-setup)
(setq-local comment-setup-function #'js--treesit-comment-setup)
;; Electric
(setq-local electric-indent-chars