Skip to content

Commit f7d3158

Browse files
committed
[cleanup] Factor out `rjsx-expand-self-closing-tag'
1 parent 10fb16a commit f7d3158

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

rjsx-mode.el

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,15 @@ inserts `</>' and places the cursor inside the new tag."
864864

865865
(define-key rjsx-mode-map "<" 'rjsx-electric-lt)
866866

867+
(defun rjsx-expand-self-closing-tag (node)
868+
"Expand NODE into a balanced tag.
869+
Assumes NODE is self-closing `rjsx-node', and that point is at
870+
the self-closing slash."
871+
(delete-char 1)
872+
(search-forward ">")
873+
(save-excursion
874+
(insert "</" (rjsx-node-opening-tag-name node) ">")))
875+
867876
(defun rjsx-electric-gt (n)
868877
"Insert a context-sensitive greater-than sign.
869878
Optional prefix argument N indicates how many signs to insert.
@@ -877,11 +886,7 @@ the tags."
877886
(insert (make-string n ?>))
878887
(let ((node (rjsx--tag-at-point)))
879888
(if node
880-
(progn
881-
(delete-char 1)
882-
(search-forward ">")
883-
(save-excursion
884-
(insert "</" (rjsx-node-opening-tag-name node) ">")))
889+
(rjsx-expand-self-closing-tag node)
885890
(insert (make-string n ?>))))))
886891

887892
(define-key rjsx-mode-map ">" 'rjsx-electric-gt)
@@ -898,11 +903,7 @@ slash and inserts a matching end-tag."
898903
(delete-char n killflag))
899904
(let ((node (rjsx--tag-at-point)))
900905
(if node
901-
(progn
902-
(delete-char 1)
903-
(search-forward ">" )
904-
(save-excursion
905-
(insert "</" (rjsx-node-opening-tag-name node) ">")))
906+
(rjsx-expand-self-closing-tag node)
906907
(delete-char 1)))))
907908

908909
(define-key rjsx-mode-map (kbd "C-d") 'rjsx-delete-creates-full-tag)

0 commit comments

Comments
 (0)