]> code.delx.au - gnu-emacs-elpa/blob - packages/yasnippet/snippets/emacs-lisp-mode/x-find-replace.yasnippet
Merge commit '0cda39255827f283e7578cd469ae42daad9556a2' from js2-mode
[gnu-emacs-elpa] / packages / yasnippet / snippets / emacs-lisp-mode / x-find-replace.yasnippet
1 # contributor: Xah Lee (XahLee.org)
2 # name: find and replace on region
3 # key: x-find-replace
4 # --
5 (defun replace-html-chars-region (start end)
6 "Replace “<” to “&lt;” and other chars in HTML.
7 This works on the current region."
8 (interactive "r")
9 (save-restriction
10 (narrow-to-region start end)
11 (goto-char (point-min))
12 (while (search-forward "&" nil t) (replace-match "&amp;" nil t))
13 (goto-char (point-min))
14 (while (search-forward "<" nil t) (replace-match "&lt;" nil t))
15 (goto-char (point-min))
16 (while (search-forward ">" nil t) (replace-match "&gt;" nil t))
17 )
18 )