Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to comment JSX code? #46

Closed
kandros opened this issue Sep 5, 2017 · 8 comments
Closed

how to comment JSX code? #46

kandros opened this issue Sep 5, 2017 · 8 comments

Comments

@kandros
Copy link

kandros commented Sep 5, 2017

Is it possible to comment JSX code using emac's (comment-line)?

@kandros kandros changed the title how to comment code? how to comment JSX code? Sep 5, 2017
@felipeochoa
Copy link
Owner

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!

@kandros
Copy link
Author

kandros commented Sep 5, 2017

I'll give it a try, but i think my lisp-foo is not that strong yet 😥

@wyuenho
Copy link
Contributor

wyuenho commented Nov 1, 2017

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.

@felipeochoa
Copy link
Owner

Thanks for trying. Yes, debugging js2 can be a little painful. Try out debug-js2-ast in this gist.

@ztlevi
Copy link

ztlevi commented Mar 21, 2018

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.

@wyuenho
Copy link
Contributor

wyuenho commented May 6, 2018

Whoops, sorry for the spam! Excellent feature currently brewing!

@wyuenho
Copy link
Contributor

wyuenho commented May 13, 2018

Check this PR out guys
#72

felipeochoa pushed a commit that referenced this issue Jun 25, 2018
felipeochoa pushed a commit that referenced this issue Jun 25, 2018
@oscu0
Copy link

oscu0 commented Aug 4, 2018

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.

felipeochoa added a commit that referenced this issue Aug 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants