unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Trouble in understanding the behavior of search-backward-regexp
@ 2009-09-07 16:03 Alain Cochard
  2009-09-07 16:17 ` Joost Kremers
  0 siblings, 1 reply; 3+ messages in thread
From: Alain Cochard @ 2009-09-07 16:03 UTC (permalink / raw)
  To: help-gnu-emacs

Hello.  The trouble concerns the regular expression 

   [[:blank:]]+ 

for which I read that it matches any sequence of spaces and tabs.

Let me start with search-forward-regexp, with which I have no problem.
Let us say I have the following sentence:

   foo                                     bar

with spaces and tabs between the two words

If I put the cursor at the beginning and I use 'search-forward-regexp'
with this [[:blank:]]+, I end up with the cursor right on the 'b',
which is what I expect.

Now, if I put the cursor at the end of that sentence and use
search-backward-regexp, again with [[:blank:]]+, I would expect to end
up on the second 'o' of 'foo'.  Instead, I end up somewhere between
the two words, which is very mysterious to me (I have tried with
several combinations of emacs-version/distributions/hardware).

Thanks in advance for any tip.
Alain


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Trouble in understanding the behavior of search-backward-regexp
  2009-09-07 16:03 Trouble in understanding the behavior of search-backward-regexp Alain Cochard
@ 2009-09-07 16:17 ` Joost Kremers
  2009-09-07 16:52   ` Alain Cochard
  0 siblings, 1 reply; 3+ messages in thread
From: Joost Kremers @ 2009-09-07 16:17 UTC (permalink / raw)
  To: help-gnu-emacs

Alain Cochard wrote:
> Hello.  The trouble concerns the regular expression 
>
>    [[:blank:]]+ 
>
> for which I read that it matches any sequence of spaces and tabs.
>
> Let me start with search-forward-regexp, with which I have no problem.
> Let us say I have the following sentence:
>
>    foo                                     bar
>
> with spaces and tabs between the two words
>
> If I put the cursor at the beginning and I use 'search-forward-regexp'
> with this [[:blank:]]+, I end up with the cursor right on the 'b',
> which is what I expect.
>
> Now, if I put the cursor at the end of that sentence and use
> search-backward-regexp, again with [[:blank:]]+, I would expect to end
> up on the second 'o' of 'foo'.  Instead, I end up somewhere between
> the two words, which is very mysterious to me (I have tried with
> several combinations of emacs-version/distributions/hardware).

it does so because a single space/tab also matches "[[:blank:]]+". and while
emacs searches backwards, it looks forward for a matching string. so the first
matching string it finds is the single space/tab directly before "bar". the
cursor is then put at the beginning of this string.


-- 
Joost Kremers                                      joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Trouble in understanding the behavior of search-backward-regexp
  2009-09-07 16:17 ` Joost Kremers
@ 2009-09-07 16:52   ` Alain Cochard
  0 siblings, 0 replies; 3+ messages in thread
From: Alain Cochard @ 2009-09-07 16:52 UTC (permalink / raw)
  To: help-gnu-emacs

Joost Kremers <joostkremers@yahoo.com> writes:

> Alain Cochard wrote:
>> Hello.  The trouble concerns the regular expression 
>>
>>    [[:blank:]]+ 
>>
>> for which I read that it matches any sequence of spaces and tabs.
>>
>> Let me start with search-forward-regexp, with which I have no problem.
>> Let us say I have the following sentence:
>>
>>    foo                                     bar
>>
>> with spaces and tabs between the two words
>>
>> If I put the cursor at the beginning and I use 'search-forward-regexp'
>> with this [[:blank:]]+, I end up with the cursor right on the 'b',
>> which is what I expect.
>>
>> Now, if I put the cursor at the end of that sentence and use
>> search-backward-regexp, again with [[:blank:]]+, I would expect to
>> end up on the second 'o' of 'foo'.  Instead, I end up somewhere
>> between the two words, which is very mysterious to me (I have tried
>> with several combinations of emacs-version/distributions/hardware).

> it does so because a single space/tab also matches
> "[[:blank:]]+". and while emacs searches backwards, it looks forward
> for a matching string. so the first matching string it finds is the
> single space/tab directly before "bar". the cursor is then put at
> the beginning of this string.

Thanks much for the fast reply.  There is this paragraph in the elisp
manual about search-forward-regexp and search-backward-regexp not
being simple mirror images, which I could not understand.  I guess
this is related and I think I understand it better with your
explanation.

Thanks again,
Alain


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-09-07 16:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-07 16:03 Trouble in understanding the behavior of search-backward-regexp Alain Cochard
2009-09-07 16:17 ` Joost Kremers
2009-09-07 16:52   ` Alain Cochard

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).