2021-04-05 14:45:07 +00:00
|
|
|
;; -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
(use-package nxml-mode
|
|
|
|
:straight (:type built-in)
|
|
|
|
:defer t
|
|
|
|
:config
|
2021-04-15 19:26:47 +00:00
|
|
|
(defun xml-pretty-print ()
|
|
|
|
(interactive)
|
|
|
|
(let ((start (if (region-active-p) (region-beginning) (point-min)))
|
|
|
|
(end (if (region-active-p) (region-end) (point-max))))
|
|
|
|
(cond
|
|
|
|
((executable-find "tidy")
|
|
|
|
(shell-command-on-region start end "tidy -wrap 88 -q -i -xml" nil t))
|
|
|
|
((executable-find "xmllint")
|
|
|
|
(shell-command-on-region start end "xmllint --format -" nil t))
|
|
|
|
(t (sgml-pretty-print start end)))))
|
|
|
|
(general-def nxml-mode-map "C-M-\\" #'xml-pretty-print)
|
2021-05-12 15:03:59 +00:00
|
|
|
(add-hook 'nxml-mode-hook #'hs-minor-mode)
|
2021-04-05 14:45:07 +00:00
|
|
|
(add-to-list 'hs-special-modes-alist
|
|
|
|
'(nxml-mode
|
|
|
|
"<!--\\|<[^/>]*[^/]>" ;; regexp for start block
|
|
|
|
"-->\\|</[^/>]*[^/]>" ;; regexp for end block
|
|
|
|
"<!--"
|
|
|
|
nxml-forward-element
|
|
|
|
nil)))
|
|
|
|
|
|
|
|
(provide 'init-xml)
|