Added pretty-print XML function.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Thu, 03 May 2018 11:52:34 +0300
changeset 1559 9f4456fcac0e
parent 1558 a7bb0608855b
child 1560 10e5b207ec7d
Added pretty-print XML function.
.emacs-my
--- a/.emacs-my	Sat Apr 14 17:15:52 2018 +0300
+++ b/.emacs-my	Thu May 03 11:52:34 2018 +0300
@@ -3502,6 +3502,17 @@
 (my--eval-after-load nxml-mode
   (define-key nxml-mode-map [C-return] 'nxml-complete))
 
+(defun my-nxml-pp ()
+  "Pretty-print XML."
+  (interactive)
+  (goto-char (point-min))
+  (while (re-search-forward ">[ \t\n\r]+<" nil t)
+    (replace-match ">\n<"))
+  (while (re-search-forward "><" nil t)
+    (replace-match ">\n<"))
+  (indent-region (point-min) (point-max))
+  (goto-char (point-min)))
+
 (defun my-nxml-where (&optional prefix)
   "Display the hierarchy of XML elements the point is on as a path."
   (interactive "P")