[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: return of replace-match
From: |
Alex Kost |
Subject: |
Re: return of replace-match |
Date: |
Wed, 05 Mar 2014 11:29:17 +0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
Phillip Lord (2014-03-04 18:42 +0400) wrote:
> I've been trying out "replace-match". The elisp manual says....
>
> -- Function: replace-match replacement &optional fixedcase literal
> string subexp
> This function performs a replacement operation on a buffer or
> string.
>
> If you did the last search in a buffer, you should omit the STRING
> argument or specify `nil' for it, and make sure that the current
> buffer is the one in which you performed the last search. Then
> this function edits the buffer, replacing the matched text with
> REPLACEMENT. It leaves point at the end of the replacement text,
> and returns `t'.
>
>
> However, if I eval the progn below (with bob where it says)
>
> (progn
> (re-search-forward "bob")
> (replace-match "fred"))
>
> bob
>
>
>
> point gets moved to the end of "bob" (now "fred") but "nil" is returned.
>
>
> The docstring doesn't say anything at all about return types (unless
> operating over a string.
>
> Am I doing something wrong?
>
> Phil
It looks correct to me. When the docstring tells nothing about the
returning value, it may be anything and you shouldn't rely on it.
`replace-match' returns a string when you operate on a string, not a
text in a buffer.