emacs-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[debbugs-tracker] bug#20395: closed (24.3; Documentation for `replace-re


From: GNU bug Tracking System
Subject: [debbugs-tracker] bug#20395: closed (24.3; Documentation for `replace-regexp-in-string')
Date: Sat, 25 Apr 2015 09:41:02 +0000

Your message dated Sat, 25 Apr 2015 12:40:06 +0300
with message-id <address@hidden>
and subject line Re: bug#20395: 24.3; Documentation for 
`replace-regexp-in-string'
has caused the debbugs.gnu.org bug report #20395,
regarding 24.3; Documentation for `replace-regexp-in-string'
to be marked as done.

(If you believe you have received this mail in error, please contact
address@hidden)


-- 
20395: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=20395
GNU Bug Tracking System
Contact address@hidden with problems
--- Begin Message --- Subject: 24.3; Documentation for `replace-regexp-in-string' 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>".

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!



--- End Message ---
--- Begin Message --- Subject: Re: bug#20395: 24.3; Documentation for `replace-regexp-in-string' Date: Sat, 25 Apr 2015 12:40:06 +0300
> From: Eli Barzilay <address@hidden>
> 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.


--- End Message ---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]