Subject: bug#76313: New function `replace-region`

From: Tassilo Horn <[email-masked]>
Date: Mon, 31 Mar 2025 08:21:56 +0200

Stefan Monnier <[email-masked]> writes:

> But I've changed my mind: I don't think we should unify
> `replace-region-contents` and my proposed `replace-region`.
>
> [...]
>
> While that was partly true, some of the problems were a lot more
> delicate: while `replace-region` is "easy" to use to do what I would
> describe as "edits", `replace-region-contents` is a good bit more
> delicate because its effect on point is less predictable.

I think that's a very good point.  Stefan's `replace-region` can be use
to replace text with some arbitrary other text with predictable
positioning of point.  `replace-region-contents` has always had the
assumption that the replacing text is very similar to the text it
replaces, e.g., a differently formatted version it.  Only in this
context it's sensible and intended that point doesn't move "out of the
middle" because only here we can assume the thing point is on is also
there in the replacing text.  (And, yes, the name
`replace-region-contents` doesn't transport that intention well.)

Bye,
Tassilo