;; -*- coding: utf-8 -*-
(defun htmlify ()
"Translate some characters to corresponding HTML sequences in current buffer.
In transient mark mode, the function operates on the region if it is active."
(interactive)
(save-excursion
(save-restriction
(when (and transient-mark-mode mark-active)
(narrow-to-region (region-beginning) (region-end)))
(let (case-fold-search)
(dolist (s '(("ä" "ä") ("Ä" "Ä") ("ö" "ö")
("Ö" "Ö") ("ü" "ü") ("Ü" "Ü")
("ß" "ß") ("<" "<") (">" ">") ("…" "...")
("–" "-") ("„" "\"") ("“" "\"")
;; add more sequences here
))
(goto-char (point-min))
(while (search-forward (car s) nil t)
(replace-match (cadr s) t t)))))))