Skip to content

Commit

Permalink
Add a pretty print xml function that works in nxml mode
Browse files Browse the repository at this point in the history
  • Loading branch information
aisipos committed Jan 6, 2011
1 parent b7f7a1c commit 90982cd
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions customizations/functions.el
@@ -1,6 +1,23 @@
;;Custom functions

;;Seems to be needed for search-at-point
;;Found at http://www.emacswiki.org/emacs/CompilationMode
(defun delete-this-overlay(overlay is-after begin end &optional len)
(delete-overlay overlay)
)

;;See http://blog.bookworm.at/2007/03/pretty-print-xml-with-emacs.html
(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"))
(indent-region begin end))
(message "Ah, much better!"))

0 comments on commit 90982cd

Please sign in to comment.