Se hai solo bisogno di un bel rientro senza introdurre nuove interruzioni di riga, puoi applicare il indent-regioncomando all'intero buffer con queste sequenze di tasti:
C-x h
C-M-\
Se hai anche bisogno di introdurre interruzioni di riga, in modo che i tag di apertura e chiusura siano su righe separate, potresti usare la seguente funzione elisp molto carina, scritta da Benjamin Ferrari . L'ho trovato sul suo blog e spero che mi vada bene riprodurlo qui:
(defun bf-pretty-print-xml-region (begin end)
"Pretty format XML markup in region. You need to have nxml-mode
http://www.emacswiki.org/cgi-bin/wiki/NxmlMode installed to do
this. The function inserts linebreaks to separate tags that have
nothing but whitespace between them. It then indents the markup
by using nxml's indentation rules."
(interactive "r")
(save-excursion
(nxml-mode)
(goto-char begin)
(while (search-forward-regexp "\>[ \\t]*\<" nil t)
(backward-char) (insert "\n") (setq end (1+ end)))
(indent-region begin end))
(message "Ah, much better!"))
Questo non si basa su uno strumento esterno come Tidy.
wrong type argument: stringp, nil