开发者

How to delete contents of an HTML tag in Emacs

Vim has an awesome feature that allows users to d开发者_如何学Celete contents of tags, within quotation marks, etc. For example, in the following situation:

<h1>  Cursor is here -> █ <- :)  </h1>

one can type d i t (“delete in tag”) to delete the contents of the <h1> HTML tag.

There are also other shortcuts, for example:

  • d i ( to delete contents in parentheses ()
  • d i " to delete contents in double quotes "".
  • d i ' to delete contents in single quotes ''.

Does anything like this exist for Emacs?

I'm aware of zap-to-char and nXhtml's sgml-delete-tag, but they don't quite do what I want.


How's this code work for you?

(defun sgml-delete-tagged-text ()
  "delete text between the tags that contain the current point"
  (interactive)
  (let ((b (point)))
    (sgml-skip-tag-backward 1)
    (when (not (eq b (point)))
      ;; moved somewhere, should be at front of a tag now
      (save-excursion 
        (forward-sexp 1)
        (setq b (point)))
      (sgml-skip-tag-forward 1)
      (backward-sexp 1)
      (delete-region b (point)))))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜