を<や>に置換

http://ubulog.blogspot.com/2007/05/emacshtml.html
をちょっと改造

.emacsに書いた

(defun html-quote (start end)
  "選択範囲の「< > & 」と引用符記号「\"」をエスケープする"
  (interactive "r")
  (save-excursion
    (save-restriction
      (narrow-to-region start end)
      (goto-char (point-min))
      (while (re-search-forward "&" nil t)
        (replace-match "&amp;"))
      (goto-char (point-min))
      (while (re-search-forward "<" nil t)
        (replace-match "&lt;"))
      (goto-char (point-min))
      (while (re-search-forward ">" nil t)
        (replace-match "&gt;"))
      (goto-char (point-min))
      (while (re-search-forward " " nil t)
        (replace-match "&nbsp;"))
      (goto-char (point-min))
      (while (re-search-forward "\"" nil t)
        (replace-match "&qute;"))
      )))

html-quote で呼び出せる