[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: elisp optimization question

From: Kevin Rodgers
Subject: Re: elisp optimization question
Date: Thu, 08 May 2008 19:45:43 -0600
User-agent: Thunderbird (Macintosh/20080421)

harven wrote:
you can save some typing by using an alist. Here is what i use to
accented-letters into html and back.

(defun accent-html (prefix)
 "Accented letter translation     é -> &eacute.
  With an argument,  reverse    é <- &eacute.
  Works on the whole buffer"
 (interactive "P")
   (let ((association
          '(("É" . "&Eacute;") ("á" . "&aacute;")  ("à" . "&agrave;")
            ("â" . "&acirc;")  ("ä" . "&auml;")    (""" . "&atilde;")
            ("é" . "&eacute;") ("è" . "&egrave;")  ("ê" . "&ecirc;")
            ("ë" . "&euml;")   ("í" . "&iacute;")  ("ì" . "&igrave;")
            ("î" . "&icirc;")  ("ï" . "&iuml;")    ("ñ" . "&ntilde;")
            ("ó" . "&oacute;") ("ò" . "&ograve;")  ("ô" . "&ocirc;")
            ("ö" . "&ouml;")   ("ı" . "&otilde;")  ("ú" .
            ("ù" . "&ugrave;") ("û" . "&ucirc;")   ("ü" . "&uuml;")
            ("ç" . "&ccedil;")))
        (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))))))

Even faster than an alist is a hash table.

Kevin Rodgers
Denver, Colorado, USA

reply via email to

[Prev in Thread] Current Thread [Next in Thread]