From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: error in replace-match: "args out of range" Date: Mon, 28 Mar 2011 11:38:53 -0400 Organization: A noiseless patient Spider Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1301326875 14431 80.91.229.12 (28 Mar 2011 15:41:15 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 28 Mar 2011 15:41:15 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Mar 28 17:41:11 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Q4EZ4-0005tW-G1 for geh-help-gnu-emacs@m.gmane.org; Mon, 28 Mar 2011 17:41:10 +0200 Original-Received: from localhost ([127.0.0.1]:58933 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q4EZ3-0005PT-6u for geh-help-gnu-emacs@m.gmane.org; Mon, 28 Mar 2011 11:41:09 -0400 Original-Path: usenet.stanford.edu!news-transit.tcx.org.uk!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 18 Injection-Info: mx02.eternal-september.org; posting-host="JfJMFqoEbuv0BaZrffjHBg"; logging-data="29938"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+IY3mj8qgy5hbrCmpBzTLc" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:3eBeF92PycjM7pdAAsnsva4oqxw= sha1:eqtmKxa/CbmXBwBUbWlL71TSBak= Original-Xref: usenet.stanford.edu gnu.emacs.help:186355 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:80483 Archived-At: > 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