* how to search and replace in nested expressions
@ 2006-02-13 5:22 JAMES FUNDERBURK
2006-02-13 6:01 ` Pascal Bourguignon
0 siblings, 1 reply; 2+ messages in thread
From: JAMES FUNDERBURK @ 2006-02-13 5:22 UTC (permalink / raw)
Is there a way to search and replace in nested expressions?
The particular form of my nested expressions is
form[x,y,...z] where each 'argument' may be either
a word (simple character string) or else
another nested expression. Note that the arguments are
separated by commas, but there may be only one argument.
For example, it might be desired to change expressions of the form
simple[x,y] to simple[y,x] in such a way that
simple[apple[u],pear[v,w]] is changed to
simple[pear[v,w],apple[u]].
I am familiar with Emacs-Lisp, so am looking for a function to do
such changes on a buffer. I have used the regular expression search and
replace functions quite a bit, but don't see how to apply them in this
situation.
Thanks for any suggestions.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: how to search and replace in nested expressions
2006-02-13 5:22 how to search and replace in nested expressions JAMES FUNDERBURK
@ 2006-02-13 6:01 ` Pascal Bourguignon
0 siblings, 0 replies; 2+ messages in thread
From: Pascal Bourguignon @ 2006-02-13 6:01 UTC (permalink / raw)
"JAMES FUNDERBURK" <funderburk1@verizon.net> writes:
> Is there a way to search and replace in nested expressions?
> The particular form of my nested expressions is
> form[x,y,...z] where each 'argument' may be either
> a word (simple character string) or else
> another nested expression. Note that the arguments are
> separated by commas, but there may be only one argument.
> For example, it might be desired to change expressions of the form
> simple[x,y] to simple[y,x] in such a way that
> simple[apple[u],pear[v,w]] is changed to
> simple[pear[v,w],apple[u]].
> I am familiar with Emacs-Lisp, so am looking for a function to do
> such changes on a buffer. I have used the regular expression search and
> replace functions quite a bit, but don't see how to apply them in this
> situation.
Regular expressions are not powerfull enough to handle nested
expressions. You need a parser. That's why lisp (lack of) syntax is
best: you only need one simple parser to parse any language and any
data.
To change:
(simple (apple u) (pear v w))
into:
(simple (pear v w) (apple u))
I only need to type:
(replace-sexps (buffer-file-name (current-buffer))
(lambda (sexp) (if (and (consp sexp)
(eq 'simple (first sexp))
(= 3 (length sexp)))
`(simple ,(third sexp) ,(second sexp))
sexp)) :deeply t)
http://www.informatimago.com/develop/emacs
cvs -z3 -d :pserver:anonymous@cvs.informatimago.com:/usr/local/cvs/public/chrooted-cvs/cvs co emacs
(see pjb-sources.el)
--
__Pascal Bourguignon__ http://www.informatimago.com/
ADVISORY: There is an extremely small but nonzero chance that,
through a process known as "tunneling," this product may
spontaneously disappear from its present location and reappear at
any random place in the universe, including your neighbor's
domicile. The manufacturer will not be responsible for any damages
or inconveniences that may result.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-02-13 6:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-13 5:22 how to search and replace in nested expressions JAMES FUNDERBURK
2006-02-13 6:01 ` Pascal Bourguignon
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.