Discussion:
Irritation about re-search-backward
Marco Wahl
2018-05-24 13:42:31 UTC
Permalink
Hi,

with "|" marking point and the following buffer

#v+
aaaaaaaaaaaa|
#v-

M-: (re-search-backward "a*")

does not change point.

Shouldn't point have been moved to the beginning of the line?

BTW

#v+
|aaaaaaaaaaaa
#v-

M-: (re-search-forward "a*")

moves point to the end of the line.


Any hint would be nice, thanks,
Marco
Michael Heerdegen
2018-05-24 15:41:50 UTC
Permalink
Post by Marco Wahl
Hi,
with "|" marking point and the following buffer
#v+
aaaaaaaaaaaa|
#v-
M-: (re-search-backward "a*")
does not change point.
Shouldn't point have been moved to the beginning of the line?
Good question - but it's the intended behavior. Try

(progn (re-search-backward "a*")
(message "Matched string: \"%s\"" (match-string 0))
(sit-for 2))

The docstring once included this sentence:

The match found is the one starting last in the buffer
and yet ending before the origin of the search.

but it obviously has been removed.

I would make a bug report, since the documentation is insufficient in
this regard.


Michael.
Marco Wahl
2018-05-24 20:25:39 UTC
Permalink
Post by Michael Heerdegen
Post by Marco Wahl
Hi,
with "|" marking point and the following buffer
nn>> #v+
Post by Michael Heerdegen
Post by Marco Wahl
aaaaaaaaaaaa|
#v-
M-: (re-search-backward "a*")
does not change point.
Shouldn't point have been moved to the beginning of the line?
Good question - but it's the intended behavior. Try
(progn (re-search-backward "a*")
(message "Matched string: \"%s\"" (match-string 0))
(sit-for 2))
Thanks!

BTW to get the "greedy" match backwards I use now a further element in
the search pattern like (re-search-backward "^a*").

[...]
Post by Michael Heerdegen
I would make a bug report, since the documentation is insufficient in
this regard.
Thanks for the suggestion but I won't file a report. If you would like
to take over feel free to do so.


Best regards,
--
Marco
Michael Heerdegen
2018-05-24 21:33:55 UTC
Permalink
Post by Marco Wahl
Thanks for the suggestion but I won't file a report. If you would like
to take over feel free to do so.
Done - see Bug#31584.


Michael.
Andreas Röhler
2018-05-25 06:32:04 UTC
Permalink
Post by Michael Heerdegen
Post by Marco Wahl
Hi,
with "|" marking point and the following buffer
#v+
aaaaaaaaaaaa|
#v-
M-: (re-search-backward "a*")
does not change point.
Shouldn't point have been moved to the beginning of the line?
Good question - but it's the intended behavior. Try
Wouldn't say "intended", just "as is".
Ralf Fassel
2018-05-25 09:23:59 UTC
Permalink
* Marco Wahl <***@gmail.com>
| BTW to get the "greedy" match backwards I use now a further element in
| the search pattern like (re-search-backward "^a*").

Note that this matches each and every line, even those not starting with 'a'.

HTH
R'
Michael Heerdegen
2018-05-25 13:03:53 UTC
Permalink
Post by Ralf Fassel
| BTW to get the "greedy" match backwards I use now a further element in
| the search pattern like (re-search-backward "^a*").
Note that this matches each and every line, even those not starting with 'a'.
Indeed. Or the OP wants `looking-back' instead of `re-search-backward'.


Michael.

Continue reading on narkive:
Loading...