[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: elisp optimization question
From: |
harven |
Subject: |
Re: elisp optimization question |
Date: |
Fri, 9 May 2008 14:43:06 -0700 (PDT) |
User-agent: |
G2/1.0 |
> I wonder whether one could use that alist to "build" a regexp which
> you could use with regexp-replace: you could use the \, syntax to add
> lisp code to the stuff run.
>
> Rupert
Here is a short command that take advantage of the advices in the
previous posts.
(setq my-alist '(
("»" . ">>") ("ö" . "o") ("—" . "-")))
(setq html-regexp (regexp-opt (mapcar 'car my-alist)))
(defun w3m-filter ()
(interactive)
(goto-char (point-min))
(while (re-search-forward html-regexp nil t)
(replace-match
(cdr (assoc (match-string 0) my-alist)) nil t)))
I don't know how to pass interactively the values of the html-regexp
variable to the M-% command, though.
It's a bit strange to use regexp here. The tree structure given by a
keymap would be better I think. If the keymap would
insert a non valid prefix key sequence instead of reporting an error,
we could just actually read the html file with a keymap
binding the "—" key sequence to "-" etc.