* Re: Question on re-search-forward and infinite loop
[not found] <mailman.11588.1259269277.2239.help-gnu-emacs@gnu.org>
@ 2009-11-26 23:17 ` Barry Margolin
2009-11-30 8:24 ` David Maus
0 siblings, 1 reply; 4+ messages in thread
From: Barry Margolin @ 2009-11-26 23:17 UTC (permalink / raw)
To: help-gnu-emacs
In article <mailman.11588.1259269277.2239.help-gnu-emacs@gnu.org>,
David Maus <maus.david@gmail.com> 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 ***
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Question on re-search-forward and infinite loop
2009-11-26 23:17 ` Question on re-search-forward and infinite loop Barry Margolin
@ 2009-11-30 8:24 ` David Maus
0 siblings, 0 replies; 4+ messages in thread
From: David Maus @ 2009-11-30 8:24 UTC (permalink / raw)
To: help-gnu-emacs
Hi there,
At Thu, 26 Nov 2009 18:17:16 -0500,
Barry Margolin wrote:
>
> 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.
Thanks, this makes perfect sense to me.
Regards,
-- David
--
OpenPGP... 0x316F4BE4670716FD
Jabber.... dmjena@jabber.org
Email..... maus.david@gmail.com
ICQ....... 241051416
^ permalink raw reply [flat|nested] 4+ messages in thread
* Question on re-search-forward and infinite loop
@ 2009-11-26 21:01 David Maus
2009-11-26 21:11 ` Lennart Borgman
0 siblings, 1 reply; 4+ messages in thread
From: David Maus @ 2009-11-26 21:01 UTC (permalink / raw)
To: help-gnu-emacs
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?
Regards,
-- David
--
OpenPGP... 0x316F4BE4670716FD
Jabber.... dmjena@jabber.org
Email..... maus.david@gmail.com
ICQ....... 241051416
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Question on re-search-forward and infinite loop
2009-11-26 21:01 David Maus
@ 2009-11-26 21:11 ` Lennart Borgman
0 siblings, 0 replies; 4+ messages in thread
From: Lennart Borgman @ 2009-11-26 21:11 UTC (permalink / raw)
To: David Maus; +Cc: help-gnu-emacs
On Thu, Nov 26, 2009 at 10:01 PM, David Maus <maus.david@gmail.com> 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?
If the match on next line is 0 chars long then it will not move forward.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-11-30 8:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.11588.1259269277.2239.help-gnu-emacs@gnu.org>
2009-11-26 23:17 ` Question on re-search-forward and infinite loop Barry Margolin
2009-11-30 8:24 ` David Maus
2009-11-26 21:01 David Maus
2009-11-26 21:11 ` Lennart Borgman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).