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

The recommended way to fold jsx tags #134

Open
shiyuangu opened this issue Jul 25, 2022 · 1 comment
Open

The recommended way to fold jsx tags #134

shiyuangu opened this issue Jul 25, 2022 · 1 comment

Comments

@shiyuangu
Copy link

What is the recommended way to fold jsx tags using rjsx-mode? I tried hide-show minor mode and origami but they all messed up the tags.
Thank you!

@felipeochoa
Copy link
Owner

I don't use folding much in JSX, but I do use fold-this in other modes. Here's a quick-and-dirty folding function you can try:

(defun rjsx-fold-tag-at-point ()
  (interactive)
  (js2-mode-wait-for-parse
   (lambda ()
     (let* ((node (rjsx--tag-at-point))
            (child0 (car (rjsx-node-kids node)))
            (closer (and node (rjsx-node-closing-tag node))))
       (cond
        ((null node) (message "No JSX tag found at point"))
        ((null closer) (message "JSX tag is void"))
        ((null child0) (message "JSX tag has no children"))
        (t (let* ((start (js2-node-abs-pos child0))
                  (end (js2-node-abs-pos closer)))
             (fold-this start end))))))))

It doesn't handle newlines, but should be enough to get you started!

As usual, PRs welcome for anyone wanting to add to rjsx core

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants