yokoloko
yokoloko

Reputation: 2860

Emacs, nxhtml how to highlight or jump to the closing html tag?

I'm using emacs with nxhtml to edit my HTML files but I can't find out how to highlight or jump to the closing HTML tag?

It sounds like an easy and stupid question but i really can't find it. Maybe I'm not looking for the right thing.

Upvotes: 10

Views: 2510

Answers (2)

phils
phils

Reputation: 73256

In nxhtml-mode, C-hm should indicate the following bindings:

<C-M-down>  nxml-down-element
<C-M-left>  nxml-backward-element
<C-M-right> nxml-forward-element
<C-M-up>    nxml-backward-up-element

The forward and backward functions are what you're asking about, while the up and down functions let you move to the parent or child element in the hierarchy.

The sgml-mode answer is more robust for HTML (as opposed to well-formed XHTML), but you may want to add autoloads for those functions if you'll be using them in nxhtml-mode, as the latter does not require the former.

(autoload 'sgml-skip-tag-forward "sgml-mode"
  "Skip to end of tag or matching closing tag if present.
With prefix argument ARG, repeat this ARG times.
Return t if after a closing tag." t)

(autoload 'sgml-skip-tag-backward "sgml-mode"
  "Skip to beginning of tag or matching opening tag if present.
With prefix argument ARG, repeat this ARG times.
Return non-nil if we skipped over matched tags." t)

Upvotes: 5

Grzegorz Rożniecki
Grzegorz Rożniecki

Reputation: 28005

I use functions from sgml-mode:

  • Ctrl+c Ctrl+f (sgml-skip-tag-forward)
  • Ctrl+c Ctrl+b (sgml-skip-tag-backward)

You can always remap them to more handy shortcut for your major mode, i.e.:

(add-hook 'html-mode-hook
 (lambda ()
 (define-key html-mode-map (kbd "<M-left>") 'sgml-skip-tag-backward)
 (define-key html-mode-map (kbd "<M-right>") 'sgml-skip-tag-forward)
 )
)

Upvotes: 14

Related Questions