In nxml-mode, I would like to insert an XML tag that has the same name as the nearest closing tag before point, without having to retype (or complete) the same tag name each time I do it.
Asked
Active
Viewed 49 times
1 Answers
1
This requires the expand-region
package.
(defun repeat-element ()
"start a new XML element with the same name as the previous XML element"
(interactive)
(er/expand-region 1)
(replace-regexp "</\\([^>]+\\)>" "\\&
<\\1" nil (region-beginning) (region-end) nil)
(funcall indent-line-function))

Jordon Biondo
- 12,332
- 2
- 41
- 62

Robin Green
- 949
- 7
- 16