Create a gist now

Instantly share code, notes, and snippets.

Little helpers for nxml
(defun cabo:nxml-balanced-close-start-tag-block ()
"Close the start-tag before point with `>' and insert a balancing end-tag.
Point is left between the start-tag and the end-tag.
If there is nothing but whitespace before the `<' that opens the
start-tag, then put point on a blank line, and put the end-tag on
another line aligned with the start-tag."
(interactive "*")
(nxml-complete)
(nxml-balanced-close-start-tag-block))
(defun cabo:nxml-balanced-close-start-tag-inline ()
"Close the start-tag before point with `>' and insert a balancing end-tag.
Point is left between the start-tag and the end-tag.
No extra whitespace is inserted."
(interactive "*")
(nxml-complete)
(nxml-balanced-close-start-tag-inline))
(defun bind-nxml-mode-keys ()
(define-key nxml-mode-map "\C-c\C-b" 'cabo:nxml-balanced-close-start-tag-block)
(define-key nxml-mode-map "\C-c\C-i" 'cabo:nxml-balanced-close-start-tag-inline)
(define-key nxml-mode-map (kbd "<C-return>") 'completion-at-point))
(add-hook 'nxml-mode-hook 'bind-nxml-mode-keys)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment