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

2

10

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.

Partake answered 11/8, 2011 at 7:52 Comment(0)
S
14

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)
 )
)
Soave answered 11/8, 2011 at 9:50 Comment(0)
P
5

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)
Phonate answered 11/8, 2011 at 17:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.