Skip to content

Instantly share code, notes, and snippets.

@dwcoates
Last active December 1, 2017 19:52
Show Gist options
  • Save dwcoates/72d6e3e9ab76451eab5cfef7be715ea4 to your computer and use it in GitHub Desktop.
Save dwcoates/72d6e3e9ab76451eab5cfef7be715ea4 to your computer and use it in GitHub Desktop.
Copy or kill HTML element at point in Emacs
(defun sgml-copy-or-kill-element (arg)
(interactive "P")
(let ((cut-tag (lambda ()
(let ((beg (point))
(end (save-excursion (sgml-skip-tag-forward 1)
(point))))
(kill-ring-save beg end)
(when arg
(delete-region beg end))))))
(save-excursion (if (sgml-beginning-of-tag)
(funcall cut-tag)
(if (progn (forward-char) (sgml-beginning-of-tag))
(funcall cut-tag)
(message "Not in an HTML tag."))))
))
(defun sgml-kill-element ()
(interactive)
(let ((current-prefix-arg 4))
(call-interactively 'sgml-copy-or-kill-element))
)
(define-key html-mode-map (kbd "C-c C-w") 'sgml-copy-or-kill-element)
(define-key html-mode-map (kbd "C-c C-k") 'sgml-kill-element)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment