sdasdadas
sdasdadas

Reputation: 25096

HTML Tags in Emacs not Aligning

I'm using the shipped HTML mode with Emacs and writing a basic index.html page (eg. just a body with a div inside). When I try to close a tag, Emacs doesn't auto-indent the tag to match the opening tag. Do I have to set something in my .emacs file?

The problem is thus:

<div>
    content....
    </div>

Thanks!

Upvotes: 2

Views: 258

Answers (2)

sdasdadas
sdasdadas

Reputation: 25096

I have resorted to running C-M-\ to auto-format my code once I've typed it.

Upvotes: 1

Alex W
Alex W

Reputation: 38163

This seems to be similar to what you're after:

Can't change Emacs's default indentation between HTML tags

More info on HTML indentation:

http://www.emacswiki.org/emacs/IndentingHtml

(add-hook 'html-mode-hook
  (lambda ()
    ;; Default indentation is usually 2 spaces, changing to 4.
    (set (make-local-variable 'sgml-basic-offset) 4)))

Edit:

This seems like it might be a good solution: Can emacs re-indent a big blob of HTML for me?

By default, when you visit a .html file in Emacs (22 or 23), it will put you in html-mode. That is probably not what you want. You probably want nxml-mode, which is seriously fancy. nxml-mode seems to only come with Emacs 23, although you can download it for earlier versions of emacs from the nXML web site. There is also a Debian and Ubuntu package named nxml-mode

Upvotes: 1

Related Questions