[Top][All Lists]

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

Re: elisp optimization question

From: Lennart Borgman (gmail)
Subject: Re: elisp optimization question
Date: Fri, 09 May 2008 00:14:49 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20071031 Thunderbird/ Mnenhy/

brad clawsie wrote:
Hash: SHA1

hi, i use the following function to translate unicode and other
entities found on the web into ascii that i can view in emacs-w3m. i
am concerned that each search and replace as done in my example is
inefficient, is there a better way to do this? i.e., is there a better
way to group search/replace pairs? thanks in advance!

(defun w3m-filter-brad (url)
  (goto-char (point-min))
  (while (re-search-forward "»" nil t)
    (replace-match ">>"))
  (goto-char (point-min))
  (while (re-search-forward "’" nil t)
    (replace-match "'"))
  (goto-char (point-min))
  (while (re-search-forward "“" nil t)
    (replace-match "\""))
  (goto-char (point-min))
  (while (re-search-forward "”" nil t)
    (replace-match "\""))
  (goto-char (point-min))
  (while (re-search-forward "—" nil t)
    (replace-match "-"))
  (goto-char (point-min))
  (while (re-search-forward "«" nil t)
    (replace-match "<"))
  (goto-char (point-min))
  (while (re-search-forward "»" nil t)
    (replace-match ">"))
  (goto-char (point-min))
  (while (re-search-forward "ö" nil t)
    (replace-match "o"))

When you write it the way you do you do not need re-search-forward, just search-forward since you search for strings, not regular expressions.

Another way to make it faster would perhaps be to make one regular expression with regexp-opt and then check the match.

reply via email to

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