rjsx-mode
rjsx-mode copied to clipboard
Command to wrap region in an element
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.
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)