GNU bug report logs -
#20395
24.3; Documentation for `replace-regexp-in-string'
Previous Next
Reported by: Eli Barzilay <eli <at> barzilay.org>
Date: Tue, 21 Apr 2015 10:00:03 UTC
Severity: minor
Found in version 24.3
Done: Eli Zaretskii <eliz <at> gnu.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 20395 in the body.
You can then email your comments to 20395 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#20395
; Package
emacs
.
(Tue, 21 Apr 2015 10:00:03 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Eli Barzilay <eli <at> barzilay.org>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Tue, 21 Apr 2015 10:00:05 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
(In GNU Emacs 24.3.1, but same in git)
I tried to use `replace-regexp-in-string' like this:
(let ((text "foo\nbar\nbaz\n") (r "*"))
(replace-regexp-in-string
"\n\\(.\\)"
(lambda (_) (concat "\n" r (match-string 1 text)))
text))
and it surprised me that this didn't work. Looking at the docstring,
I found this
When REP is called, the match data are the result of matching
REGEXP against a substring of STRING.
and IMO that "a substring" is very subtle and easy to miss. I then
looked at the code, and at least in its current form, I saw that I
could do this instead:
(let ((text "foo\nbar\nbaz\n") (r "*"))
(replace-regexp-in-string
"\n\\(.\\)"
(lambda (s) (concat "\n" r (match-string 1 s)))
text))
So I think that it would be really good if this was made explicit in
the documentation, better with an example. Something like
When REP is called, the match data are the result of matching
REGEXP against only the currently matched substring of STRING.
For example, (lambda (s) (concat "<" (match-string 1 s) ">")) as
REP is equivalent to "<\\1>".
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://barzilay.org/ Maze is Life!
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#20395
; Package
emacs
.
(Tue, 21 Apr 2015 15:01:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 20395 <at> debbugs.gnu.org (full text, mbox):
> From: Eli Barzilay <eli <at> barzilay.org>
> Date: Tue, 21 Apr 2015 05:59:01 -0400
>
> When REP is called, the match data are the result of matching
> REGEXP against a substring of STRING.
>
> and IMO that "a substring" is very subtle and easy to miss. I then
> looked at the code, and at least in its current form, I saw that I
> could do this instead:
>
> (let ((text "foo\nbar\nbaz\n") (r "*"))
> (replace-regexp-in-string
> "\n\\(.\\)"
> (lambda (s) (concat "\n" r (match-string 1 s)))
> text))
>
> So I think that it would be really good if this was made explicit in
> the documentation, better with an example. Something like
>
> When REP is called, the match data are the result of matching
> REGEXP against only the currently matched substring of STRING.
> For example, (lambda (s) (concat "<" (match-string 1 s) ">")) as
> REP is equivalent to "<\\1>".
Thanks.
However, I wonder whether your suggested change is really enough of an
improvement. AFAIU, the main problem with the existing doc string is
that it doesn't explain _which_ substring is being alluded to here, it
only hints on the answer. And your suggested change also leaves that
part unexplained, leaving it to the reader to glean that from the fact
that 'concat' is being used.
So I think it would be good to come up with text that actually makes
that part clear. WDYT?
Reply sent
to
Eli Zaretskii <eliz <at> gnu.org>
:
You have taken responsibility.
(Sat, 25 Apr 2015 09:41:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Eli Barzilay <eli <at> barzilay.org>
:
bug acknowledged by developer.
(Sat, 25 Apr 2015 09:41:03 GMT)
Full text and
rfc822 format available.
Message #13 received at 20395-done <at> debbugs.gnu.org (full text, mbox):
> From: Eli Barzilay <eli <at> barzilay.org>
> Date: Tue, 21 Apr 2015 05:59:01 -0400
>
> (In GNU Emacs 24.3.1, but same in git)
>
> I tried to use `replace-regexp-in-string' like this:
>
> (let ((text "foo\nbar\nbaz\n") (r "*"))
> (replace-regexp-in-string
> "\n\\(.\\)"
> (lambda (_) (concat "\n" r (match-string 1 text)))
> text))
>
> and it surprised me that this didn't work. Looking at the docstring,
> I found this
>
> When REP is called, the match data are the result of matching
> REGEXP against a substring of STRING.
>
> and IMO that "a substring" is very subtle and easy to miss. I then
> looked at the code, and at least in its current form, I saw that I
> could do this instead:
>
> (let ((text "foo\nbar\nbaz\n") (r "*"))
> (replace-regexp-in-string
> "\n\\(.\\)"
> (lambda (s) (concat "\n" r (match-string 1 s)))
> text))
>
> So I think that it would be really good if this was made explicit in
> the documentation, better with an example. Something like
>
> When REP is called, the match data are the result of matching
> REGEXP against only the currently matched substring of STRING.
> For example, (lambda (s) (concat "<" (match-string 1 s) ">")) as
> REP is equivalent to "<\\1>".
I tried to clarify this issue in a slightly different way.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sat, 23 May 2015 11:24:06 GMT)
Full text and
rfc822 format available.
This bug report was last modified 10 years and 34 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.