unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* return of replace-match
@ 2014-03-04 14:42 Phillip Lord
  2014-03-04 15:16 ` Michael Heerdegen
  2014-03-05  7:29 ` Alex Kost
  0 siblings, 2 replies; 7+ messages in thread
From: Phillip Lord @ 2014-03-04 14:42 UTC (permalink / raw)
  To: Help-gnu-emacs



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



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: return of replace-match
  2014-03-04 14:42 return of replace-match Phillip Lord
@ 2014-03-04 15:16 ` Michael Heerdegen
  2014-03-04 15:33   ` Phillip Lord
  2014-03-05  7:29 ` Alex Kost
  1 sibling, 1 reply; 7+ messages in thread
From: Michael Heerdegen @ 2014-03-04 15:16 UTC (permalink / raw)
  To: help-gnu-emacs

phillip.lord@newcastle.ac.uk (Phillip Lord) writes:

> (progn
>   (re-search-forward "bob")
>   (replace-match "fred"))
>
> bob
>
> point gets moved to the end of "bob" (now "fred") but "nil" is returned.

> Am I doing something wrong?

I think the manual is just lying.  If nobody disagrees, please make a
bug report.


Regards,

Michael.




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: return of replace-match
  2014-03-04 15:16 ` Michael Heerdegen
@ 2014-03-04 15:33   ` Phillip Lord
  0 siblings, 0 replies; 7+ messages in thread
From: Phillip Lord @ 2014-03-04 15:33 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs

Michael Heerdegen <michael_heerdegen@web.de> writes:

> phillip.lord@newcastle.ac.uk (Phillip Lord) writes:
>
>> (progn
>>   (re-search-forward "bob")
>>   (replace-match "fred"))
>>
>> bob
>>
>> point gets moved to the end of "bob" (now "fred") but "nil" is returned.
>
>> Am I doing something wrong?
>
> I think the manual is just lying.  If nobody disagrees, please make a
> bug report.


Was my impression!

Phil



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: return of replace-match
  2014-03-04 14:42 return of replace-match Phillip Lord
  2014-03-04 15:16 ` Michael Heerdegen
@ 2014-03-05  7:29 ` Alex Kost
  2014-03-05  9:15   ` Bastien
  1 sibling, 1 reply; 7+ messages in thread
From: Alex Kost @ 2014-03-05  7:29 UTC (permalink / raw)
  To: help-gnu-emacs

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.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: return of replace-match
  2014-03-05  7:29 ` Alex Kost
@ 2014-03-05  9:15   ` Bastien
  2014-03-05 10:58     ` Phillip Lord
  2014-03-05 11:11     ` Nicolas Richard
  0 siblings, 2 replies; 7+ messages in thread
From: Bastien @ 2014-03-05  9:15 UTC (permalink / raw)
  To: Alex Kost; +Cc: help-gnu-emacs

Alex Kost <alezost@gmail.com> writes:

> 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.

IIUC, the problem here is that the docstring says it will return `t'
and return `nil' instead.  I guess that's just a documentation bug.

-- 
 Bastien



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: return of replace-match
  2014-03-05  9:15   ` Bastien
@ 2014-03-05 10:58     ` Phillip Lord
  2014-03-05 11:11     ` Nicolas Richard
  1 sibling, 0 replies; 7+ messages in thread
From: Phillip Lord @ 2014-03-05 10:58 UTC (permalink / raw)
  To: Bastien; +Cc: Alex Kost, help-gnu-emacs



Bastien <bzg@altern.org> writes:

> Alex Kost <alezost@gmail.com> writes:
>
>> 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.
>
> IIUC, the problem here is that the docstring says it will return `t'
> and return `nil' instead.  I guess that's just a documentation bug.

The docstring doesn't say anything. The elisp manual says "returns `t`".

I'll send a bug report.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: return of replace-match
  2014-03-05  9:15   ` Bastien
  2014-03-05 10:58     ` Phillip Lord
@ 2014-03-05 11:11     ` Nicolas Richard
  1 sibling, 0 replies; 7+ messages in thread
From: Nicolas Richard @ 2014-03-05 11:11 UTC (permalink / raw)
  To: Bastien; +Cc: Alex Kost, help-gnu-emacs

Bastien <bzg@altern.org> writes:
> Alex Kost <alezost@gmail.com> writes:
>> 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.
>
> IIUC, the problem here is that the docstring says it will return `t'
> and return `nil' instead.

s/docstring/info manual/
See (info "(elisp) Replacing Match")

> I guess that's just a documentation bug.

Agreed. "return Qnil" has been in the code forever as far as I can see
(which is what C-x v g can see).

-- 
Nico.



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-03-05 11:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-04 14:42 return of replace-match Phillip Lord
2014-03-04 15:16 ` Michael Heerdegen
2014-03-04 15:33   ` Phillip Lord
2014-03-05  7:29 ` Alex Kost
2014-03-05  9:15   ` Bastien
2014-03-05 10:58     ` Phillip Lord
2014-03-05 11:11     ` Nicolas Richard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).