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

Command to wrap region in an element #52

Open
felipeochoa opened this issue Oct 9, 2017 · 1 comment
Open

Command to wrap region in an element #52

felipeochoa opened this issue Oct 9, 2017 · 1 comment

Comments

@felipeochoa
Copy link
Owner

It would be nice to have a structure-aware command to wrap the region with a new JSX element, similar to web-mode-element-wrap, but preserving a valid JSX file.

@yoLotus
Copy link

yoLotus commented May 16, 2018

I use a very naive function to it, it does not check at all if it is a valid JSX file after (I am not sure if it's easy to check JSX validity), I am not very good at eLisp.

(defun rjsx-region-wrap (node)
  "Wrap an region with NODE tag"
  (interactive "sTag wrapper: ")
  (if (region-active-p)
      (save-mark-and-excursion
       (progn
         (if (< (mark) (point)) (exchange-point-and-mark))
         (insert (concat "<" node ">"))
         (exchange-point-and-mark)
         (insert (concat "</" node ">"))))
    (message "no active region")))

(define-key rjsx-mode-map (kbd "C-c C-w") 'rjsx-region-wrap)

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

2 participants