all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Eli Barzilay <eli@barzilay.org>
Cc: 20395@debbugs.gnu.org
Subject: bug#20395: 24.3; Documentation for `replace-regexp-in-string'
Date: Tue, 21 Apr 2015 18:00:01 +0300	[thread overview]
Message-ID: <83383t5xxq.fsf@gnu.org> (raw)
In-Reply-To: <21814.8037.812473.636136@home.barzilay.org>

> From: Eli Barzilay <eli@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	other threads:[~2015-04-21 15:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-21  9:59 bug#20395: 24.3; Documentation for `replace-regexp-in-string' Eli Barzilay
2015-04-21 15:00 ` Eli Zaretskii [this message]
2015-04-25  9:40 ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83383t5xxq.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=20395@debbugs.gnu.org \
    --cc=eli@barzilay.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.