[Top][All Lists]

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

Re: How to do search and replace with a lookup

From: tomas
Subject: Re: How to do search and replace with a lookup
Date: Mon, 11 Dec 2017 11:03:08 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

Hash: SHA1

On Mon, Dec 11, 2017 at 12:49:47AM -0800, Angus Comber wrote:
> I have log file output like this:
> Received device state message: pen state = 11 - uig state 10
> where pen state and uig state are enums.
> I want to do a search and replace where if for example pen state 11 enum is 
> diagnostics and uig state 10 enum is starting, then I want the line to be 
> updated to:
> Received device state message: pen state = diagnostics - uig state starting
> What is the easiest way to do this?
> I can do search and replace using c-m-% and change for each permutation of 
> number to string but that would be fairly labour intensive if enums were 
> fairly long.  Can I combine that with a lookup somehow?  What is best way to 
> do it?

If you do query-replace-regexp, you can use \,(...) in the
substitution text for a Lisp expression to be evaluated at
substitution time. You can pass it (parts of) the matched
string with the usual \0, \1, etc.

Thus if you have a mapping available for your enums which
is accessible from Lisp (an alist, a hash, whatever) you
should be half way there.

The manual[1] has a little example (it starts at the point
"Most readers can skip it", so make sure to *not* skip it :-)

The Emacs Wiki[2] has a couple of nice examples.

Just yell if you need more help.


- -- tomás
Version: GnuPG v1.4.12 (GNU/Linux)


reply via email to

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