* How to do search and replace with a lookup
@ 2017-12-11 8:49 Angus Comber
2017-12-11 10:03 ` tomas
0 siblings, 1 reply; 2+ messages in thread
From: Angus Comber @ 2017-12-11 8:49 UTC (permalink / raw)
To: help-gnu-emacs
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?
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: How to do search and replace with a lookup
2017-12-11 8:49 How to do search and replace with a lookup Angus Comber
@ 2017-12-11 10:03 ` tomas
0 siblings, 0 replies; 2+ messages in thread
From: tomas @ 2017-12-11 10:03 UTC (permalink / raw)
To: help-gnu-emacs
-----BEGIN PGP SIGNED MESSAGE-----
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.
Cheers
[1] https://www.gnu.org/software/emacs/manual/html_node/emacs/Regexp-Replace.html
[2] https://www.emacswiki.org/emacs/ReplaceRegexpWithLispExpressions
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
iEYEARECAAYFAlouV9wACgkQBcgs9XrR2kasoQCfTqWd/At13mpCPtAZn+9VgM65
J+gAn3/AFIu+nwhfK4IJE6db0unak4qt
=0GSb
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-12-11 10:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-11 8:49 How to do search and replace with a lookup Angus Comber
2017-12-11 10:03 ` tomas
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.