Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a pretty print xml function that works in nxml mode
- Loading branch information
Showing
1 changed file
with
17 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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!")) |