From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Barry Margolin Newsgroups: gmane.emacs.help Subject: Re: Question on re-search-forward and infinite loop Date: Thu, 26 Nov 2009 18:17:16 -0500 Organization: A noiseless patient Spider Message-ID: References: NNTP-Posting-Host: lo.gmane.org X-Trace: ger.gmane.org 1259278857 29687 80.91.229.12 (26 Nov 2009 23:40:57 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 26 Nov 2009 23:40:57 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Nov 27 00:40:50 2009 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.50) id 1NDnxC-0006Xj-2I for geh-help-gnu-emacs@m.gmane.org; Fri, 27 Nov 2009 00:40:50 +0100 Original-Received: from localhost ([127.0.0.1]:60087 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDnxB-0006Cd-N7 for geh-help-gnu-emacs@m.gmane.org; Thu, 26 Nov 2009 18:40:49 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!goblin1!goblin.stu.neva.ru!feeder.eternal-september.org!eternal-september.org!news.eternal-september.org!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 37 Original-X-Trace: news.eternal-september.org U2FsdGVkX1+zXioOZzPlAEGfLNOEtUJ08/3iD4AnEct7eGIY0a8tjgngBqiqTxpnkQSCSFj4lOKoo+wNnBPn8IzA5xPml6w8y5VyPm0dnMFFwPVj2CUGOtpgRolVW1GA6d9CA7eARxU= Original-X-Complaints-To: abuse@eternal-september.org Original-NNTP-Posting-Date: Thu, 26 Nov 2009 23:17:16 +0000 (UTC) User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) X-Auth-Sender: U2FsdGVkX1/zAVF2vfDzWnLmYJGA31uuv5H7Mkz9yhU= Cancel-Lock: sha1:4B/gFxcE1hIJYZfaJcGv8Qdqy7A= Original-Xref: news.stanford.edu gnu.emacs.help:175098 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:70164 Archived-At: In article , David Maus wrote: > Hi, > > By accident I stumpled on a way to force Emacs in a infinite loop with > `re-search-forward'. > > If I create a shiny new buffer, insert something like this: > > ,---- > | (while (re-search-forward "^[ \t]*")) > | Something else > `---- > > -- go back beyond the while-clause and evaluate it, Emacs enters an > infinite loop. As far as I was able to find out > `re-search-forward' with this regexp moves point to the beginning > of the next line above the "S" of "Something else" and stays there > forever so it never reaches end-of-buffer. > > As I dunno much (or better: anything) on Emacs' interiors my question > is: Why does this happen? Your regexp matches zero or more whitespace characters at the beginning of a line. If there's an empty line at the end of the buffer, it will match that. But since it's a zero-length match, point is left at that position, and the next time around it again matches it. In general, whenever a regexp can match a zero-length string, I think that type of loop will go infinitely. -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** *** PLEASE don't copy me on replies, I'll read them in the group ***