Skip to content

Instantly share code, notes, and snippets.

@kosh04
Created March 23, 2012 09:05
Show Gist options
  • Save kosh04/2168718 to your computer and use it in GitHub Desktop.
Save kosh04/2168718 to your computer and use it in GitHub Desktop.
[xyzzy]xmlを整形する
;; 【元ネタ】VimだけでXML Reformat
;; KaoriYa http://www.kaoriya.net/blog/2012/02/09
;; xml-mode <http://chez-sugi.net/xyzzy/xml-mode.html> を利用して xml を整形します
;; ...空白にマッチする正規表現ってなかったっけ?
(defun xml-format-buffer ()
"編集中のxmlをそれなりに整形する."
(interactive "*")
(labels ((%s (reg rep)
(goto-char (point-min))
(replace-regexp reg rep t)
))
(save-excursion
(%s "><" ">\n<")
(%s ">\\([^ \t\n\r\f\v]\\)" ">\n\\1")
(%s "\\([^ \t\n]\\)<" "\\1\n<")
(xml:xml-mode)
(indent-region (point-min) (point-max)))
t))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment