tags:

views:

1955

answers:

3

When editing HTML in emacs, is there a way to automatically pretty-format a blob of markup, changing something like this:

  <table>
  <tr>
<td>blah</td></tr></table>

...into this:

<table>
 <tr>
  <td>
   blah
  </td>
 </tr>
</table>
+5  A: 

http://www.delorie.com/gnu/docs/emacs/emacs_277.html

C-M-q

Reindent all the lines within one parenthetical grouping(indent-sexp).

*C-M-\*

Reindent all lines in the region (indent-region).

Jay
That doesn't work for me -- on the example above, C-M-q does nothing, and C-M-\ gives a completely incorrect indenting.
raldi
Also doesn't work for me in nxml mode. index-sexp and indent-region will indent code that already has line breaks, this example is missing a few.
Justin Tanner
+4  A: 

Tidy can do what you want, but only for whole buffer it seems (and the result is XHTML)

M-x tidy-buffer
Chris Conway
+4  A: 
jfm3