Subject: 31.0.50; quoted-printable-en/decode-region doesn't preserve end markers

From: Stefan Monnier <[email-masked]>
Date: Mon, 06 Jan 2025 23:24:15 -0500

Package: Emacs
Version: 31.0.50

In a fresh Emacs try:

       (with-temp-buffer
         (set-buffer-multibyte nil)
         (insert "\300\300")
         (encode-coding-region (point-min) (point) 'utf-8)
         (quoted-printable-encode-region (point-min) (point))
         (insert "!!")
         (buffer-string))

It will likely return "=C0!!=C0" whereas it should return "=C0=C0!!".

Found via a bug in VM: https://gitlab.com/emacs-vm/vm/-/issues/491

The same problem plagues `quoted-printable-decode-region`.

I think we really need to introduce a `replace-region` primitive which
takes care of preserving the position of markers instead of having to teach
ELisp coders the delicate art of combining `insert(-before-markers)` and
`delete` to best preserve markers.

        Stefan