[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Fwd: Re: Inadequate documentation of silly characters on screen.
From: |
Alan Mackenzie |
Subject: |
Re: Fwd: Re: Inadequate documentation of silly characters on screen. |
Date: |
Thu, 19 Nov 2009 17:08:38 +0000 |
User-agent: |
Mutt/1.5.9i |
Hi, Stefan,
On Thu, Nov 19, 2009 at 09:08:29AM -0500, Stefan Monnier wrote:
> >> If you give us more context (i.e. more of the real code where the
> >> problem show up), maybe we can tell you how to avoid it.
> > OK. I have my own routine to display regexps. As a first step, I
> > translate \n -> ñ, (and \t, \r, \f similarly). This is how:
> > (defun translate-rnt (regexp)
> > "REGEXP is a string. Translate any \t \n \r and \f characters
> > to wierd non-ASCII printable characters: \t to Î (206, \xCE), \n
> > to ñ (241, \xF1), \r to ® (174, \xAE) and \f to £ (163, \xA3).
> > The original string is modified."
> > (let (ch pos)
> > (while (setq pos (string-match "[\t\n\r\f]" regexp))
> > (setq ch (aref regexp pos))
> > (aset regexp pos ; <===================
> > (cond ((eq ch ?\t) ?Î)
> > ((eq ch ?\n) ?ñ)
> > ((eq ch ?\r) ?®)
> > (t ?£))))
> > regexp))
> Each one of those `aset' (when performed according to your wishes) would
> change the byte-size of the string, so it would internally require
> copying the whole string each time: aset on (multibyte) strings is very
> inefficient (compared to what most people expect, not necessarily
> compared to other operations). I'd recommend you use higher-level
> operations since they'll work just as well and are less susceptible to
> such problems:
> (replace-regexp-in-string "[\t\n\r\f]"
> (lambda (s)
> (or (cdr (assoc s '(("\t" . "Î")
> ("\n" . "ñ")
> ("\r" . "®"))))
> "£"))
> regexp)
That works 100%. Even in Emacs 23 ;-). Thanks!
> Stefan
--
Alan Mackenzie (Nuremberg, Germany).
- Re: Inadequate documentation of silly characters on screen., (continued)
- Re: Inadequate documentation of silly characters on screen., David Kastrup, 2009/11/21
- Re: Inadequate documentation of silly characters on screen., Stephen J. Turnbull, 2009/11/21
- Re: Inadequate documentation of silly characters on screen., David Kastrup, 2009/11/21
- Re: Inadequate documentation of silly characters on screen., Stephen J. Turnbull, 2009/11/21
- Re: Inadequate documentation of silly characters on screen., David Kastrup, 2009/11/21
- Re: Inadequate documentation of silly characters on screen., Sebastian Rose, 2009/11/21
- Re: Inadequate documentation of silly characters on screen., David Kastrup, 2009/11/22
- Re: Inadequate documentation of silly characters on screen., Sebastian Rose, 2009/11/22
- Re: Fwd: Re: Inadequate documentation of silly characters on screen.,
Alan Mackenzie <=