help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: error in replace-match: "args out of range"


From: Stefan Monnier
Subject: Re: error in replace-match: "args out of range"
Date: Mon, 28 Mar 2011 11:38:53 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

>   eval((replace-match head-text-nested t nil head-text 4))

There's your problem right there: replace-match operates on the
match-data "returned" (i.e. set up) by the previous regexp match.
Now regexp matches happen *all the time* in Emacs, so the match-data
gets changed continuously.  So your above command will, maybe,
sometimes, operate on the match-data you want, but other times it will
operate on the match-data corresponding to some other regexp-match
you're not even aware of.

The only way to use replace-match reliably is to do it in the same piece
of code that did the regex-match and make sure nothing of importance
happens in between.  Going back to the top-level is not "nothing of
importance" since it'll run various hooks, may run pending timers,
process filters, plus cause redisplay which may call font-lock, etc...


        Stefan


reply via email to

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