dotemacs

My Emacs configuration
git clone git://git.entf.net/dotemacs
Log | Files | Refs | LICENSE

commit 45c2bb2adcedfc10b42f888605518be6ba4beda2
parent dcb9557ef8108694a0176593e52540b346a7d10f
Author: Lukas Henkel <lh@entf.net>
Date:   Mon, 17 Oct 2022 20:50:41 +0200

Add function to escape/unescape xml

Diffstat:
Minit.el | 2++
Alisp/lh-xml.el | 19+++++++++++++++++++
2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/init.el b/init.el @@ -146,6 +146,8 @@ ("C-c i i s" . lh/insert-random-sha1) ("C-c i i u" . uuidgen) ("C-c i r f" . lh/insert-number-from-register-format) + + ("C-c e x" . lh/xml-escape-region) ("<mouse-8>" . xref-go-back) ("<mouse-9>" . xref-go-forward))) diff --git a/lisp/lh-xml.el b/lisp/lh-xml.el @@ -0,0 +1,19 @@ +;; -*- lexical-binding: t; -*- +(require 'xml) + +(defun lh/xml-escape-region (beg end ARG) + (interactive "r\nP") + (when (not (region-active-p)) + (setq beg (point-min)) + (setq end (point-max))) + (let* ((text (buffer-substring-no-properties beg end)) + (escaped (if ARG + (with-temp-buffer + (save-excursion + (insert text)) + (xml-parse-string)) + (xml-escape-string text)))) + (delete-region beg end) + (insert escaped))) + +(provide 'lh-xml)