[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: elisp optimization question
From: |
harven |
Subject: |
Re: elisp optimization question |
Date: |
Thu, 8 May 2008 17:00:30 -0700 (PDT) |
User-agent: |
G2/1.0 |
hi,
you can save some typing by using an alist. Here is what i use to
convert
accented-letters into html and back.
(defun accent-html (prefix)
"Accented letter translation é -> é.
With an argument, reverse é <- é.
Works on the whole buffer"
(interactive "P")
(save-excursion
(let ((association
'(("É" . "É") ("á" . "á") ("à" . "à")
("â" . "â") ("ä" . "ä") (""" . "ã")
("é" . "é") ("è" . "è") ("ê" . "ê")
("ë" . "ë") ("í" . "í") ("ì" . "ì")
("î" . "î") ("ï" . "ï") ("ñ" . "ñ")
("ó" . "ó") ("ò" . "ò") ("ô" . "ô")
("ö" . "ö") ("ı" . "õ") ("ú" .
"ú")
("ù" . "ù") ("û" . "û") ("ü" . "ü")
("ç" . "ç")))
(case-fold-search nil))
(dolist (paire association)
(when prefix
(setq paire (cons (cdr paire) (car paire))))
(goto-char (point-min))
(while (search-forward (car paire) nil t)
(replace-match (cdr paire) nil t))))))
This is not more efficient than your own defun. If you only want to
translate characters, the function (subst-char-in-region) is a
primitive
that saves a while loop and is probably faster.