forked from purcell/emacs.d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-nxml.el
50 lines (42 loc) · 1.53 KB
/
init-nxml.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
;;; init-nxml.el --- Support for editing XML with NXML -*- lexical-binding: t -*-
;;; Commentary:
;;; Code:
(add-auto-mode
'nxml-mode
(concat "\\."
(regexp-opt
'("xml" "xsd" "sch" "rng" "xslt" "svg" "rss"
"gpx" "tcx" "plist"))
"\\'"))
(setq magic-mode-alist (cons '("<\\?xml " . nxml-mode) magic-mode-alist))
(fset 'xml-mode 'nxml-mode)
(setq nxml-slash-auto-complete-flag t)
;; See: http://sinewalker.wordpress.com/2008/06/26/pretty-printing-xml-with-emacs-nxml-mode/
(defun sanityinc/pp-xml-region (beg end)
"Pretty format XML markup in region. 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")
(unless (use-region-p)
(setq beg (point-min)
end (point-max)))
;; Use markers because our changes will move END
(setq beg (set-marker (make-marker) beg)
end (set-marker (make-marker) end))
(save-excursion
(goto-char beg)
(while (search-forward-regexp "\>[ \\t]*\<" end t)
(backward-char) (insert "\n"))
(nxml-mode)
(indent-region beg end)))
;; Integration with tidy for html + xml
(defun sanityinc/tidy-buffer-xml (beg end)
"Run \"tidy -xml\" on the region from BEG to END, or whole buffer."
(interactive "r")
(unless (use-region-p)
(setq beg (point-min)
end (point-max)))
(shell-command-on-region beg end "tidy -xml -q -i" (current-buffer) t "*tidy-errors*" t))
(provide 'init-nxml)
;;; init-nxml.el ends here