]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/yasnippet/snippets/emacs-lisp-mode/x-find-replace.yasnippet
Add yasnippet.
[gnu-emacs-elpa] / packages / yasnippet / snippets / emacs-lisp-mode / x-find-replace.yasnippet
diff --git a/packages/yasnippet/snippets/emacs-lisp-mode/x-find-replace.yasnippet b/packages/yasnippet/snippets/emacs-lisp-mode/x-find-replace.yasnippet
new file mode 100644 (file)
index 0000000..e5a1d6c
--- /dev/null
@@ -0,0 +1,18 @@
+# contributor: Xah Lee (XahLee.org)
+# name: find and replace on region
+# key: x-find-replace
+# --
+(defun replace-html-chars-region (start end)
+  "Replace “<” to “&lt;” and other chars in HTML.
+This works on the current region."
+  (interactive "r")
+  (save-restriction 
+    (narrow-to-region start end)
+    (goto-char (point-min))
+    (while (search-forward "&" nil t) (replace-match "&amp;" nil t))
+    (goto-char (point-min))
+    (while (search-forward "<" nil t) (replace-match "&lt;" nil t))
+    (goto-char (point-min))
+    (while (search-forward ">" nil t) (replace-match "&gt;" nil t))
+    )
+  )
\ No newline at end of file