Closed kandros closed 6 years ago
Unfortunately not. It should not be too hard to implement, though. It would require defining a new comment-region-function
that checks whether the commenting context is JSX or JS. If the former, extend the region to include a complete JSX node and then wrap the region in {/* ... */}
, otherwise, use comment-region-default
. Determining which commenting style to use may take some trial and error, but I'd guess a reasonable test may be if either beg
or end
are descendants of JSX nodes.
I don't have time to do it myself, but PR welcome!
I'll give it a try, but i think my lisp-foo is not that strong yet 😥
This is actually not as easy as it seems as js2 is quite unconventional, newcomment.el is also... oh god... 20-year-old code...
I gave it a go, I'm afraid just trying to decipher which node beg is looking at gave me a headache. (j2-node-at-point)
gave me a giant block unformatted tree when printed out. I honestly don't know how people debug js2. Choosing which comment-start
and comment-end
in a context sensitive way is also quite a mess.
Thanks for trying. Yes, debugging js2
can be a little painful. Try out debug-js2-ast
in this gist.
Agree on the lisp-foo😂... Just in case someone else wants a quick solution for this, I found a temporary solution by pushing a pair to evil-surround-pairs-alist
. Then you can select a region in evil-mode
and press S/
to comment region in rjsx-mode
.
(add-hook 'rjsx-mode-hook (lambda ()
(push '(?/ . ("{/*" . "*/}")) evil-surround-pairs-alist)))
Similarily, you can go with wrap-region.
Whoops, sorry for the spam! Excellent feature currently brewing!
Check this PR out guys https://github.com/felipeochoa/rjsx-mode/pull/72
It still doesn't work for me. With my full config M-;
is bound to comment-or-uncomment-region
, but even with emacs -u none
and loading rjsx-mode
manually it still inserts slashes in fron of commented out tags.
Is it possible to comment JSX code using emac's
(comment-line)
?