help-gnu-emacs
[Top][All Lists]
Advanced

[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:1.8.1.9) Gecko/20071031 Thunderbird/2.0.0.9 Mnenhy/0.7.5.666

brad clawsie wrote:
-----BEGIN PGP SIGNED MESSAGE-----
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]