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: ken
Subject: Re: error in replace-match: "args out of range"
Date: Mon, 28 Mar 2011 14:50:04 -0400
User-agent: Thunderbird 2.0.0.24 (X11/20101213)

On 03/28/2011 11:38 AM Stefan Monnier wrote:
>>   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

Stefan,

Thanks for your reply.

I know that the error occurs on that line.  What I'm trying to figure
out is what to change on that line to correct the problem... resolve the
error.  I understand that another search-- one invoked since the
subexpressions were set for the above-cited replace-match-- will render
ineffective those subexpressions.  However, this replace-match (and
others used in the same function) occurs after the relevant search and
there is no other search occurring in between.  In fact, the relevant
search (the one where the relevant replace-match sets needed
subexpressions) is the *last* one in this function.

Moreover, I've run this function through edebug and when I evaluate the
individual variables inside the above-cited replace-match, those
variables do evaluate to the desired values.

Now I'm trying to understand what you're saying in your last sentence
above.  Are you saying that another search invoked by emacs and outside
of my code could alter the values of subexpressions of my last search?
If so, this would counsel against ever using replace-match *ever* in any
code.  For this reason I don't think it's what you're saying, or what is
actually confounding my replace-match.  Besides this, as said,
evaluating the values of the variables (excepting of course the final
arg consisting of the subexpression number) shows that those variables
contain expected values.

Let me add that I've altered the args to the above replace-match and get
the same error message.  Strangely the out-of-range args are "-1 -1".
What does that particular couple of numbers signify?

Thanks again for the reply.






reply via email to

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