From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: harven Newsgroups: gmane.emacs.help Subject: Re: elisp optimization question Date: Fri, 9 May 2008 14:43:06 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <875de456-396d-4c4e-9d99-2ccb5a4a94d8@z72g2000hsb.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1210372865 18610 80.91.229.12 (9 May 2008 22:41:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 9 May 2008 22:41:05 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat May 10 00:41:40 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JubHX-0006CZ-3c for geh-help-gnu-emacs@m.gmane.org; Sat, 10 May 2008 00:41:39 +0200 Original-Received: from localhost ([127.0.0.1]:39035 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JubGo-0003A3-Oe for geh-help-gnu-emacs@m.gmane.org; Fri, 09 May 2008 18:40:54 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!d77g2000hsb.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 29 Original-NNTP-Posting-Host: 82.240.200.149 Original-X-Trace: posting.google.com 1210369387 23897 127.0.0.1 (9 May 2008 21:43:07 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Fri, 9 May 2008 21:43:07 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d77g2000hsb.googlegroups.com; posting-host=82.240.200.149; posting-account=hanW0AoAAADuR-PIr5jGeb298Y3jGR7p User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14,gzip(gfe),gzip(gfe) Original-Xref: shelby.stanford.edu gnu.emacs.help:158494 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:53859 Archived-At: > 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.