unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [bojohan+mail@dd.chalmers.se: replace-regexp at end of buffer]
@ 2007-02-26  8:47 Richard Stallman
  2007-02-27 16:23 ` Chong Yidong
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Stallman @ 2007-02-26  8:47 UTC (permalink / raw)
  To: emacs-devel

Would someone please check that this is correct,
and if so install it and ack?

------- Start of forwarded message -------
From: bojohan+mail@dd.chalmers.se (Johan =?utf-8?Q?Bockg=C3=A5rd?=)
To: emacs-pretest-bug@gnu.org
Date: Thu, 22 Feb 2007 19:57:57 +0100
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Subject: replace-regexp at end of buffer
X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=failed 
	version=3.0.4


replace-regexp/perform-replace wrongly moves back a character when the
match is at end of buffer.

Run

   (perform-replace "abc" "123" nil t nil)

on a buffer that ends in "abc" (no final newline).

Point ends up between 2 and 3.

This is because point could not move too far in this case, and so the
following correction shouldn't be done [perform-replace]:

   ;; The code preventing adjacent regexp matches in the condition
   ;; of the while-loop above will haven taken us one character
   ;; beyond the last replacement.  Undo that.
   (when (and regexp-flag (not match-again) (> replace-count 0))
     (backward-char 1))


- -- 
Johan Bockgård


_______________________________________________
emacs-pretest-bug mailing list
emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug
------- End of forwarded message -------

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

* Re: [bojohan+mail@dd.chalmers.se: replace-regexp at end of buffer]
  2007-02-26  8:47 [bojohan+mail@dd.chalmers.se: replace-regexp at end of buffer] Richard Stallman
@ 2007-02-27 16:23 ` Chong Yidong
  2007-02-27 17:56   ` Johan Bockgård
  2007-02-28  2:38   ` Richard Stallman
  0 siblings, 2 replies; 5+ messages in thread
From: Chong Yidong @ 2007-02-27 16:23 UTC (permalink / raw)
  To: rms; +Cc: emacs-devel

Richard Stallman <rms@gnu.org> writes:

> Would someone please check that this is correct,
> and if so install it and ack?

perform-replace is a subroutine of query-replace, which does not
exhibit any problem (it corrects the buffer position when this case
occurs).  It is not used in generic Elisp code, which should be using
replace-match instead.

Therefore, no fix is required or desired.

> replace-regexp/perform-replace wrongly moves back a character when the
> match is at end of buffer.
>
> Run
>
>    (perform-replace "abc" "123" nil t nil)
>
> on a buffer that ends in "abc" (no final newline).
>
> Point ends up between 2 and 3.
>
> This is because point could not move too far in this case, and so the
> following correction shouldn't be done [perform-replace]:
>
>    ;; The code preventing adjacent regexp matches in the condition
>    ;; of the while-loop above will haven taken us one character
>    ;; beyond the last replacement.  Undo that.
>    (when (and regexp-flag (not match-again) (> replace-count 0))
>      (backward-char 1))

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

* Re: [bojohan+mail@dd.chalmers.se: replace-regexp at end of buffer]
  2007-02-27 16:23 ` Chong Yidong
@ 2007-02-27 17:56   ` Johan Bockgård
  2007-02-28 18:56     ` Chong Yidong
  2007-02-28  2:38   ` Richard Stallman
  1 sibling, 1 reply; 5+ messages in thread
From: Johan Bockgård @ 2007-02-27 17:56 UTC (permalink / raw)
  To: emacs-devel

Chong Yidong <cyd@stupidchicken.com> writes:

> perform-replace is a subroutine of query-replace, which does not
> exhibit any problem (it corrects the buffer position when this case
> occurs). It is not used in generic Elisp code, which should be using
> replace-match instead.
>
> Therefore, no fix is required or desired.

This affects regexp replacement. Try M-x replace-regexp (this command
was already mentioned), or query-replace-regexp if you like.

-- 
Johan Bockgård

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

* Re: [bojohan+mail@dd.chalmers.se: replace-regexp at end of buffer]
  2007-02-27 16:23 ` Chong Yidong
  2007-02-27 17:56   ` Johan Bockgård
@ 2007-02-28  2:38   ` Richard Stallman
  1 sibling, 0 replies; 5+ messages in thread
From: Richard Stallman @ 2007-02-28  2:38 UTC (permalink / raw)
  To: Chong Yidong; +Cc: emacs-devel

    perform-replace is a subroutine of query-replace, which does not
    exhibit any problem (it corrects the buffer position when this case
    occurs).

The bug does not occur in query-replace, but it does occur
in query-replace-regexp.  Some fix is needed.

Can you fix it?

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

* Re: [bojohan+mail@dd.chalmers.se: replace-regexp at end of buffer]
  2007-02-27 17:56   ` Johan Bockgård
@ 2007-02-28 18:56     ` Chong Yidong
  0 siblings, 0 replies; 5+ messages in thread
From: Chong Yidong @ 2007-02-28 18:56 UTC (permalink / raw)
  To: emacs-devel

bojohan+news@dd.chalmers.se (Johan Bockgård) writes:

> Chong Yidong <cyd@stupidchicken.com> writes:
>
>> perform-replace is a subroutine of query-replace, which does not
>> exhibit any problem (it corrects the buffer position when this case
>> occurs). It is not used in generic Elisp code, which should be using
>> replace-match instead.
>>
>> Therefore, no fix is required or desired.
>
> This affects regexp replacement. Try M-x replace-regexp (this command
> was already mentioned), or query-replace-regexp if you like.

I see the problem now.  I've checked in a fix, thanks.

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

end of thread, other threads:[~2007-02-28 18:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-26  8:47 [bojohan+mail@dd.chalmers.se: replace-regexp at end of buffer] Richard Stallman
2007-02-27 16:23 ` Chong Yidong
2007-02-27 17:56   ` Johan Bockgård
2007-02-28 18:56     ` Chong Yidong
2007-02-28  2:38   ` Richard Stallman

Code repositories for project(s) associated with this public inbox

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

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