GNU bug report logs - #76313
New function `replace-region`

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Stefan Monnier <monnier@HIDDEN>; Keywords: patch; dated Sat, 15 Feb 2025 22:19:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 8 Mar 2025 09:46:30 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 08 04:46:30 2025
Received: from localhost ([127.0.0.1]:52878 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tqqlK-00052A-AT
	for submit <at> debbugs.gnu.org; Sat, 08 Mar 2025 04:46:30 -0500
Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]:61835)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <stefankangas@HIDDEN>)
 id 1tqqlH-00051n-HV
 for 76313 <at> debbugs.gnu.org; Sat, 08 Mar 2025 04:46:28 -0500
Received: by mail-ed1-x531.google.com with SMTP id
 4fb4d7f45d1cf-5e5c9662131so4173136a12.3
 for <76313 <at> debbugs.gnu.org>; Sat, 08 Mar 2025 01:46:27 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1741427181; x=1742031981; darn=debbugs.gnu.org;
 h=cc:to:subject:message-id:date:mime-version:references:in-reply-to
 :from:from:to:cc:subject:date:message-id:reply-to;
 bh=TXt33jtH4QlG1nC7t/mQwTcXRT4MZsllhSea7IX4/to=;
 b=BaDw8B2C/BhKhD/iJcorZuF9V5i+BNVH1vhQLB4MOTzIaVNdBs2xL5znCffB4dSEzX
 MW8PJF5kpuQv0u96S/ffwvH/qO4l5bVmvBFpwmbRqs1D0a95I/jXexKc/MAm4i2JLLX+
 idJkPAyVdWBgau1P6OCICM86TlpX8G2JDYoX1W8pIJi0iThqd4fTGo571kEAhgEQnF/O
 GECIzVTEQm/uYRwPaIarZ5CNLG5ztx8lq/JnvbYY3US7RvVYWuWVtRPWySIfJuU7qpip
 DO3LnJBvx3/Se8tEwQ4F8A9daC6eELGW1lONreEjffmLh++DMMshXa3O2ePR5R6VEZSk
 Z36w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1741427181; x=1742031981;
 h=cc:to:subject:message-id:date:mime-version:references:in-reply-to
 :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=TXt33jtH4QlG1nC7t/mQwTcXRT4MZsllhSea7IX4/to=;
 b=gTH1OqdKEgMQ4qGiSPFkJO6IET9PW7uC/oQGUP1h4odbPO50piFvHSHawo+T9uyZBC
 HAHYtNks3w67rgWvUOIVl5QKBweZcDd6sZO2WL7C0fL0yTgA1bsREkxZuLqa7QP252v+
 84PqtvVfHiCSK3kN5OcnCNeQj3IcVcqZBfVpviV1Oq/KBT1WRT9VhELFFTbNVt9ZXW3V
 +wsUn8LB6ph3o85RZCNSxKRpuXBgEHG/aU1AAues3WotdkS1Fo9ZInmEGJyvJAkl96gf
 sm6v85pwrPZWE6T97B5/+FByuZr0kd1633CgqLJf9hD3TDzNKlmj4FDGhy+qLR0j3gZ/
 5PTA==
X-Gm-Message-State: AOJu0YyPI41Fg6pHZi6miwYCqAPUDRGovRRbYqYPEll/Z2LDuTf2kwcE
 qcgIBYegZNZZO8E9rcU5clg299U4k+fJvfGTgTvbvV2eeUaq6ukegbYZXGqsLAONrOHO7vUl/kJ
 n/Mu21cXPOnzJkC6OTl2JfcYWWdo=
X-Gm-Gg: ASbGncuAEQQ2y5by+cPC7r/1kImp05x2xv7pe+mwvePZJDHTPqonGcw5JEVt/IX4w3X
 aTdVVA4f+XC1D5f9MOfcZsio0jeV6H/V9+xp6y5uBCfPPN6BauqEWk5LOIyWXjjWn0EDg0Ek81/
 VY/MDnU8WtKvvLRRT6sBvOGpQMkw==
X-Google-Smtp-Source: AGHT+IGGyL935nBOuwB4OoTQY4OgnxU43wtdOfR7dy6GY3mCOzayxlDvHin56cV7LiiRFQ0J3usi/9THJK/2fw3ATDQ=
X-Received: by 2002:a05:6402:2157:b0:5e5:e78a:c501 with SMTP id
 4fb4d7f45d1cf-5e5e78ac8f9mr5532362a12.13.1741427181188; Sat, 08 Mar 2025
 01:46:21 -0800 (PST)
Received: from 753933720722 named unknown by gmailapi.google.com with
 HTTPREST; Sat, 8 Mar 2025 01:46:20 -0800
From: Stefan Kangas <stefankangas@HIDDEN>
In-Reply-To: <86sennkiv8.fsf@HIDDEN>
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <865xl8blam.fsf@HIDDEN>
 <jwvy0y49w9z.fsf-monnier+emacs@HIDDEN> <86ldu3a18y.fsf@HIDDEN>
 <jwvpljf1jh5.fsf-monnier+emacs@HIDDEN> <86msej8du2.fsf@HIDDEN>
 <jwvtt8ryyzl.fsf-monnier+emacs@HIDDEN> <86a5aj82zq.fsf@HIDDEN>
 <jwvtt8rxbnr.fsf-monnier+emacs@HIDDEN> <86h64q6t87.fsf@HIDDEN>
 <jwveczuugkw.fsf-monnier+emacs@HIDDEN>
 <CADwFkmm_wYVQRMk83EJww9mTbboCcyTTc-bVVbog9SNeN0d05A@HIDDEN>
 <87r03tw121.fsf@HIDDEN>
 <CADwFkmn_G9DZjk_cjzPOtAr9wpQQ6tUVVjp3fBnetyT8cGahfA@HIDDEN>
 <jwvpljbguqm.fsf-monnier+emacs@HIDDEN>
 <CADwFkmnL1VaEh+hdMjY6fPXOQDhOw6b9QP0ySY9K9Q_C5YwdGA@HIDDEN>
 <864j07pqh7.fsf@HIDDEN>
 <CADwFkmneyHrb9GAK4MxeK1RPtSJa3P1W2wtNL=OuwJHJRudnow@HIDDEN>
 <861pvao89f.fsf@HIDDEN>
 <CADwFkmkuxfQtHcuzAdfi9hbvookoskT5wUa5JF+30aUBpz=1XA@HIDDEN>
 <86sennkiv8.fsf@HIDDEN>
MIME-Version: 1.0
Date: Sat, 8 Mar 2025 01:46:20 -0800
X-Gm-Features: AQ5f1JqcZJ8o3hEdGa0zuPLp_vPZBJw57Ei2Sjga9e05PdsigVs2P1uOcBSCSP4
Message-ID: <CADwFkm=5VjYgFKe5Mp3Nf1aOkxf_=ra0ihRvZ+arh_BBxnyhLA@HIDDEN>
Subject: Re: bug#76313: New function `replace-region`
To: Eli Zaretskii <eliz@HIDDEN>
Content-Type: text/plain; charset="UTF-8"
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76313
Cc: 76313 <at> debbugs.gnu.org, monnier@HIDDEN, tsdh@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Eli Zaretskii <eliz@HIDDEN> writes:

> I'm saying that the documentation aspect of this is not the real
> problem.  Once we agree on the code and API changes, updating the
> documentation is a no-brainer, and I don't expect it to trigger an
> argument.
>
> The problem here is how to provide the functionality without
> complicating Emacs with yet another API, where we already have two.

OK, thanks.  That makes it more clear to me what you're saying.

I don't have any better solution to propose than:

    a) Obsoleting `replace-buffer-contents`.

    b) Renaming `replace-region-contents` to `replace-region-carefully`.

I think both of these would make sense independently of `replace-region`.
How about we move ahead with those, and then revisit the situation once
that is done?




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 8 Mar 2025 08:49:12 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 08 03:49:12 2025
Received: from localhost ([127.0.0.1]:52742 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tqprr-0007Rl-Fr
	for submit <at> debbugs.gnu.org; Sat, 08 Mar 2025 03:49:11 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:52234)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tqpro-0007RP-9J
 for 76313 <at> debbugs.gnu.org; Sat, 08 Mar 2025 03:49:09 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1tqprh-0008BE-U1; Sat, 08 Mar 2025 03:49:01 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=ObBWtjW8zhA8C4b5tc1ij+Xz32vVHCbT0F1G/iSPRac=; b=PnRkKGS/inE6
 e7Nx5S/X3vWJoJ0p457BrPiTK0+qh3RfEw1+E5ozFNLm2n335eQ0GEZyuGS+Qd8o86gqOPNjqybr1
 BasbNOqKPiAvWm9bniMkmP1Ntou3dp7G46fof1fRsUoy2+kuQ3Pz1MSpam/W92QDrvOJMEvm4CPZJ
 01zG1J9d3CPhMJpabmli1e7C0lEwa60gN+36k5fr9Wemcdf4dSk1NRZCvW4RDFRmrOpiKBi/2zSal
 urIoyEtZTH236qkWhJfkkwfcZTolmdDU4q6VQI0z+vv8ZIxffGTZ8/2T2LvmVhjdby8FKlJLfG7YH
 qGxg+c+q4LsAzD5QVBRBiQ==;
Date: Sat, 08 Mar 2025 10:48:59 +0200
Message-Id: <86sennkiv8.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Stefan Kangas <stefankangas@HIDDEN>
In-Reply-To: <CADwFkmkuxfQtHcuzAdfi9hbvookoskT5wUa5JF+30aUBpz=1XA@HIDDEN>
 (message from Stefan Kangas on Fri, 7 Mar 2025 20:23:09 +0000)
Subject: Re: bug#76313: New function `replace-region`
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86h64sbw57.fsf@HIDDEN>
 <jwvzfik398m.fsf-monnier+emacs@HIDDEN> <865xl8blam.fsf@HIDDEN>
 <jwvy0y49w9z.fsf-monnier+emacs@HIDDEN> <86ldu3a18y.fsf@HIDDEN>
 <jwvpljf1jh5.fsf-monnier+emacs@HIDDEN> <86msej8du2.fsf@HIDDEN>
 <jwvtt8ryyzl.fsf-monnier+emacs@HIDDEN> <86a5aj82zq.fsf@HIDDEN>
 <jwvtt8rxbnr.fsf-monnier+emacs@HIDDEN> <86h64q6t87.fsf@HIDDEN>
 <jwveczuugkw.fsf-monnier+emacs@HIDDEN>
 <CADwFkmm_wYVQRMk83EJww9mTbboCcyTTc-bVVbog9SNeN0d05A@HIDDEN>
 <87r03tw121.fsf@HIDDEN>
 <CADwFkmn_G9DZjk_cjzPOtAr9wpQQ6tUVVjp3fBnetyT8cGahfA@HIDDEN>
 <jwvpljbguqm.fsf-monnier+emacs@HIDDEN>
 <CADwFkmnL1VaEh+hdMjY6fPXOQDhOw6b9QP0ySY9K9Q_C5YwdGA@HIDDEN>
 <864j07pqh7.fsf@HIDDEN>
 <CADwFkmneyHrb9GAK4MxeK1RPtSJa3P1W2wtNL=OuwJHJRudnow@HIDDEN>
 <861pvao89f.fsf@HIDDEN>
 <CADwFkmkuxfQtHcuzAdfi9hbvookoskT5wUa5JF+30aUBpz=1XA@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76313
Cc: 76313 <at> debbugs.gnu.org, monnier@HIDDEN, tsdh@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Stefan Kangas <stefankangas@HIDDEN>
> Date: Fri, 7 Mar 2025 20:23:09 +0000
> Cc: 76313 <at> debbugs.gnu.org, monnier@HIDDEN, tsdh@HIDDEN
> 
> Eli Zaretskii <eliz@HIDDEN> writes:
> 
> > but it doesn't solve the problem, either: the
> > other APIs still exist, so the potential confusion what to use when is
> > still there.  I very much doubt that you will be able to catch all the
> > subtleties in our documentation to avoid the confusion, but feel free
> > to try convincing me otherwise.
> 
> I don't fully understand what exactly you are asking for here.  Would
> you like me to propose a documentation patch on top of Stefan Monnier's
> patch?
> 
> I don't know if this is sufficient, but I suggest putting
> `replace-region` at the top of (info "(elisp) Replacing").  I don't
> think it will be very hard to explain the specialized nature of a
> renamed `replace-region-carefully`.  It's doable even if we don't rename
> it, I think, although the `replace-region-contents` name is a fair bit
> less self-explanatory.
> 
> I'm sure that we can come up with good documentation if we collaborate
> to make it so; we usually do.

I'm saying that the documentation aspect of this is not the real
problem.  Once we agree on the code and API changes, updating the
documentation is a no-brainer, and I don't expect it to trigger an
argument.

The problem here is how to provide the functionality without
complicating Emacs with yet another API, where we already have two.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 7 Mar 2025 20:23:20 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Mar 07 15:23:19 2025
Received: from localhost ([127.0.0.1]:50701 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tqeE3-0003rf-IS
	for submit <at> debbugs.gnu.org; Fri, 07 Mar 2025 15:23:19 -0500
Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]:57814)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <stefankangas@HIDDEN>)
 id 1tqeE0-0003rM-Ol
 for 76313 <at> debbugs.gnu.org; Fri, 07 Mar 2025 15:23:17 -0500
Received: by mail-ed1-x52c.google.com with SMTP id
 4fb4d7f45d1cf-5e5e22e6ed2so2197344a12.3
 for <76313 <at> debbugs.gnu.org>; Fri, 07 Mar 2025 12:23:16 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1741378990; x=1741983790; darn=debbugs.gnu.org;
 h=cc:to:subject:message-id:date:mime-version:references:in-reply-to
 :from:from:to:cc:subject:date:message-id:reply-to;
 bh=Q6O9+DVpS0XIfhvlpcBaKV8BEXL7lEB9WrF1/okRfHw=;
 b=iZca+jpwgP0eVk13nY5dMoa5/I9DWT0/7ULO2jyyU6HjlowAa0vY+QNRTQ7R9+IYlR
 a9fuRInoycJ9gPEA4lKswVWqiqHlc8pQs8H311o8DbA982RiH5GKtDv5SXIlYiID6bcC
 kVvqAHctJdpo3xfsPypuOfPI/S61FybHQ0RELGEiAkVyiVdMccWtkwqw7PGj2shQkbqY
 6cPFPwnkLwTXzSpw9C8zPzVdD4VEdiCf24nNchWKCOcVLCb3RxPzH97fQJrWgmRC3EKS
 /+wvjViKVPB1uqJO9OcA9BGb8fbUAS+9ktnwBFTgGGQE+RvHweyxVA4P9q+u6Gjl9OYO
 BUiA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1741378990; x=1741983790;
 h=cc:to:subject:message-id:date:mime-version:references:in-reply-to
 :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=Q6O9+DVpS0XIfhvlpcBaKV8BEXL7lEB9WrF1/okRfHw=;
 b=aj/vyoS/Is2Ug1IpXEg0sW8bYzNSiImOQFj5pMqVAvcj2VVjJZKZrWNFS5bchsU3bX
 tj6dX+Ev8a+Y3dV7bgw3kVb441G23vNI7/VS+RIh5ITCWhzzMDBUWp6H8kYEvp+UtJIE
 GkinYxpTcz+lhsAJq7Ks+s/CvZkP3hQtpCHcoP5fNPYxggYcgb9x0FC+VeKosMlY9v/J
 I7ULnpMSYbU7qoohLmbUpEnMXExjeR1Isv8YdpnoC1NGcvvnAjfosJimsz47ogQdQpiq
 4Zjd7suERjyBwy4JBgDOu0cHzXvygiF0KeF6+U35jSO8dskzO3aB/cYRsRkwdEtzTb+X
 mSdg==
X-Gm-Message-State: AOJu0YzIQLEhiZ5DLN69iysu9A8S82RGrQZRoS7zrqKD0agtHh9j6eIs
 cHg7aWbHiNrL9KYh8rGmJc7TsGOqEhHQM0Ui8/Q1HgKaCTJQujkuDkwD5CPLoKRcSx94ZZdoIO2
 4Oq5GEjRohzrhfK6bvBzShyqVUhHyvKsw
X-Gm-Gg: ASbGncsg4+nxja3ZfoTbAzbdRWI5FgFRA5zAX/Gttv//O6apjl8DlUfrLpYjurd5CZI
 rGFIm9qZ1c3VyY8ao3n6f8AcnLovt6yIhXrJn95VDBDMA8pS28YKpAdWZN7u+KEMIhBbN/znf8g
 Tc9p7HrppU/ybyqZ0j9gxWtAlQ5g==
X-Google-Smtp-Source: AGHT+IGM8dLdb0TNfWLE1XH2vbbeI4j56qSvoHoIZcYSInVRArQeARMEXlBmJn8wkUi3ABpoHgWeg1RtTQ/SOc52Ucw=
X-Received: by 2002:a05:6402:26cd:b0:5e5:b388:29f9 with SMTP id
 4fb4d7f45d1cf-5e5e22bf9e3mr4745462a12.5.1741378990431; Fri, 07 Mar 2025
 12:23:10 -0800 (PST)
Received: from 753933720722 named unknown by gmailapi.google.com with
 HTTPREST; Fri, 7 Mar 2025 20:23:09 +0000
From: Stefan Kangas <stefankangas@HIDDEN>
In-Reply-To: <861pvao89f.fsf@HIDDEN>
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86h64sbw57.fsf@HIDDEN>
 <jwvzfik398m.fsf-monnier+emacs@HIDDEN> <865xl8blam.fsf@HIDDEN>
 <jwvy0y49w9z.fsf-monnier+emacs@HIDDEN> <86ldu3a18y.fsf@HIDDEN>
 <jwvpljf1jh5.fsf-monnier+emacs@HIDDEN> <86msej8du2.fsf@HIDDEN>
 <jwvtt8ryyzl.fsf-monnier+emacs@HIDDEN> <86a5aj82zq.fsf@HIDDEN>
 <jwvtt8rxbnr.fsf-monnier+emacs@HIDDEN> <86h64q6t87.fsf@HIDDEN>
 <jwveczuugkw.fsf-monnier+emacs@HIDDEN>
 <CADwFkmm_wYVQRMk83EJww9mTbboCcyTTc-bVVbog9SNeN0d05A@HIDDEN>
 <87r03tw121.fsf@HIDDEN>
 <CADwFkmn_G9DZjk_cjzPOtAr9wpQQ6tUVVjp3fBnetyT8cGahfA@HIDDEN>
 <jwvpljbguqm.fsf-monnier+emacs@HIDDEN>
 <CADwFkmnL1VaEh+hdMjY6fPXOQDhOw6b9QP0ySY9K9Q_C5YwdGA@HIDDEN>
 <864j07pqh7.fsf@HIDDEN>
 <CADwFkmneyHrb9GAK4MxeK1RPtSJa3P1W2wtNL=OuwJHJRudnow@HIDDEN>
 <861pvao89f.fsf@HIDDEN>
MIME-Version: 1.0
Date: Fri, 7 Mar 2025 20:23:09 +0000
X-Gm-Features: AQ5f1JohA7VYJZmGBhlGMBsgBkEGaX0O6IKYFX2Qpw7T352Plp_g6n4LslgT3_8
Message-ID: <CADwFkmkuxfQtHcuzAdfi9hbvookoskT5wUa5JF+30aUBpz=1XA@HIDDEN>
Subject: Re: bug#76313: New function `replace-region`
To: Eli Zaretskii <eliz@HIDDEN>
Content-Type: text/plain; charset="UTF-8"
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76313
Cc: 76313 <at> debbugs.gnu.org, monnier@HIDDEN, tsdh@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Eli Zaretskii <eliz@HIDDEN> writes:

>> To make things even clearer, we could consider renaming
>> `replace-region-contents` to `carefully-replace-region`, or something
>> along those lines.  Its docstring and manual entry should emphasize it's
>> specialized nature.  Then, we have only one API that we really recommend
>> for this, plus the specialized function for the rare cases when you
>> really need it.
>
> I'm not opposed to renaming too much (although it does have its
> non-negligible price),

Fully agreed.  It's more painful to rename things that are used often,
of course.

> but it doesn't solve the problem, either: the
> other APIs still exist, so the potential confusion what to use when is
> still there.  I very much doubt that you will be able to catch all the
> subtleties in our documentation to avoid the confusion, but feel free
> to try convincing me otherwise.

I don't fully understand what exactly you are asking for here.  Would
you like me to propose a documentation patch on top of Stefan Monnier's
patch?

I don't know if this is sufficient, but I suggest putting
`replace-region` at the top of (info "(elisp) Replacing").  I don't
think it will be very hard to explain the specialized nature of a
renamed `replace-region-carefully`.  It's doable even if we don't rename
it, I think, although the `replace-region-contents` name is a fair bit
less self-explanatory.

I'm sure that we can come up with good documentation if we collaborate
to make it so; we usually do.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 6 Mar 2025 08:48:09 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Mar 06 03:48:09 2025
Received: from localhost ([127.0.0.1]:41387 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tq6tl-00025g-6w
	for submit <at> debbugs.gnu.org; Thu, 06 Mar 2025 03:48:09 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:41070)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tq6th-000257-4V
 for 76313 <at> debbugs.gnu.org; Thu, 06 Mar 2025 03:48:06 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1tq6ta-0003Rf-HE; Thu, 06 Mar 2025 03:47:58 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=R7TXgPzWqnV03zqVvrrxQg7rUU+ztXgKw/Ib5vkE/K0=; b=Uh2wsCb64BHi
 FBypmuoJYPRIFMn4NIxUVS+p/osRewSjE1xAZbE9DBLdLJLBv9t1RPMhO6L64Fb8wMmamZmrjaSpS
 MIAC2CKtSz9oVsPu6gnjIypgC9xW4GMdwS8/YFqRFwtKwXj5AKZq+Sqga9dX0jJuMcoBLFAdxmPZ3
 JhH3ll4c09K5nqYrglWe0TRV4xAq4aiKuty+VoxUYcSRTrn271q5F4UMO0WeefgAAZG8I6DK2pANY
 qx3wB+WIglqG2rzijc+RBzEmImxkeSlMP6MVAQvqldwzaM6ZQOOiJRkc3hhToOPYK27Q9xfl/5SSf
 DicERVM9DNZH2NPrF+Y4fA==;
Date: Thu, 06 Mar 2025 10:47:40 +0200
Message-Id: <861pvao89f.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Stefan Kangas <stefankangas@HIDDEN>
In-Reply-To: <CADwFkmneyHrb9GAK4MxeK1RPtSJa3P1W2wtNL=OuwJHJRudnow@HIDDEN>
 (message from Stefan Kangas on Wed, 5 Mar 2025 11:28:42 -0800)
Subject: Re: bug#76313: New function `replace-region`
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86mselbsbi.fsf@HIDDEN>
 <jwv1pvx5mtw.fsf-monnier+emacs@HIDDEN> <86h64sbw57.fsf@HIDDEN>
 <jwvzfik398m.fsf-monnier+emacs@HIDDEN> <865xl8blam.fsf@HIDDEN>
 <jwvy0y49w9z.fsf-monnier+emacs@HIDDEN> <86ldu3a18y.fsf@HIDDEN>
 <jwvpljf1jh5.fsf-monnier+emacs@HIDDEN> <86msej8du2.fsf@HIDDEN>
 <jwvtt8ryyzl.fsf-monnier+emacs@HIDDEN> <86a5aj82zq.fsf@HIDDEN>
 <jwvtt8rxbnr.fsf-monnier+emacs@HIDDEN> <86h64q6t87.fsf@HIDDEN>
 <jwveczuugkw.fsf-monnier+emacs@HIDDEN>
 <CADwFkmm_wYVQRMk83EJww9mTbboCcyTTc-bVVbog9SNeN0d05A@HIDDEN>
 <87r03tw121.fsf@HIDDEN>
 <CADwFkmn_G9DZjk_cjzPOtAr9wpQQ6tUVVjp3fBnetyT8cGahfA@HIDDEN>
 <jwvpljbguqm.fsf-monnier+emacs@HIDDEN>
 <CADwFkmnL1VaEh+hdMjY6fPXOQDhOw6b9QP0ySY9K9Q_C5YwdGA@HIDDEN>
 <864j07pqh7.fsf@HIDDEN>
 <CADwFkmneyHrb9GAK4MxeK1RPtSJa3P1W2wtNL=OuwJHJRudnow@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76313
Cc: 76313 <at> debbugs.gnu.org, monnier@HIDDEN, tsdh@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Stefan Kangas <stefankangas@HIDDEN>
> Date: Wed, 5 Mar 2025 11:28:42 -0800
> Cc: monnier@HIDDEN, 76313 <at> debbugs.gnu.org, tsdh@HIDDEN
> 
> Eli Zaretskii <eliz@HIDDEN> writes:
> 
> >> FWIW, I think that I'd personally rather see another function than
> >> complicating the `replace-region` interface just for this.
> >
> > And I'm of the directly opposite opinion.  I think having 2 APIs for
> > this is too much; adding a 3rd is overboard.
> >
> > I proposed some ways to avoid adding yet another API.  Yes, they are
> > less than ideal, but then we don't develop Emacs from scratch here, so
> > compromises are unavoidable.  (And it bothers me that two of the most
> > prolific Emacs contributors don't see t5he terrible downsides of
> > exponential explosion in the number of Emacs functions and variables.)
> 
> My proposal is to obsolete `replace-buffer-contents`, as per Stefan
> Monnier's suggestion.[1]

Why would we obsolete a function that is used in half a dozen places
in our own sources?

And anyway, obsoleting a function doesn't remove it from Emacs until
many years in the future.

> Adding `replace-region` would then bring us up to 2 APIs.  This is the
> same as what we have now.

This trick doesn't solve my problem, sorry.

> To make things even clearer, we could consider renaming
> `replace-region-contents` to `carefully-replace-region`, or something
> along those lines.  Its docstring and manual entry should emphasize it's
> specialized nature.  Then, we have only one API that we really recommend
> for this, plus the specialized function for the rare cases when you
> really need it.

I'm not opposed to renaming too much (although it does have its
non-negligible price), but it doesn't solve the problem, either: the
other APIs still exist, so the potential confusion what to use when is
still there.  I very much doubt that you will be able to catch all the
subtleties in our documentation to avoid the confusion, but feel free
to try convincing me otherwise.

> (BTW, since `replace-region-contents` is currently unused in our tree,
> maybe we don't even need it.  OTOH, if we rename it, it shouldn't hurt
> to leave it alone, in case it will be needed again in the future.)

OTOH, my suggestion to extend replace-buffer-contents instead was
rejected by Stefan Monnier more strongly than the suggestion to extend
replace-region-contents.  So it sounds like Stefan favors
replace-region-contents.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.
Did not alter fixed versions and reopened. Request was from Debbugs Internal Request <help-debbugs@HIDDEN> to internal_control <at> debbugs.gnu.org. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 5 Mar 2025 19:28:53 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Mar 05 14:28:53 2025
Received: from localhost ([127.0.0.1]:39917 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tpuQG-0001Me-RO
	for submit <at> debbugs.gnu.org; Wed, 05 Mar 2025 14:28:53 -0500
Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]:53575)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <stefankangas@HIDDEN>)
 id 1tpuQD-0001MN-Ky
 for 76313 <at> debbugs.gnu.org; Wed, 05 Mar 2025 14:28:50 -0500
Received: by mail-ej1-x62f.google.com with SMTP id
 a640c23a62f3a-abf3d64849dso718483666b.3
 for <76313 <at> debbugs.gnu.org>; Wed, 05 Mar 2025 11:28:49 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1741202923; x=1741807723; darn=debbugs.gnu.org;
 h=cc:to:subject:message-id:date:mime-version:references:in-reply-to
 :from:from:to:cc:subject:date:message-id:reply-to;
 bh=3g04mcutJU9DFSzmAwRXFwzhwJgIrw0hpEIXLfmz8tg=;
 b=PPEyJWZcbztfuFmCfq2oAlt15rJlri0xLSKNXiSYqZwyyn+AGB41s4FqdRK0sGXJU8
 vgPnex2Ss+t5ZykxA3CcPleeHPuLZEv+MGfEF/DiLCpHYrFmF4HLhbyZGFcjMeYDwUf+
 hiQe+QPeOIDEuam3IHDkKhynkmDvY+/Q70Wp79INzMtt7TmLBkNBh4fAatfGDvKtFLpT
 c8o7ORV1fVuVe/UkxDlBZdOfanzd50YUJ9tuQ8W5LI7K+XCrtYx201oYNyGsyPtny8Ce
 hFgLJEihcE66SKJHe3Ve8hVOJc67rLd798nLk9jSRUh3Xn5YABjg5kXgeIlvXv/yc0kp
 HIBQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1741202923; x=1741807723;
 h=cc:to:subject:message-id:date:mime-version:references:in-reply-to
 :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=3g04mcutJU9DFSzmAwRXFwzhwJgIrw0hpEIXLfmz8tg=;
 b=HA6kPoMIQG+i/o7/wrBzHL8xwYqkAHp/V7OmPgGYkrzIfY7SUHEQMol9EKskNRXgzK
 c48wN7e3EGxh7Pp4O/7rFD+6D798f8yT8jgTs+g0V6bXdF6SrGFYx+9EnIHQ1q/2O510
 EYCKz6DM/iuU9fCYkXMXuqqzZ26GVlOTrGoCvyFEv2oxmBP+PBhTlXl24shw8VZwJAXm
 Yx14qWI/5YNk3yaMqIH5AW4bogsLYCKDCZly5S0f0lGgMa66kHwpS5BFgiYRnRMYoFe4
 WmyrTGMAWKsi+UmX8rmqUtRFSIcTyIgOeifH4XYbyeN7Bhhr6RzjyFodD81hvLwdQI42
 9/mg==
X-Forwarded-Encrypted: i=1;
 AJvYcCU2CcJ5Yt10jj9hiiKFgr6gByckMR3LeodCR4mpG5NvpxW3JHKTjyzhATfDmjAd/ky4E0pRfQ==@debbugs.gnu.org
X-Gm-Message-State: AOJu0Yzn1Oha5bqg30wfJDiXR3ootkq+D2os8nwEIDOONBBpn+yR/hVD
 xkWQ0FiKmkfmLrhiPzFm4lMvJa+lMuGKvf/n/3xtehu+zcVUkDY2GUa5/HXfUtrZT/Y6mx7NedC
 4pBF2MMceYeluX/jdb7RsQpHTg0U=
X-Gm-Gg: ASbGncu6hGlbmUsNVHtcxojIYBR222AmIRgvc1+4fqLc5ytBwgnDMkyEKRpCHRSJiiX
 kv7EEOF9jk5wiSfjkNWFh+OLV/NseAfwqBpGtSM08VOqMmxWyzxtFWBDh340q9fT6cqRx9St1OX
 zpBeMrIvcEtOKB0v+XyaqR8rNAuA==
X-Google-Smtp-Source: AGHT+IGXyWnZ20//sql41X2s6tzagJiAeP1Hn4hJqFYmJ3LkNEKnJieCCdn5RgMD1kxa0nrak4l1/B32VyVP1uo34kc=
X-Received: by 2002:a05:6402:4614:b0:5e5:ba77:6f24 with SMTP id
 4fb4d7f45d1cf-5e5ba77738amr4420658a12.16.1741202923307; Wed, 05 Mar 2025
 11:28:43 -0800 (PST)
Received: from 753933720722 named unknown by gmailapi.google.com with
 HTTPREST; Wed, 5 Mar 2025 11:28:42 -0800
From: Stefan Kangas <stefankangas@HIDDEN>
In-Reply-To: <864j07pqh7.fsf@HIDDEN>
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86mselbsbi.fsf@HIDDEN>
 <jwv1pvx5mtw.fsf-monnier+emacs@HIDDEN> <86h64sbw57.fsf@HIDDEN>
 <jwvzfik398m.fsf-monnier+emacs@HIDDEN> <865xl8blam.fsf@HIDDEN>
 <jwvy0y49w9z.fsf-monnier+emacs@HIDDEN> <86ldu3a18y.fsf@HIDDEN>
 <jwvpljf1jh5.fsf-monnier+emacs@HIDDEN> <86msej8du2.fsf@HIDDEN>
 <jwvtt8ryyzl.fsf-monnier+emacs@HIDDEN> <86a5aj82zq.fsf@HIDDEN>
 <jwvtt8rxbnr.fsf-monnier+emacs@HIDDEN> <86h64q6t87.fsf@HIDDEN>
 <jwveczuugkw.fsf-monnier+emacs@HIDDEN>
 <CADwFkmm_wYVQRMk83EJww9mTbboCcyTTc-bVVbog9SNeN0d05A@HIDDEN>
 <87r03tw121.fsf@HIDDEN>
 <CADwFkmn_G9DZjk_cjzPOtAr9wpQQ6tUVVjp3fBnetyT8cGahfA@HIDDEN>
 <jwvpljbguqm.fsf-monnier+emacs@HIDDEN>
 <CADwFkmnL1VaEh+hdMjY6fPXOQDhOw6b9QP0ySY9K9Q_C5YwdGA@HIDDEN>
 <864j07pqh7.fsf@HIDDEN>
MIME-Version: 1.0
Date: Wed, 5 Mar 2025 11:28:42 -0800
X-Gm-Features: AQ5f1JpDTrq_wp0ex6SKYvY6kRHd1SHMtMdQINTcMAqEPENnTOyGDm6Zy0TFISU
Message-ID: <CADwFkmneyHrb9GAK4MxeK1RPtSJa3P1W2wtNL=OuwJHJRudnow@HIDDEN>
Subject: Re: bug#76313: New function `replace-region`
To: Eli Zaretskii <eliz@HIDDEN>
Content-Type: text/plain; charset="UTF-8"
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76313
Cc: 76313 <at> debbugs.gnu.org, monnier@HIDDEN, tsdh@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Eli Zaretskii <eliz@HIDDEN> writes:

>> From: Stefan Kangas <stefankangas@HIDDEN>
>> Date: Tue, 4 Mar 2025 19:58:05 -0800
>> Cc: Philipp Stephani <phst@HIDDEN>, 76313 <at> debbugs.gnu.org, Eli Zaretskii <eliz@HIDDEN>,
>> 	Tassilo Horn <tsdh@HIDDEN>
>>
>> FWIW, I think that I'd personally rather see another function than
>> complicating the `replace-region` interface just for this.
>
> And I'm of the directly opposite opinion.  I think having 2 APIs for
> this is too much; adding a 3rd is overboard.
>
> I proposed some ways to avoid adding yet another API.  Yes, they are
> less than ideal, but then we don't develop Emacs from scratch here, so
> compromises are unavoidable.  (And it bothers me that two of the most
> prolific Emacs contributors don't see t5he terrible downsides of
> exponential explosion in the number of Emacs functions and variables.)

My proposal is to obsolete `replace-buffer-contents`, as per Stefan
Monnier's suggestion.[1]  This is orthogonal to adding `replace-region`,
but means that we only have one API.

Adding `replace-region` would then bring us up to 2 APIs.  This is the
same as what we have now.

To make things even clearer, we could consider renaming
`replace-region-contents` to `carefully-replace-region`, or something
along those lines.  Its docstring and manual entry should emphasize it's
specialized nature.  Then, we have only one API that we really recommend
for this, plus the specialized function for the rare cases when you
really need it.

(BTW, since `replace-region-contents` is currently unused in our tree,
maybe we don't even need it.  OTOH, if we rename it, it shouldn't hurt
to leave it alone, in case it will be needed again in the future.)

Footnotes:
[1]  https://debbugs.gnu.org/cgi/bugreport.cgi?bug=76313#76




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 5 Mar 2025 15:17:10 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Mar 05 10:17:10 2025
Received: from localhost ([127.0.0.1]:39093 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tpqUf-0005FG-Nt
	for submit <at> debbugs.gnu.org; Wed, 05 Mar 2025 10:17:10 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:59528)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tpqUc-0005ET-3E
 for 76313 <at> debbugs.gnu.org; Wed, 05 Mar 2025 10:17:06 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1tpqUU-0006yY-PZ; Wed, 05 Mar 2025 10:16:58 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=zJ4dIyPWEhSbJ3n8dq71acy7TwOsX/qiGNcuYS0ACzU=; b=MvPexMGCdhk1
 +fp7fxFaVc6J2ErONPC2ldbS8xmMhCFpRTldOgcfm1HzYgRrnoj6ysAoU4HJX3qUneYoUTa53sofH
 p8yXSW+1MTiRiBEnTtx0h0yCiLkdieQP0w+OxkHQGW8EY3qCR0ATevarXdaKM7EwVFGzRHX2U3blV
 MwssA6/OpnTx3gueoVNZgjZ/WNlq0L1EPfVLJm5rnFDapL9s2T6k/+xk0/wC2js7T7ElE0wCTLNNg
 ibWO1XLGe8L6wgj2DpA5e3rhKitPr7nv0JRQKqbnb8soNYIMYMxKlsS7Lwe5+2Cu09PNSMXXUhMgd
 5EKr3YfCbJ2sXTFq6w5jkA==;
Date: Wed, 05 Mar 2025 17:16:55 +0200
Message-Id: <86o6yfo6c8.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
In-Reply-To: <jwvv7snzhms.fsf-monnier+emacs@HIDDEN> (message from Stefan
 Monnier on Wed, 05 Mar 2025 09:21:51 -0500)
Subject: Re: bug#76313: New function `replace-region`
References: <jwv4j0u50tn.fsf-monnier+@gnu.org>
 <jwvr03xzuvz.fsf-monnier+emacs@HIDDEN> <86mselbsbi.fsf@HIDDEN>
 <jwv1pvx5mtw.fsf-monnier+emacs@HIDDEN> <86h64sbw57.fsf@HIDDEN>
 <jwvzfik398m.fsf-monnier+emacs@HIDDEN> <865xl8blam.fsf@HIDDEN>
 <jwvy0y49w9z.fsf-monnier+emacs@HIDDEN> <86ldu3a18y.fsf@HIDDEN>
 <jwvpljf1jh5.fsf-monnier+emacs@HIDDEN> <86msej8du2.fsf@HIDDEN>
 <jwvtt8ryyzl.fsf-monnier+emacs@HIDDEN> <86a5aj82zq.fsf@HIDDEN>
 <jwvtt8rxbnr.fsf-monnier+emacs@HIDDEN> <86h64q6t87.fsf@HIDDEN>
 <jwveczuugkw.fsf-monnier+emacs@HIDDEN>
 <CADwFkmm_wYVQRMk83EJww9mTbboCcyTTc-bVVbog9SNeN0d05A@HIDDEN>
 <87r03tw121.fsf@HIDDEN>
 <CADwFkmn_G9DZjk_cjzPOtAr9wpQQ6tUVVjp3fBnetyT8cGahfA@HIDDEN>
 <jwvpljbguqm.fsf-monnier+emacs@HIDDEN>
 <CADwFkmnL1VaEh+hdMjY6fPXOQDhOw6b9QP0ySY9K9Q_C5YwdGA@HIDDEN>
 <jwvv7snzhms.fsf-monnier+emacs@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76313
Cc: 76313 <at> debbugs.gnu.org, stefankangas@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Stefan Monnier <monnier@HIDDEN>
> Cc: Philipp Stephani <phst@HIDDEN>,  76313 <at> debbugs.gnu.org,  Eli
>  Zaretskii <eliz@HIDDEN>,  Tassilo Horn <tsdh@HIDDEN>
> Date: Wed, 05 Mar 2025 09:21:51 -0500
> 
> >> I think it's hard to fix the problems of `replace-buffer-contents` in
> >> a backward incompatible way, so I suggest we "standardize" on
> >> `replace-region-contents` instead where we replace its REPLACE-FN
> >> argument with a REPLACE argument which can be either a string, or a
> >> buffer, or a function (this latter one could be deprecated, but we'd
> >> keep it for backward compatibility).
> >> This is backward-compatible, so we would obsolete only `replace-buffer-contents`.
> > This is orthogonal to `replace-region`, is it not?
> 
> Mostly.  And that's the point: to try and allow forward progress while
> we try and resolve the remaining disagreement.
> 
> > It sounds to me like a good change, in any case.
> 
> Eli?

I don't think I understand what is the question I'm being asked here.

If the suggestion is to extend replace-region-contents, then you will
recall that this was your first proposal, with which I agreed in
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=76313#14, and again in
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=76313#29, but you then
said in https://debbugs.gnu.org/cgi/bugreport.cgi?bug=76313#32 you
didn't like that?




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 5 Mar 2025 14:22:03 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Mar 05 09:22:03 2025
Received: from localhost ([127.0.0.1]:36314 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tppdK-0001p8-S7
	for submit <at> debbugs.gnu.org; Wed, 05 Mar 2025 09:22:03 -0500
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:2906)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1tppdI-0001oY-0m
 for 76313 <at> debbugs.gnu.org; Wed, 05 Mar 2025 09:22:00 -0500
Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id DE79F100040;
 Wed,  5 Mar 2025 09:21:53 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1741184513;
 bh=FgCTToGDrYtfX128ghoEBgcsv/UDO0qoAQI6x2tb0Vg=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=nzTUYYv7emd7CQLcPvRChde4zER+GHxgmQmwhQDgDY1X9NHr2dlSL1gYIO3403efk
 wZml9y7jnpSgwPDSEBvGHVd/3jAGRHJaHXYNx7MHoU/iOHHfWaSHGYr1qTIYx4H9R+
 SiM3vN/cQwPBys2js1q6wS9d+eaVMv919LsfFNKoZ3ox1pa5vUw4Itn3xZlcRoNANm
 iYewqYS54ytzXHR0gsSEplWJgeSzqclYV6KpMfytZNFfwOZc+G4lmjvxjGwjWcaEc8
 Dvo3wJLMj/yrIYgN3SH2ZSkIEhiaF883Rs8mf8DCadvEjWXrcZml9mVIvgTToVS6sh
 YtgPYvIFooHJQ==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 42B8B100034;
 Wed,  5 Mar 2025 09:21:53 -0500 (EST)
Received: from alfajor (unknown [104.247.242.5])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 082261209D0;
 Wed,  5 Mar 2025 09:21:53 -0500 (EST)
From: Stefan Monnier <monnier@HIDDEN>
To: Stefan Kangas <stefankangas@HIDDEN>
Subject: Re: bug#76313: New function `replace-region`
In-Reply-To: <CADwFkmnL1VaEh+hdMjY6fPXOQDhOw6b9QP0ySY9K9Q_C5YwdGA@HIDDEN>
Message-ID: <jwvv7snzhms.fsf-monnier+emacs@HIDDEN>
References: <jwv4j0u50tn.fsf-monnier+@gnu.org>
 <jwvr03xzuvz.fsf-monnier+emacs@HIDDEN> <86mselbsbi.fsf@HIDDEN>
 <jwv1pvx5mtw.fsf-monnier+emacs@HIDDEN> <86h64sbw57.fsf@HIDDEN>
 <jwvzfik398m.fsf-monnier+emacs@HIDDEN> <865xl8blam.fsf@HIDDEN>
 <jwvy0y49w9z.fsf-monnier+emacs@HIDDEN> <86ldu3a18y.fsf@HIDDEN>
 <jwvpljf1jh5.fsf-monnier+emacs@HIDDEN> <86msej8du2.fsf@HIDDEN>
 <jwvtt8ryyzl.fsf-monnier+emacs@HIDDEN> <86a5aj82zq.fsf@HIDDEN>
 <jwvtt8rxbnr.fsf-monnier+emacs@HIDDEN> <86h64q6t87.fsf@HIDDEN>
 <jwveczuugkw.fsf-monnier+emacs@HIDDEN>
 <CADwFkmm_wYVQRMk83EJww9mTbboCcyTTc-bVVbog9SNeN0d05A@HIDDEN>
 <87r03tw121.fsf@HIDDEN>
 <CADwFkmn_G9DZjk_cjzPOtAr9wpQQ6tUVVjp3fBnetyT8cGahfA@HIDDEN>
 <jwvpljbguqm.fsf-monnier+emacs@HIDDEN>
 <CADwFkmnL1VaEh+hdMjY6fPXOQDhOw6b9QP0ySY9K9Q_C5YwdGA@HIDDEN>
Date: Wed, 05 Mar 2025 09:21:51 -0500
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.279 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76313
Cc: Philipp Stephani <phst@HIDDEN>, 76313 <at> debbugs.gnu.org,
 Eli Zaretskii <eliz@HIDDEN>, Tassilo Horn <tsdh@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

>> I think it's hard to fix the problems of `replace-buffer-contents` in
>> a backward incompatible way, so I suggest we "standardize" on
>> `replace-region-contents` instead where we replace its REPLACE-FN
>> argument with a REPLACE argument which can be either a string, or a
>> buffer, or a function (this latter one could be deprecated, but we'd
>> keep it for backward compatibility).
>> This is backward-compatible, so we would obsolete only `replace-buffer-contents`.
> This is orthogonal to `replace-region`, is it not?

Mostly.  And that's the point: to try and allow forward progress while
we try and resolve the remaining disagreement.

> It sounds to me like a good change, in any case.

Eli?


        Stefan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 5 Mar 2025 13:16:47 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Mar 05 08:16:47 2025
Received: from localhost ([127.0.0.1]:36095 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tpocB-00014J-EI
	for submit <at> debbugs.gnu.org; Wed, 05 Mar 2025 08:16:47 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:50802)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tpoc9-000149-Ky
 for 76313 <at> debbugs.gnu.org; Wed, 05 Mar 2025 08:16:46 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1tpoc3-0001YD-Ak; Wed, 05 Mar 2025 08:16:39 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=uA0GjB4JEaC8/gXVVMHb9e0nypNPnOAxoLPTE45k4lc=; b=gAim9cbcidKZ
 VQcimLYXIo5Tt4Xlsb9Xypqn2KxDFRXCO6BvkKR0nFg06nOB+SuCqilqrOXbXcZkReebKznekYgef
 g+gUPDw6VgOtGz4hJ0I7dcfzvRvhqCN7TpyzVyZlbQ7r/PvkkqUVM33P2oIPGCjOiVglz0kTTMRE8
 066yC3pxVWBJXtRkWXRlOn4yiQ3jjjXz9Ppqo1etOxgMAbghW2SnanIHnC3jVixVlI5yFVOVPolTw
 OXk6EaDmqJaxVw9pmBbPXE/pwJCgWWSKRQZeCcNbSHkes6KhlJMEYCYtKeBI1P/wV44g5hUJHnr5f
 hn7ZDhKmsF8tb3HbPovhVQ==;
Date: Wed, 05 Mar 2025 15:16:36 +0200
Message-Id: <864j07pqh7.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Stefan Kangas <stefankangas@HIDDEN>
In-Reply-To: <CADwFkmnL1VaEh+hdMjY6fPXOQDhOw6b9QP0ySY9K9Q_C5YwdGA@HIDDEN>
 (message from Stefan Kangas on Tue, 4 Mar 2025 19:58:05 -0800)
Subject: Re: bug#76313: New function `replace-region`
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86seoecung.fsf@HIDDEN>
 <jwvr03xzuvz.fsf-monnier+emacs@HIDDEN> <86mselbsbi.fsf@HIDDEN>
 <jwv1pvx5mtw.fsf-monnier+emacs@HIDDEN> <86h64sbw57.fsf@HIDDEN>
 <jwvzfik398m.fsf-monnier+emacs@HIDDEN> <865xl8blam.fsf@HIDDEN>
 <jwvy0y49w9z.fsf-monnier+emacs@HIDDEN> <86ldu3a18y.fsf@HIDDEN>
 <jwvpljf1jh5.fsf-monnier+emacs@HIDDEN> <86msej8du2.fsf@HIDDEN>
 <jwvtt8ryyzl.fsf-monnier+emacs@HIDDEN> <86a5aj82zq.fsf@HIDDEN>
 <jwvtt8rxbnr.fsf-monnier+emacs@HIDDEN> <86h64q6t87.fsf@HIDDEN>
 <jwveczuugkw.fsf-monnier+emacs@HIDDEN>
 <CADwFkmm_wYVQRMk83EJww9mTbboCcyTTc-bVVbog9SNeN0d05A@HIDDEN>
 <87r03tw121.fsf@HIDDEN>
 <CADwFkmn_G9DZjk_cjzPOtAr9wpQQ6tUVVjp3fBnetyT8cGahfA@HIDDEN>
 <jwvpljbguqm.fsf-monnier+emacs@HIDDEN>
 <CADwFkmnL1VaEh+hdMjY6fPXOQDhOw6b9QP0ySY9K9Q_C5YwdGA@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76313
Cc: phst@HIDDEN, 76313 <at> debbugs.gnu.org, monnier@HIDDEN,
 tsdh@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Stefan Kangas <stefankangas@HIDDEN>
> Date: Tue, 4 Mar 2025 19:58:05 -0800
> Cc: Philipp Stephani <phst@HIDDEN>, 76313 <at> debbugs.gnu.org, Eli Zaretskii <eliz@HIDDEN>, 
> 	Tassilo Horn <tsdh@HIDDEN>
> 
> FWIW, I think that I'd personally rather see another function than
> complicating the `replace-region` interface just for this.

And I'm of the directly opposite opinion.  I think having 2 APIs for
this is too much; adding a 3rd is overboard.

I proposed some ways to avoid adding yet another API.  Yes, they are
less than ideal, but then we don't develop Emacs from scratch here, so
compromises are unavoidable.  (And it bothers me that two of the most
prolific Emacs contributors don't see t5he terrible downsides of
exponential explosion in the number of Emacs functions and variables.)




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 5 Mar 2025 03:58:16 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Mar 04 22:58:15 2025
Received: from localhost ([127.0.0.1]:33895 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tpftf-0004W9-EK
	for submit <at> debbugs.gnu.org; Tue, 04 Mar 2025 22:58:15 -0500
Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]:60429)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <stefankangas@HIDDEN>)
 id 1tpftd-0004Vp-DD
 for 76313 <at> debbugs.gnu.org; Tue, 04 Mar 2025 22:58:14 -0500
Received: by mail-ed1-x52f.google.com with SMTP id
 4fb4d7f45d1cf-5e0373c7f55so9776149a12.0
 for <76313 <at> debbugs.gnu.org>; Tue, 04 Mar 2025 19:58:13 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1741147087; x=1741751887; darn=debbugs.gnu.org;
 h=content-transfer-encoding:cc:to:subject:message-id:date
 :mime-version:references:in-reply-to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=FgdswbpZeRsgt3CckyQE7tYa1w0T6lOyUZsojDcWeMI=;
 b=PSnJoIFbR+f9WfCbU+y89pzLJd4+fJEv4hLJsJ/yMaAplK1cy0VzheFIl7Sth4dRHK
 uv3F8tGlkhRgAsSr8xWd3bIz15D/OQmkHNdLAttnePDX+WjyyYH2HuU4mk+ZVmSf+nMt
 EndlQmyydDtyMASLMeMq3t2OYmbI2oLD9/JLjhdRyqA5LJWR1Jt+hB9olqDWJSL5GfUX
 Gs9AQ/66fhAiX0SvoQ98/QCF4U5znQcQPxxk/S39zwAAdRefqkfceyIksAH1jqUEQPw/
 1DVEDKTVoKsYV/wt364GsCRBfX8iz50FfbG+L5U87AfVWUfKPbQofRIoXGwSTLBimXcF
 U6EQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1741147087; x=1741751887;
 h=content-transfer-encoding:cc:to:subject:message-id:date
 :mime-version:references:in-reply-to:from:x-gm-message-state:from:to
 :cc:subject:date:message-id:reply-to;
 bh=FgdswbpZeRsgt3CckyQE7tYa1w0T6lOyUZsojDcWeMI=;
 b=C6V6r3GB5zvCqrG2WfZag1QMw897eNyOsdzP4LqwQc+NN2u/OrMc8EvQ3wbdf8GPXb
 W2DGSvnDbCzTb5moup+oIPsy/GpXsgZl3LtKyt6Ycqn8Eeb3IiW0CMKAC+ilPSma1Bu+
 T7go2vv457peuBZ1+CDNpRzph3JfSLK/it15kYwb3+7uxVrda99FOBMD30MW0s1UADzP
 Ybu+PJ3rmXyG3QTYdMjeusWr6joDfhOh0lE3O+w2PG/dFkOquWUFeVAZWy44a1X8xlPX
 yvuWrisB4H1mDbJ5p60tGCGTNL9ahBnaFaljZJABN07IJATmRQ9Rw8Bg7FDOkEweaO97
 AXng==
X-Forwarded-Encrypted: i=1;
 AJvYcCX1KbNyjZHAzovJeETGw7AUJFtv7vfDTFH/KN9aZAIm73jlXAewz/RoFfvDHvvIBHQKmlxWTQ==@debbugs.gnu.org
X-Gm-Message-State: AOJu0Yx4kjhRmjYzfW2J/J/nfBmTb1OUDzM/6QbYqfDd+SknFT810Ee1
 8O5xk16UAzQBXKIMlt5PNsJj/ffcaxsfYcEn9FWGD3qB/xw/fu/L2F0GnhPONMnCrwTAmF8qJxL
 EFGDkkZ8PGhm1PAKJ/YZVzs8lNGQ=
X-Gm-Gg: ASbGncuDMgdN9dvZqOk/GNuQeWNbTbgmSQMFO6ZpVtHM7HF+kGx4Y5F3jw+uWMoNWOs
 fRmNsjDo99B9u2aGkMZMRi4tBb8YYsvl1YOC0PDCC03INNtD2qElpG6JTcvOlgClxASUo8MrWI/
 NBDVWx3YgIUXO+qBtkHMrN0L4t8S8=
X-Google-Smtp-Source: AGHT+IFZ6krGXzWINFaC2lh/pf1rK5vayJRgq5zV9eLj69Alk3zVswzx8S3M3ijTBNmaaeN0nhCJ8+eMnCQJS232a0k=
X-Received: by 2002:a05:6402:4316:b0:5e5:437c:1daf with SMTP id
 4fb4d7f45d1cf-5e59f3c85acmr1358329a12.16.1741147086918; Tue, 04 Mar 2025
 19:58:06 -0800 (PST)
Received: from 753933720722 named unknown by gmailapi.google.com with
 HTTPREST; Tue, 4 Mar 2025 19:58:05 -0800
From: Stefan Kangas <stefankangas@HIDDEN>
In-Reply-To: <jwvpljbguqm.fsf-monnier+emacs@HIDDEN>
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86seoecung.fsf@HIDDEN>
 <jwvr03xzuvz.fsf-monnier+emacs@HIDDEN> <86mselbsbi.fsf@HIDDEN>
 <jwv1pvx5mtw.fsf-monnier+emacs@HIDDEN> <86h64sbw57.fsf@HIDDEN>
 <jwvzfik398m.fsf-monnier+emacs@HIDDEN> <865xl8blam.fsf@HIDDEN>
 <jwvy0y49w9z.fsf-monnier+emacs@HIDDEN> <86ldu3a18y.fsf@HIDDEN>
 <jwvpljf1jh5.fsf-monnier+emacs@HIDDEN> <86msej8du2.fsf@HIDDEN>
 <jwvtt8ryyzl.fsf-monnier+emacs@HIDDEN> <86a5aj82zq.fsf@HIDDEN>
 <jwvtt8rxbnr.fsf-monnier+emacs@HIDDEN> <86h64q6t87.fsf@HIDDEN>
 <jwveczuugkw.fsf-monnier+emacs@HIDDEN>
 <CADwFkmm_wYVQRMk83EJww9mTbboCcyTTc-bVVbog9SNeN0d05A@HIDDEN>
 <87r03tw121.fsf@HIDDEN>
 <CADwFkmn_G9DZjk_cjzPOtAr9wpQQ6tUVVjp3fBnetyT8cGahfA@HIDDEN>
 <jwvpljbguqm.fsf-monnier+emacs@HIDDEN>
MIME-Version: 1.0
Date: Tue, 4 Mar 2025 19:58:05 -0800
X-Gm-Features: AQ5f1JowHCBD0TTFhmobIzClLrPKYFn1n3CcahrqbexIPerRuMn9hovB6V0m9KY
Message-ID: <CADwFkmnL1VaEh+hdMjY6fPXOQDhOw6b9QP0ySY9K9Q_C5YwdGA@HIDDEN>
Subject: Re: bug#76313: New function `replace-region`
To: Stefan Monnier <monnier@HIDDEN>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76313
Cc: Philipp Stephani <phst@HIDDEN>, 76313 <at> debbugs.gnu.org,
 Eli Zaretskii <eliz@HIDDEN>, Tassilo Horn <tsdh@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Stefan Monnier <monnier@HIDDEN> writes:

> I suggest we start by merging `replace-region-contents` and `replace-buff=
er-contents`.
> The downsides I see of each interface is:
>
> - `replace-region-contents` takes a REPLACE-FN whereas
>   it's often easier to compute the replacement beforehand.
> - `replace-buffer-contents` operates only on the "whole"
>   buffer, so requires the use of narrowing if we need something else.
> - `replace-buffer-contents` can't accept a string as the replacement
>   because it already takes a string to mean the name of a buffer.

I'll add that MAX-SECS and MAX-COSTS is a significant complication in
the interfaces of both functions.  I think this is because they were
neither designed as nor intended to be low-level operations.  This is
the main reason why I think `replace-region` is still needed, though I
also agree with the above points.

See also Bug#71370, where we are struggling to justify the obsoletion of
the generalized variable `buffer-substring`, because we do not have
anything to replace it with.  According to the statistics posted there
by Andrea, that is the most popular generalized variable by far, so
there are clearly more than a few users that want something like it.

> I think it's hard to fix the problems of `replace-buffer-contents` in
> a backward incompatible way, so I suggest we "standardize" on
> `replace-region-contents` instead where we replace its REPLACE-FN
> argument with a REPLACE argument which can be either a string, or a
> buffer, or a function (this latter one could be deprecated, but we'd
> keep it for backward compatibility).
>
> This is backward-compatible, so we would obsolete only `replace-buffer-co=
ntents`.

This is orthogonal to `replace-region`, is it not?  It sounds to me like
a good change, in any case.

> Compared to my notion of ideal this would still have three problems:
>
> - It's much slower than insert+delete-region, so it's not a replacement
>   for the function I proposed.  We could add a "fast" option to it, but
>   this fast option (which would presumably be the most common use case)
>   would require every caller to pass an extra argument, which
>   would be inconvenient (would encourage people to use the expensive
>   code without being aware of the risk).
> - It lacks an option to `insert-and-inherit` (needed by
>   `minibuffer--replace`).  We could add one more optional arg for it.
>   It would be kind of "far" (after MAX-SECS MAX-COSTS), so it's not
>   ideal, but it's not the end of the world.
> - It still uses this MAX-COSTS argument which noone seems to understand.
>
> BTW, the code of `replace-buffer-contents` does:
>
>        del_range (...);
>        Finsert_buffer_substring (...);
>
> This means that As it currently stands, when there is no similarity
> between the before and after contents, `replace-buffer-contents`
> preserves markers less carefully than the `replace-region` code
> I sent =F0=9F=99=81.
>
> The above would be better replaced by a call to a simple&fast
> `replace-region`, tho contrary to the one I sent, that one needs to take
> its replacement text from a region of a buffer rather than from
> a string.  I guess we could let the STRING (aka REPLACE) arg of
> `replace-region` be a triplet (BUFFER FROM TO), or we could add another
> function of the form
>
>     (replace-region-from-buffer BEG END
>                                 BUFFER BUFFER-BEG BUFFER-END
>                                 &optional INHERIT)
>
> or require the use of narrowing in the source buffer to implicitly pass
> the bounds.

FWIW, I think that I'd personally rather see another function than
complicating the `replace-region` interface just for this.  OTOH, if
it's needed only here perhaps we could just inline it.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 21 Feb 2025 16:31:21 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Feb 21 11:31:21 2025
Received: from localhost ([127.0.0.1]:33779 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tlVvs-0001A8-5I
	for submit <at> debbugs.gnu.org; Fri, 21 Feb 2025 11:31:21 -0500
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:17730)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1tlVvp-00018x-6B
 for 76313 <at> debbugs.gnu.org; Fri, 21 Feb 2025 11:31:17 -0500
Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 5354C4418E1;
 Fri, 21 Feb 2025 11:31:10 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1740155469;
 bh=aPCUhsqL+vdvYm0tu+hW1xjdWuLrN3/q2cq8sVcnSZQ=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=Da36n9ND+ygTo/OJ/Cb/fJb27yN5oWNE4iKuzwfgCtPzVLv/aMNCbihsatycPohcj
 67vcNpt3gs25zI/zVsR7nOIhRIhNNjNSugaYcpE5n1d/nbBjvjsCQYLDusIkuxE22N
 ul4UDsopqdvFvo7q9fx9KyTzlNuj6xBZvNRDHutO80nJIQQT/5olfXB3sJ28NTeWEg
 1T9rZJRv92+g9r4iZrKgyp/sy6V+dV9z9ebO0d70u5INZfFZG81R1tRXaGlTUM0RgS
 QYlGR2S1/2o5sX61ARtCHRxAdzALKYJ1N7RHaWelKFMXNFeWyWDUFQLW/k5CEIiqUe
 IdjlDEdzhDSKQ==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id EF8CA44179C;
 Fri, 21 Feb 2025 11:31:08 -0500 (EST)
Received: from alfajor (modemcable005.21-80-70.mc.videotron.ca [70.80.21.5])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id BDEEC12005D;
 Fri, 21 Feb 2025 11:31:08 -0500 (EST)
From: Stefan Monnier <monnier@HIDDEN>
To: Stefan Kangas <stefankangas@HIDDEN>
Subject: Re: bug#76313: New function `replace-region`
In-Reply-To: <CADwFkmn_G9DZjk_cjzPOtAr9wpQQ6tUVVjp3fBnetyT8cGahfA@HIDDEN>
Message-ID: <jwvpljbguqm.fsf-monnier+emacs@HIDDEN>
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86seoecung.fsf@HIDDEN>
 <jwvr03xzuvz.fsf-monnier+emacs@HIDDEN> <86mselbsbi.fsf@HIDDEN>
 <jwv1pvx5mtw.fsf-monnier+emacs@HIDDEN> <86h64sbw57.fsf@HIDDEN>
 <jwvzfik398m.fsf-monnier+emacs@HIDDEN> <865xl8blam.fsf@HIDDEN>
 <jwvy0y49w9z.fsf-monnier+emacs@HIDDEN> <86ldu3a18y.fsf@HIDDEN>
 <jwvpljf1jh5.fsf-monnier+emacs@HIDDEN> <86msej8du2.fsf@HIDDEN>
 <jwvtt8ryyzl.fsf-monnier+emacs@HIDDEN> <86a5aj82zq.fsf@HIDDEN>
 <jwvtt8rxbnr.fsf-monnier+emacs@HIDDEN> <86h64q6t87.fsf@HIDDEN>
 <jwveczuugkw.fsf-monnier+emacs@HIDDEN>
 <CADwFkmm_wYVQRMk83EJww9mTbboCcyTTc-bVVbog9SNeN0d05A@HIDDEN>
 <87r03tw121.fsf@HIDDEN>
 <CADwFkmn_G9DZjk_cjzPOtAr9wpQQ6tUVVjp3fBnetyT8cGahfA@HIDDEN>
Date: Fri, 21 Feb 2025 11:31:00 -0500
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.065 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76313
Cc: Philipp Stephani <phst@HIDDEN>, 76313 <at> debbugs.gnu.org,
 Eli Zaretskii <eliz@HIDDEN>, Tassilo Horn <tsdh@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

>>> The `replace-region-contents' function builds on that, and similarly
>>> has a complicated calling convention.  I think it should similarly be
>>> renamed to highlight its specialized nature.
>>
>> Fine with me but we have to consider that it's already used in the wild.
>> I remember submitting patches to at least restclient.el (which only uses
>> it through json-pretty-print-buffer so wouldn't be affected by renaming)
>> and hindent.el, see
>> https://github.com/mihaimaruseac/hindent/blob/master/elisp/hindent.el#L2=
20.
>> Maybe there are other callers in third-party packages.
>
> We could just leave the old names as aliases, so nothing should break.
> Anyways, it's not highly important to rename it, I just think that it
> might help clarify its intended use.

I suggest we start by merging `replace-region-contents` and `replace-buffer=
-contents`.
The downsides I see of each interface is:

- `replace-region-contents` takes a REPLACE-FN whereas
  it's often easier to compute the replacement beforehand.
- `replace-buffer-contents` operates only on the "whole"
  buffer, so requires the use of narrowing if we need something else.
- `replace-buffer-contents` can't accept a string as the replacement
  because it already takes a string to mean the name of a buffer.

I think it's hard to fix the problems of `replace-buffer-contents`
in a backward incompatible way, so I suggest we "standardize" on
`replace-region-contents` instead where we replace its REPLACE-FN argument
with a REPLACE argument which can be either a string, or a buffer, or
a function (this latter one could be deprecated, but we'd keep it for
backward compatibility).

This is backward-compatible, so we would obsolete only `replace-buffer-cont=
ents`.

Compared to my notion of ideal this would still have three problems:

- It's much slower than insert+delete-region, so it's not a replacement
  for the function I proposed.  We could add a "fast" option to it, but
  this fast option (which would presumably be the most common use case)
  would require every caller to pass an extra argument, which
  would be inconvenient (would encourage people to use the expensive
  code without being aware of the risk).
- It lacks an option to `insert-and-inherit` (needed by
  `minibuffer--replace`).  We could add one more optional arg for it.
  It would be kind of "far" (after MAX-SECS MAX-COSTS), so it's not
  ideal, but it's not the end of the world.
- It still uses this MAX-COSTS argument which noone seems to understand.

BTW, the code of `replace-buffer-contents` does:

       del_range (...);
       Finsert_buffer_substring (...);

This means that As it currently stands, when there is no similarity
between the before and after contents, `replace-buffer-contents`
preserves markers less carefully than the `replace-region` code
I sent =F0=9F=99=81.

The above would be better replaced by a call to a simple&fast
`replace-region`, tho contrary to the one I sent, that one needs to take
its replacement text from a region of a buffer rather than from
a string.  I guess we could let the STRING (aka REPLACE) arg of
`replace-region` be a triplet (BUFFER FROM TO), or we could add another
function of the form

    (replace-region-from-buffer BEG END
                                BUFFER BUFFER-BEG BUFFER-END
                                &optional INHERIT)

or require the use of narrowing in the source buffer to implicitly pass
the bounds.


        Stefan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 20 Feb 2025 10:37:56 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Feb 20 05:37:56 2025
Received: from localhost ([127.0.0.1]:60804 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tl3wJ-0005FF-Js
	for submit <at> debbugs.gnu.org; Thu, 20 Feb 2025 05:37:56 -0500
Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]:59879)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <stefankangas@HIDDEN>)
 id 1tl3wG-0005ET-DJ
 for 76313 <at> debbugs.gnu.org; Thu, 20 Feb 2025 05:37:53 -0500
Received: by mail-ed1-x533.google.com with SMTP id
 4fb4d7f45d1cf-5ded51d31f1so1286287a12.3
 for <76313 <at> debbugs.gnu.org>; Thu, 20 Feb 2025 02:37:52 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1740047866; x=1740652666; darn=debbugs.gnu.org;
 h=cc:to:subject:message-id:date:mime-version:references:in-reply-to
 :from:from:to:cc:subject:date:message-id:reply-to;
 bh=8b09D2E/Q6YxNVAm/vtcb4v8YqNGl8ptlRCVjMA29M8=;
 b=IpD5jLOgfhizpre4kmJW5fvhNHu1KXoGKRswvBkNwySe/C3njpNY7FWV578TddHtLi
 z/a5QxVGHZLd01r/iF6J6M1vm9cQ6OzbQ0t1BP7pwsIIw6N3DtGZ0GDTNny1lvsETIcZ
 3jBrGfQS7rS2ZOPldWPNWxgq5IZ8E9xryj7Kwn+RrBG/Prt55iHr5ODEXQhl52hmk0WY
 7EtuNEbH0zMLSyy490pna47SVgiHABlUlJfzX4W6U79hqHNNaDkLFmEuhZUXR55YShyP
 omA8QuhdIDliPW5k6HI3VsOXQSTkrVUyTJPQ9F+Q5x7OPly71BBfK7o4qRVikfEqZYRM
 oN1g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1740047866; x=1740652666;
 h=cc:to:subject:message-id:date:mime-version:references:in-reply-to
 :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=8b09D2E/Q6YxNVAm/vtcb4v8YqNGl8ptlRCVjMA29M8=;
 b=Ikg8x7xEQ6Evgpnsm91cHE/LJWxko1eExleNjQo2Tvkn1qZMIAG+NIuXeLMKZT98gp
 JnXTT5tPTDl5OcY9NE1jGLrloatqnCrN02kIFJNI4VByuSdXmHIoAq7K9YJyKoqOPaSc
 0oubEpHtg5HMJZkBgsYJfwrEtoDnjnNCnzlrxsC/yCsVvoRZytAypXs6Fq/IulQGwUGe
 lCiKv5b+JRO/1izpDgFh2Js0ekM3VQK0sUBLkgHCOwg5GwS8vxld5/acMW88qf808nF/
 pElm94Ck0EXe3islg22tDnD8q4AfcuV2ZETQF7OvE2MPxgIPBOG0JCY5C68ETxKqTPc/
 qs8g==
X-Forwarded-Encrypted: i=1;
 AJvYcCWL2FyydmgBMONp/wRZDJTyoF/ql0EyBlRpjf7NTdeBH/dyKI5EMfKleIl6l+ncX/b+ljqpSw==@debbugs.gnu.org
X-Gm-Message-State: AOJu0YxWcwdoOmTTNRQNBEcrYntpu07q2cZnhLWwhFKkNdKLqN+S3beg
 q/mZ7b7z9dQNZ5y+IavbdZe/wyIkJn2bFPBCaYQRx+Dp1bT6PfPOZavwNe2AYd9m+48Mj9cF1ro
 FmMilAWX00bg9UwfioTXUjeF1MJY=
X-Gm-Gg: ASbGnctRqn6mfO/onCn6uyMa3FGYFMvVcRW5BujviuoxHskP07U4Vv8B46DxHPI6db7
 hd+PUopa/xYVZ1Qvy0MxLI1RQHyqOApCzQdFYbl6MGhsJU0Z1JHhR73KgXG3TtmayNdQCHO+2Vp
 0=
X-Google-Smtp-Source: AGHT+IFeymHbQnuYtedQHdFvwN0YBBpaI9NKjsvvxT9GIpJBeB0pJZ9Se25LQnnNKMdAcoO/Sj2FSX8CXFv9peUjix0=
X-Received: by 2002:a05:6402:26cd:b0:5d9:82bc:ad06 with SMTP id
 4fb4d7f45d1cf-5e0894f7a1dmr6921582a12.3.1740047866195; Thu, 20 Feb 2025
 02:37:46 -0800 (PST)
Received: from 753933720722 named unknown by gmailapi.google.com with
 HTTPREST; Thu, 20 Feb 2025 02:37:45 -0800
From: Stefan Kangas <stefankangas@HIDDEN>
In-Reply-To: <87r03tw121.fsf@HIDDEN>
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86seoecung.fsf@HIDDEN>
 <jwvr03xzuvz.fsf-monnier+emacs@HIDDEN> <86mselbsbi.fsf@HIDDEN>
 <jwv1pvx5mtw.fsf-monnier+emacs@HIDDEN> <86h64sbw57.fsf@HIDDEN>
 <jwvzfik398m.fsf-monnier+emacs@HIDDEN> <865xl8blam.fsf@HIDDEN>
 <jwvy0y49w9z.fsf-monnier+emacs@HIDDEN> <86ldu3a18y.fsf@HIDDEN>
 <jwvpljf1jh5.fsf-monnier+emacs@HIDDEN> <86msej8du2.fsf@HIDDEN>
 <jwvtt8ryyzl.fsf-monnier+emacs@HIDDEN> <86a5aj82zq.fsf@HIDDEN>
 <jwvtt8rxbnr.fsf-monnier+emacs@HIDDEN> <86h64q6t87.fsf@HIDDEN>
 <jwveczuugkw.fsf-monnier+emacs@HIDDEN>
 <CADwFkmm_wYVQRMk83EJww9mTbboCcyTTc-bVVbog9SNeN0d05A@HIDDEN>
 <87r03tw121.fsf@HIDDEN>
MIME-Version: 1.0
Date: Thu, 20 Feb 2025 02:37:45 -0800
X-Gm-Features: AWEUYZkGNlZNHbg7es7BSukyTnCqo8gtOYkLBnDRop8XxusYssk2RjfLr53onDs
Message-ID: <CADwFkmn_G9DZjk_cjzPOtAr9wpQQ6tUVVjp3fBnetyT8cGahfA@HIDDEN>
Subject: Re: bug#76313: New function `replace-region`
To: Tassilo Horn <tsdh@HIDDEN>
Content-Type: text/plain; charset="UTF-8"
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76313
Cc: Philipp Stephani <phst@HIDDEN>, 76313 <at> debbugs.gnu.org,
 Eli Zaretskii <eliz@HIDDEN>, Stefan Monnier <monnier@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Tassilo Horn <tsdh@HIDDEN> writes:

> Stefan Kangas <stefankangas@HIDDEN> writes:
>
>>> The benefits of supporting the `replace-region-contents` API are much
>>> smaller than the "sounded minor" annoyances we'd have to pay for the
>>> rest of Emacs's future.
>>
>> AFAIU, the `replace-buffer-contents` API exists because:
>>
>>> There are many tools (e.g. auto-formatters) that take buffer
>>> contents, reformat them, and write the reformatted output somewhere.
>>> However, there is no good way how to apply the modified output to the
>>> source buffer.  The naive way (erasing and re-inserting the buffer
>>> contents) loses point and markers.  Therefore there should be a
>>> function (e.g. `replace-buffer-contents') that calculates a minimal
>>> diff between the old and the new contents and uses editing operations
>>> (insert, delete, etc.) to apply the diff.  Ideally this would be done
>>> without any external tools (e.g. 'diff').
>>   https://debbugs.gnu.org/cgi/bugreport.cgi?bug=25355
>
> That's true.  I use it frequently (through json-pretty-print-buffer) to
> format minimized JSON replies from REST-APIs.  It would be a bummer if
> point moved to the end of the buffer contents after formatting.  But it
> can be unbearable slow if the region is very large and the replacement
> text differs a lot from the current text.  That's why it has these
> strange MAX-SECS and MAX-COSTS arguments.
>
>> This sounds quite specialized to my mind, and the API is also quite
>> complicated.  I think it's a fine addition for this use case, but I'd
>> suggest renaming it to something that highlights its specialized
>> nature.
>>
>> The `replace-region-contents' function builds on that, and similarly
>> has a complicated calling convention.  I think it should similarly be
>> renamed to highlight its specialized nature.
>
> Fine with me but we have to consider that it's already used in the wild.
> I remember submitting patches to at least restclient.el (which only uses
> it through json-pretty-print-buffer so wouldn't be affected by renaming)
> and hindent.el, see
> https://github.com/mihaimaruseac/hindent/blob/master/elisp/hindent.el#L220.
> Maybe there are other callers in third-party packages.

We could just leave the old names as aliases, so nothing should break.
Anyways, it's not highly important to rename it, I just think that it
might help clarify its intended use.

>> Meanwhile, according to what we have learned in Bug#71370, many users
>> are currently using this:
>>
>>     (setf (buffer-substring START END) "foo")
>
> That's actually quite elegant (although it gives an obsolecence
> warning).  It never occured to me that (buffer-substring START END) was
> a generalized variable.

I think the main "problem" is that ELisp programmers are more used to
functions than generalized variables, so some people (like you and me
probably) are less used to them.  I also wasn't aware of this until we
decided to obsolete it a few years ago.

>> I think this shows the need for a more low-level operation, and
>> `replace-region` seems to fit this use case exactly.  So I would be in
>> favor of installing it.
>
> IMHO, it should at least reference replace-region-contents from its
> docstring and explain the difference (and vice-versa).

Fully agreed.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 20 Feb 2025 07:03:16 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Feb 20 02:03:16 2025
Received: from localhost ([127.0.0.1]:58755 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tl0aZ-0001mY-MJ
	for submit <at> debbugs.gnu.org; Thu, 20 Feb 2025 02:03:16 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:45350)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <tsdh@HIDDEN>) id 1tl0aW-0001lk-Ex
 for 76313 <at> debbugs.gnu.org; Thu, 20 Feb 2025 02:03:13 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <tsdh@HIDDEN>)
 id 1tl0aQ-0001dd-7K; Thu, 20 Feb 2025 02:03:06 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To:
 From; bh=e3gSmXDLbufRFtjy+Wig4IaOJ6kSlq1iIHLOWGHATGg=; b=DDfdusTMqCw5RSShdt3k
 eHiDkyl69FxCr188WD/fYiRfL84kbJ1c4ceN2mO/DAn1Dz/jB7vgqRWAEj7ocWww4j2wVXMfDBsb3
 QCBhgomZEPjHgOfGW7YnwjkIQ7OeJkGRGKBx7vODhLAgEsQnX8DT0ne7dZyjuj4IekZ9FmYkq4fZM
 Yl9ilIqe14ew6Lpw/Dv9jVz7wwPwUybKlSN24lhl0J2BHBewJMuWgPlH7UnxLOArxFrcFezYxGVWR
 uoYkgzUorAsFydnkszsHt8u0S5zD/AeFYOVPU+YLLjl7QViC3zyNXX6PB7DJ4OUvAarCtJFCuiuxm
 JlZy/WkxYpfvyA==;
X-ME-Sender: <xms:qNO2Z_CpIwVuK5ZRn-LxVyqr7mGMBrS8m7CFPOMAZU1IxNNBRdME5w>
 <xme:qNO2Z1gXE0xnmL15LfDYZkFwnu5k3DfpMn6f_ZV1n5ZIfw9gMXs4GwevMiWxUmyV3
 ourrOIN4DpPDg>
X-ME-Received: <xmr:qNO2Z6lYmlcFDUb1ZQsHcjUXvjTy4mHz-NvMxEq-EY8-VerCV6mj8twmKPpjuKZARVZdRz0Wv8ki0Jx5SDt8BABTiyY4GoGL>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdeiieehudcutefuodetggdotefrod
 ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp
 uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg
 hnthhsucdlqddutddtmdenucfjughrpefhvfevufgjfhgffffkgggtsehttdertddtredt
 necuhfhrohhmpefvrghsshhilhhoucfjohhrnhcuoehtshguhhesghhnuhdrohhrgheqne
 cuggftrfgrthhtvghrnhepvdeiveefhedvtdejiefftdeitdfggfejjeehkefggeefgfeg
 ieelveejhffhfefgnecuffhomhgrihhnpehgnhhurdhorhhgpdhgihhthhhusgdrtghomh
 enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehthhho
 rhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdekieejfeekjeekgedqie
 efhedvleekqdhtshguhheppehgnhhurdhorhhgsehfrghsthhmrghilhdrfhhmpdhnsggp
 rhgtphhtthhopeehpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehphhhsthesgh
 hoohhglhgvrdgtohhmpdhrtghpthhtohepjeeifedufeesuggvsggsuhhgshdrghhnuhdr
 ohhrghdprhgtphhtthhopegvlhhiiiesghhnuhdrohhrghdprhgtphhtthhopehmohhnnh
 hivghrsehirhhordhumhhonhhtrhgvrghlrdgtrgdprhgtphhtthhopehsthgvfhgrnhhk
 rghnghgrshesghhmrghilhdrtghomh
X-ME-Proxy: <xmx:qNO2ZxwCD4fOXaaQF7pOMfyu6SqfgsKIskF7NkJuoU8lyKp2xuAqAA>
 <xmx:qNO2Z0TSXHMtl0cWjj6wRHNqLXUUF5cKEnrAv0xUbExVU5EZZG1cGw>
 <xmx:qNO2Z0Y7BdMGA5PuuOo8q14BbmGakG9XOI05XEmnTGi70MVMn_WBWA>
 <xmx:qNO2Z1SyoFfIdhxEbjnUr5wSi0vx30Gpg3vYPvec-GZ4r-raGKHj4w>
 <xmx:qdO2Z6AyxPVrPZ-eKGD1YLy0fdgF78YbiTiMmyVBH2KBeqgDEsZqk-Y5>
Feedback-ID: ib2b94485:Fastmail
From: Tassilo Horn <tsdh@HIDDEN>
To: Stefan Kangas <stefankangas@HIDDEN>
Subject: Re: bug#76313: New function `replace-region`
In-Reply-To: <CADwFkmm_wYVQRMk83EJww9mTbboCcyTTc-bVVbog9SNeN0d05A@HIDDEN>
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86seoecung.fsf@HIDDEN>
 <jwvr03xzuvz.fsf-monnier+emacs@HIDDEN> <86mselbsbi.fsf@HIDDEN>
 <jwv1pvx5mtw.fsf-monnier+emacs@HIDDEN> <86h64sbw57.fsf@HIDDEN>
 <jwvzfik398m.fsf-monnier+emacs@HIDDEN> <865xl8blam.fsf@HIDDEN>
 <jwvy0y49w9z.fsf-monnier+emacs@HIDDEN> <86ldu3a18y.fsf@HIDDEN>
 <jwvpljf1jh5.fsf-monnier+emacs@HIDDEN> <86msej8du2.fsf@HIDDEN>
 <jwvtt8ryyzl.fsf-monnier+emacs@HIDDEN> <86a5aj82zq.fsf@HIDDEN>
 <jwvtt8rxbnr.fsf-monnier+emacs@HIDDEN> <86h64q6t87.fsf@HIDDEN>
 <jwveczuugkw.fsf-monnier+emacs@HIDDEN>
 <CADwFkmm_wYVQRMk83EJww9mTbboCcyTTc-bVVbog9SNeN0d05A@HIDDEN>
User-Agent: mu4e 1.12.8; emacs 31.0.50
Date: Thu, 20 Feb 2025 08:03:02 +0100
Message-ID: <87r03tw121.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76313
Cc: Philipp Stephani <phst@HIDDEN>, 76313 <at> debbugs.gnu.org,
 Eli Zaretskii <eliz@HIDDEN>, Stefan Monnier <monnier@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Stefan Kangas <stefankangas@HIDDEN> writes:

>> The benefits of supporting the `replace-region-contents` API are much
>> smaller than the "sounded minor" annoyances we'd have to pay for the
>> rest of Emacs's future.
>
> AFAIU, the `replace-buffer-contents` API exists because:
>
>> There are many tools (e.g. auto-formatters) that take buffer
>> contents, reformat them, and write the reformatted output somewhere.
>> However, there is no good way how to apply the modified output to the
>> source buffer.  The naive way (erasing and re-inserting the buffer
>> contents) loses point and markers.  Therefore there should be a
>> function (e.g. `replace-buffer-contents') that calculates a minimal
>> diff between the old and the new contents and uses editing operations
>> (insert, delete, etc.) to apply the diff.  Ideally this would be done
>> without any external tools (e.g. 'diff').
>   https://debbugs.gnu.org/cgi/bugreport.cgi?bug=25355

That's true.  I use it frequently (through json-pretty-print-buffer) to
format minimized JSON replies from REST-APIs.  It would be a bummer if
point moved to the end of the buffer contents after formatting.  But it
can be unbearable slow if the region is very large and the replacement
text differs a lot from the current text.  That's why it has these
strange MAX-SECS and MAX-COSTS arguments.

> This sounds quite specialized to my mind, and the API is also quite
> complicated.  I think it's a fine addition for this use case, but I'd
> suggest renaming it to something that highlights its specialized
> nature.
>
> The `replace-region-contents' function builds on that, and similarly
> has a complicated calling convention.  I think it should similarly be
> renamed to highlight its specialized nature.

Fine with me but we have to consider that it's already used in the wild.
I remember submitting patches to at least restclient.el (which only uses
it through json-pretty-print-buffer so wouldn't be affected by renaming)
and hindent.el, see
https://github.com/mihaimaruseac/hindent/blob/master/elisp/hindent.el#L220.
Maybe there are other callers in third-party packages.

> Meanwhile, according to what we have learned in Bug#71370, many users
> are currently using this:
>
>     (setf (buffer-substring START END) "foo")

That's actually quite elegant (although it gives an obsolecence
warning).  It never occured to me that (buffer-substring START END) was
a generalized variable.

> I think this shows the need for a more low-level operation, and
> `replace-region` seems to fit this use case exactly.  So I would be in
> favor of installing it.

IMHO, it should at least reference replace-region-contents from its
docstring and explain the difference (and vice-versa).

Bye,
Tassilo




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 19 Feb 2025 18:22:52 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Feb 19 13:22:52 2025
Received: from localhost ([127.0.0.1]:51283 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tkoih-0004V8-KA
	for submit <at> debbugs.gnu.org; Wed, 19 Feb 2025 13:22:52 -0500
Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]:45297)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <stefankangas@HIDDEN>)
 id 1tkoic-0004Tv-MW
 for 76313 <at> debbugs.gnu.org; Wed, 19 Feb 2025 13:22:49 -0500
Received: by mail-ed1-x52c.google.com with SMTP id
 4fb4d7f45d1cf-5e04cb346eeso24062a12.2
 for <76313 <at> debbugs.gnu.org>; Wed, 19 Feb 2025 10:22:46 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1739989360; x=1740594160; darn=debbugs.gnu.org;
 h=cc:to:subject:message-id:date:mime-version:references:in-reply-to
 :from:from:to:cc:subject:date:message-id:reply-to;
 bh=aIesORsqXleWs9CHPWl4Vy3dM6kXps4UAwPqQdfjpWQ=;
 b=UbxOQQ+yTszItyfdDPnJrRZ4OuNZ8AZOxd5tOcvi1JWWwYTjISPAM/9HkkFd9Q5gTv
 UqsW7D1yc2QUJHd5/g2YWYIi5xOnCT3k7z15Ao1y2vBzULwEQOnM/GudtiEEG2+2olnu
 uGd2d0nCSoPRDF9vBnFGx3XG5Npkz3nGUcSjZkU/JGYRN21+/38NA7TiFBua0iuR8kKr
 FUgmB5qObqmo4kIMiMMaADNUMVh6WaJhqpj4tntXGfTFH4xkeIn8CTDEUYbbMq2aV8bR
 RpyqKSIFFwxJ4jOF2TYDZFYr9BM1PI73weLuWaQNa6qXzLLcn0F1R0kW6Cpln9Odducc
 Iv4Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1739989360; x=1740594160;
 h=cc:to:subject:message-id:date:mime-version:references:in-reply-to
 :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=aIesORsqXleWs9CHPWl4Vy3dM6kXps4UAwPqQdfjpWQ=;
 b=laDOGeUV8RAWfuO9Ho1CbVTIc9oBZ5jghAe25IFaa4yj23DkKW9juZRj4LafiWdw3Y
 t9S0a7O9c6xFgQKPIThlJT352lzC87UMWblYZb85od434Wbl4x2MccYOX2cmwVu23pwu
 bxrkcUIM0uFvkOEip7Cy6H+qTFN1SVktBM5RdA6YYZ0Xmm85TYeia+rn6nG+opurg+SF
 9X7c/HdkJp4UPlfXauPp6Yt5v7MQtlOdFnbtcEE/FmAsFX8rJMM5gXbIVzoSxUol2Jc3
 cctyjnuLXAsKiIV5utUUm8Kp/IkjERJ0BFl1Vmp6XbyTPcVme+RXarXByFag1BioECYL
 D5QA==
X-Gm-Message-State: AOJu0Yx+r7Upx36wQWr6NCK1uLgWwWN8UqvONVzonVCf3d3iKaPZbv+7
 VHUCaEGbppHFT8O95Hux02gxyEBofiYNPPbM4T2yTnvbSKvsYMbTCxGsJ/WmuDotm6vsx7YQd/k
 FNbkInEZtyvkJeTiB4r5S9BYaq/0=
X-Gm-Gg: ASbGncviF02OyRi5fVSLUHW1gjerQdPXOqoTSz7VrfyjEs3zfOkmf9JPSjqePM9sfYa
 iB8D1TqEum76y4QN1SerNKIDTfS8jGB4+JCd1TJCkZ9i2p1zrInHf33kN7oRLKvdiq0OXzge/xw
 ==
X-Google-Smtp-Source: AGHT+IHb1wBlO+ZDTTM6Jrp5kLlYMCUyqqy/qMamVd7MJhr2IyWnWiY44YtTgiRkYUC87KedDg68W30yEjXVNJ0fyw4=
X-Received: by 2002:a05:6402:40c8:b0:5de:5865:4994 with SMTP id
 4fb4d7f45d1cf-5e03606f44dmr18050888a12.8.1739989360136; Wed, 19 Feb 2025
 10:22:40 -0800 (PST)
Received: from 753933720722 named unknown by gmailapi.google.com with
 HTTPREST; Wed, 19 Feb 2025 18:22:39 +0000
From: Stefan Kangas <stefankangas@HIDDEN>
In-Reply-To: <jwveczuugkw.fsf-monnier+emacs@HIDDEN>
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86seoecung.fsf@HIDDEN>
 <jwvr03xzuvz.fsf-monnier+emacs@HIDDEN> <86mselbsbi.fsf@HIDDEN>
 <jwv1pvx5mtw.fsf-monnier+emacs@HIDDEN> <86h64sbw57.fsf@HIDDEN>
 <jwvzfik398m.fsf-monnier+emacs@HIDDEN> <865xl8blam.fsf@HIDDEN>
 <jwvy0y49w9z.fsf-monnier+emacs@HIDDEN> <86ldu3a18y.fsf@HIDDEN>
 <jwvpljf1jh5.fsf-monnier+emacs@HIDDEN> <86msej8du2.fsf@HIDDEN>
 <jwvtt8ryyzl.fsf-monnier+emacs@HIDDEN> <86a5aj82zq.fsf@HIDDEN>
 <jwvtt8rxbnr.fsf-monnier+emacs@HIDDEN> <86h64q6t87.fsf@HIDDEN>
 <jwveczuugkw.fsf-monnier+emacs@HIDDEN>
MIME-Version: 1.0
Date: Wed, 19 Feb 2025 18:22:39 +0000
X-Gm-Features: AWEUYZkMLTiCl66azawosKsXuVmC4vPraayhCft8yz5a1wNoP1dWW-DVCWfw69o
Message-ID: <CADwFkmm_wYVQRMk83EJww9mTbboCcyTTc-bVVbog9SNeN0d05A@HIDDEN>
Subject: Re: bug#76313: New function `replace-region`
To: Stefan Monnier <monnier@HIDDEN>, Eli Zaretskii <eliz@HIDDEN>
Content-Type: text/plain; charset="UTF-8"
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 76313
Cc: Philipp Stephani <phst@HIDDEN>, 76313 <at> debbugs.gnu.org,
 Tassilo Horn <tsdh@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <bug-gnu-emacs@HIDDEN> writes:

>> It's up to you, but I still think that by a relatively simple and
>> backward-compatible change to the API of replace-region-contents we
>> could have a new mode of that function which would do what you wanted.
>> I still don't understand why you rejected that, the reasons you gave
>> sounded minor to me, certainly not important enough to throw in the
>> towel.
>
> The benefits of supporting the `replace-region-contents` API are much
> smaller than the "sounded minor" annoyances we'd have to pay for the
> rest of Emacs's future.

AFAIU, the `replace-buffer-contents` API exists because:

> There are many tools (e.g. auto-formatters) that take buffer contents,
> reformat them, and write the reformatted output somewhere.  However,
> there is no good way how to apply the modified output to the source
> buffer.  The naive way (erasing and re-inserting the buffer contents)
> loses point and markers.  Therefore there should be a function
> (e.g. `replace-buffer-contents') that calculates a minimal diff between
> the old and the new contents and uses editing operations (insert,
> delete, etc.) to apply the diff.  Ideally this would be done without any
> external tools (e.g. 'diff').
  https://debbugs.gnu.org/cgi/bugreport.cgi?bug=25355

This sounds quite specialized to my mind, and the API is also quite
complicated.  I think it's a fine addition for this use case, but I'd
suggest renaming it to something that highlights its specialized nature.

The `replace-region-contents' function builds on that, and similarly has
a complicated calling convention.  I think it should similarly be
renamed to highlight its specialized nature.

Meanwhile, according to what we have learned in Bug#71370, many users
are currently using this:

    (setf (buffer-substring START END) "foo")

I think this shows the need for a more low-level operation, and
`replace-region` seems to fit this use case exactly.  So I would be in
favor of installing it.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313-done <at> debbugs.gnu.org:


Received: (at 76313-done) by debbugs.gnu.org; 19 Feb 2025 15:03:04 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Feb 19 10:03:04 2025
Received: from localhost ([127.0.0.1]:48796 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tklbL-0006Jc-L9
	for submit <at> debbugs.gnu.org; Wed, 19 Feb 2025 10:03:04 -0500
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:10781)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1tklbJ-0006Io-0q
 for 76313-done <at> debbugs.gnu.org; Wed, 19 Feb 2025 10:03:01 -0500
Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 409F3442801;
 Wed, 19 Feb 2025 10:02:55 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1739977374;
 bh=EEY7P6BeZnmVpX3dSeCgDWw+JUDSv6WECpZfZq86lKY=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=bx40q3YUIux06W55ic9v58yF2JFZOIKln7tAOeIlrpK+yJ1A6Omuvfu9TkF1qtIeF
 KhJgPbpHGhvzCURo/NDB39NfYtFbePzF9SQ6hJxgERsoz6cHKbigWfGEPgYNLveAoS
 Zz1pZuszjQsCz8ehpgCDIiQGjlKP8S6lopNSXPQ3s2ajbmxgp6plhdtH42gSdDpmZ/
 O5GOKCDVI255Hvdxtgh/JOSmHWOCFaeJWt7B90W9FEPY8ScyZVCpV6THyZmKv8t6f6
 a+TP8fngjk9UCuhsqD1jm8JaK98F7ui/K9v3X8pLflSz1DCet88MnCw8gK/S/z12sZ
 yU9Og9b4s9kow==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 5525F4427FE;
 Wed, 19 Feb 2025 10:02:54 -0500 (EST)
Received: from alfajor (unknown [104.247.242.5])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 2B2F4120198;
 Wed, 19 Feb 2025 10:02:54 -0500 (EST)
From: Stefan Monnier <monnier@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#76313: New function `replace-region`
In-Reply-To: <86h64q6t87.fsf@HIDDEN> (Eli Zaretskii's message of "Wed, 19 Feb
 2025 13:59:04 +0200")
Message-ID: <jwveczuugkw.fsf-monnier+emacs@HIDDEN>
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86seoecung.fsf@HIDDEN>
 <jwvr03xzuvz.fsf-monnier+emacs@HIDDEN> <86mselbsbi.fsf@HIDDEN>
 <jwv1pvx5mtw.fsf-monnier+emacs@HIDDEN> <86h64sbw57.fsf@HIDDEN>
 <jwvzfik398m.fsf-monnier+emacs@HIDDEN> <865xl8blam.fsf@HIDDEN>
 <jwvy0y49w9z.fsf-monnier+emacs@HIDDEN> <86ldu3a18y.fsf@HIDDEN>
 <jwvpljf1jh5.fsf-monnier+emacs@HIDDEN> <86msej8du2.fsf@HIDDEN>
 <jwvtt8ryyzl.fsf-monnier+emacs@HIDDEN> <86a5aj82zq.fsf@HIDDEN>
 <jwvtt8rxbnr.fsf-monnier+emacs@HIDDEN> <86h64q6t87.fsf@HIDDEN>
Date: Wed, 19 Feb 2025 10:02:53 -0500
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.541 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76313-done
Cc: 76313-done <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> It's up to you, but I still think that by a relatively simple and
> backward-compatible change to the API of replace-region-contents we
> could have a new mode of that function which would do what you wanted.
> I still don't understand why you rejected that, the reasons you gave
> sounded minor to me, certainly not important enough to throw in the
> towel.

The benefits of supporting the `replace-region-contents` API are much
smaller than the "sounded minor" annoyances we'd have to pay for the
rest of Emacs's future.

And really, this whole discussion has been much too frustrating, for
such a trivial function which everyone can feel free to reinvent badly in
their own code.


        Stefan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313-done <at> debbugs.gnu.org:


Received: (at 76313-done) by debbugs.gnu.org; 19 Feb 2025 11:59:16 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Feb 19 06:59:15 2025
Received: from localhost ([127.0.0.1]:44009 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tkijT-0006XG-Am
	for submit <at> debbugs.gnu.org; Wed, 19 Feb 2025 06:59:15 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:33176)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tkijR-0006WR-5J
 for 76313-done <at> debbugs.gnu.org; Wed, 19 Feb 2025 06:59:13 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1tkijL-0004rn-Jc; Wed, 19 Feb 2025 06:59:07 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=X4EtbbHqKA7v6N/Xsvb6xDJz9sBk+EFEel2wiQlG/94=; b=LStflJvui0+0
 gsbJvmEkDufxQopLiGOnK0uIxrNMrPQt8rPYCSp9Bl/goqspVBDadXISeYjawoy2xBu7xDxW7S+qB
 4hMw3Y7wNtDa4OTn11MZ5aGF5q2P1IBUP5lMcZ6X/fEl3bBPt7IW9ZA3lpt4f/HEDDIE/91AQRYOt
 jdbthcXBtM5m1OnC65t+Cb0wKocEtOTRMC+ri5HJqUV+dKbE1dKRe8ccYBE8LVY2//AyCM0Y7tbEg
 LyFbla1O38KjZSf0oaM8FBijgIkYPWOxwCDCUg3wbhPX144KmmZW7F/uPlFUdtPFuTdDVCPAWpJaU
 6VD5diollEXAK6Fpc04E3w==;
Date: Wed, 19 Feb 2025 13:59:04 +0200
Message-Id: <86h64q6t87.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
In-Reply-To: <jwvtt8rxbnr.fsf-monnier+emacs@HIDDEN> (message from Stefan
 Monnier on Tue, 18 Feb 2025 15:04:22 -0500)
Subject: Re: bug#76313: New function `replace-region`
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86seoecung.fsf@HIDDEN>
 <jwvr03xzuvz.fsf-monnier+emacs@HIDDEN> <86mselbsbi.fsf@HIDDEN>
 <jwv1pvx5mtw.fsf-monnier+emacs@HIDDEN> <86h64sbw57.fsf@HIDDEN>
 <jwvzfik398m.fsf-monnier+emacs@HIDDEN> <865xl8blam.fsf@HIDDEN>
 <jwvy0y49w9z.fsf-monnier+emacs@HIDDEN> <86ldu3a18y.fsf@HIDDEN>
 <jwvpljf1jh5.fsf-monnier+emacs@HIDDEN> <86msej8du2.fsf@HIDDEN>
 <jwvtt8ryyzl.fsf-monnier+emacs@HIDDEN> <86a5aj82zq.fsf@HIDDEN>
 <jwvtt8rxbnr.fsf-monnier+emacs@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76313-done
Cc: 76313-done <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Stefan Monnier <monnier@HIDDEN>
> Cc: 76313-done <at> debbugs.gnu.org
> Date: Tue, 18 Feb 2025 15:04:22 -0500
> 
> > So basically, you reject every attempt to compromise that I could come
> > up with, and keep pressing for your original proposal, whose downsides
> > I prefer not to sustain.  Are you really saying that your way is the
> > only way? why?
> 
> Never mind,

It's up to you, but I still think that by a relatively simple and
backward-compatible change to the API of replace-region-contents we
could have a new mode of that function which would do what you wanted.
I still don't understand why you rejected that, the reasons you gave
sounded minor to me, certainly not important enough to throw in the
towel.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313-done <at> debbugs.gnu.org:


Received: (at 76313-done) by debbugs.gnu.org; 18 Feb 2025 20:04:33 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Feb 18 15:04:33 2025
Received: from localhost ([127.0.0.1]:33831 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tkTpY-0001ze-Ly
	for submit <at> debbugs.gnu.org; Tue, 18 Feb 2025 15:04:32 -0500
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:55062)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1tkTpW-0001z5-6C
 for 76313-done <at> debbugs.gnu.org; Tue, 18 Feb 2025 15:04:31 -0500
Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id E668D4426C8;
 Tue, 18 Feb 2025 15:04:23 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1739909063;
 bh=N1KKPaFUKZTx24gYhArmhZE8VmPEfYSxBmK+LbnNVRQ=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=piEoffwZpqHMyj3+6whmYocAhpNTbqnM6scJ1Y2tyjScQt+q/VlO5Jw4+bTmTeGju
 Nr7aPc57qGdpXtNjbaKqtMQEoSoeIf38J1xj1JQbuMczdDY7G/4Hh5w6GhnwbmFlWC
 qUX+e7UFCh3Sze8BtoU2XQJWWdb29gYQksBW7CHXiOln0E+tohxMKGHpdtigIejKo1
 s6xzF16c4F5FWXhtj9WHcJ7CMBKhkUALOEOtyDA/QHZksuqKa9gzKEjAWKCX6bRmne
 5+6CEZ5hXlVa7EfWkrpCHc71HEF1MVF5Ay+IIRh6bTPyhFxtKuXFHN+br2W4SfzNlf
 4sTlJ0tL8MBMw==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 1C0624426C3;
 Tue, 18 Feb 2025 15:04:23 -0500 (EST)
Received: from alfajor (modemcable005.21-80-70.mc.videotron.ca [70.80.21.5])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 0095C1204EE;
 Tue, 18 Feb 2025 15:04:22 -0500 (EST)
From: Stefan Monnier <monnier@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#76313: New function `replace-region`
In-Reply-To: <86a5aj82zq.fsf@HIDDEN> (Eli Zaretskii's message of "Tue, 18 Feb
 2025 21:30:33 +0200")
Message-ID: <jwvtt8rxbnr.fsf-monnier+emacs@HIDDEN>
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86seoecung.fsf@HIDDEN>
 <jwvr03xzuvz.fsf-monnier+emacs@HIDDEN> <86mselbsbi.fsf@HIDDEN>
 <jwv1pvx5mtw.fsf-monnier+emacs@HIDDEN> <86h64sbw57.fsf@HIDDEN>
 <jwvzfik398m.fsf-monnier+emacs@HIDDEN> <865xl8blam.fsf@HIDDEN>
 <jwvy0y49w9z.fsf-monnier+emacs@HIDDEN> <86ldu3a18y.fsf@HIDDEN>
 <jwvpljf1jh5.fsf-monnier+emacs@HIDDEN> <86msej8du2.fsf@HIDDEN>
 <jwvtt8ryyzl.fsf-monnier+emacs@HIDDEN> <86a5aj82zq.fsf@HIDDEN>
Date: Tue, 18 Feb 2025 15:04:22 -0500
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.092 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76313-done
Cc: 76313-done <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> So basically, you reject every attempt to compromise that I could come
> up with, and keep pressing for your original proposal, whose downsides
> I prefer not to sustain.  Are you really saying that your way is the
> only way? why?

Never mind,


        Stefan





Notification sent to Stefan Monnier <monnier@HIDDEN>:
bug acknowledged by developer. Full text available.
Reply sent to Stefan Monnier <monnier@HIDDEN>:
You have taken responsibility. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 18 Feb 2025 19:30:50 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Feb 18 14:30:50 2025
Received: from localhost ([127.0.0.1]:33518 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tkTIv-0005Vo-8f
	for submit <at> debbugs.gnu.org; Tue, 18 Feb 2025 14:30:49 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:60328)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tkTIs-0005CL-8k
 for 76313 <at> debbugs.gnu.org; Tue, 18 Feb 2025 14:30:47 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1tkTIk-0007LO-IM; Tue, 18 Feb 2025 14:30:40 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=zP64frgZYACCHjdqp7tq0oXb2/8Xb4WcGzVXQ52k4kA=; b=Ug0LLoh7V7v0
 Tx7T3UOcaRc62CAjNqckozqBD/t3NvlPM8kylK9E0cdXHobeTIwg8SfVW5mUsXcprQ9pVft5KI1ah
 41WP/14/q9LRN7jiFLEsbToCqks+yDwWhvj8Q85yo6Gf/fYvZzCOJ11TZF9AbVJwNA12BOpfK3Jqz
 2iFtt6ee21ubiU3pRkanTuUmSYkmVXZyNS8dYF4zPUW8CteuAtO8UN1RapviS/Z5WOtZR9px8GjT0
 bjZWe4O5WSFtEEMY8c1AaTf+/bAQ9biYX5LzL4WP7LbRebbihdE4qoteCwmDoPW0JGqYeYG/IBT7c
 V2YQQwiY7pBQoQnju2wr8w==;
Date: Tue, 18 Feb 2025 21:30:33 +0200
Message-Id: <86a5aj82zq.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
In-Reply-To: <jwvtt8ryyzl.fsf-monnier+emacs@HIDDEN> (message from Stefan
 Monnier on Tue, 18 Feb 2025 12:01:38 -0500)
Subject: Re: bug#76313: New function `replace-region`
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86seoecung.fsf@HIDDEN>
 <jwvr03xzuvz.fsf-monnier+emacs@HIDDEN> <86mselbsbi.fsf@HIDDEN>
 <jwv1pvx5mtw.fsf-monnier+emacs@HIDDEN> <86h64sbw57.fsf@HIDDEN>
 <jwvzfik398m.fsf-monnier+emacs@HIDDEN> <865xl8blam.fsf@HIDDEN>
 <jwvy0y49w9z.fsf-monnier+emacs@HIDDEN> <86ldu3a18y.fsf@HIDDEN>
 <jwvpljf1jh5.fsf-monnier+emacs@HIDDEN> <86msej8du2.fsf@HIDDEN>
 <jwvtt8ryyzl.fsf-monnier+emacs@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76313
Cc: 76313 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Stefan Monnier <monnier@HIDDEN>
> Cc: 76313 <at> debbugs.gnu.org
> Date: Tue, 18 Feb 2025 12:01:38 -0500
> 
> >> `replace-region-contents` is a bad API
> > Why is it bad?
> 
> - REPLACE-FN is never useful, it's always just as easy (and marginally
>   more efficient) to compute the replacement beforehand.
> - It defaults to being expensive, whereas most potential users of
>   `replace-region` currently use insert+delete-region and thus would
>   need to pass an extra "cheaply" argument for fear of being impacted by
>   a slowdown.
> - MAX-COSTS is ill-defined.
> 
> Also, personally I must say that I'd be happier calling `replace-region`
> than `replace-region-contents`, just because it's shorter.
> 
> Given that `replace-region-contents` is fairly new and very little used,
> I don't see much gain in trying to fit within its API.

So basically, you reject every attempt to compromise that I could come
up with, and keep pressing for your original proposal, whose downsides
I prefer not to sustain.  Are you really saying that your way is the
only way? why?




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 18 Feb 2025 17:01:58 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Feb 18 12:01:58 2025
Received: from localhost ([127.0.0.1]:60092 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tkQys-0007Cf-1Z
	for submit <at> debbugs.gnu.org; Tue, 18 Feb 2025 12:01:58 -0500
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:52171)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1tkQyg-0007C0-Rc
 for 76313 <at> debbugs.gnu.org; Tue, 18 Feb 2025 12:01:56 -0500
Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 008734415EE;
 Tue, 18 Feb 2025 12:01:41 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1739898100;
 bh=IdeU4BFKx5vFUrTxIB+QJPz0aZYy3/p7+X4UNRdgzmw=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=Z3SN0Ep3s1iITan4+pKpG0bFpAwiZN4UAtBGMi5JJ1h6jikJ04pVayiBE/aVxqzl6
 +YD1Rw47afuFwpLbadvQEdnwziR9EUBOnEexNGrrwM5u3DpppMLZIcseLYN07xrcuV
 PIlaPTZqAeVkkTFdffCoM0umOwr7Gkq7CQRaxss1mW0f7QxW2e4dRU9Yiey0g1/uDA
 dTjxdGlYQAQ4ci4rZLU8btq/cGRUSXi6zwTlFceC9Fx03AvdXXc9OQJLem7eRwhLVS
 hTVAeZhWSkup6myy6c2fvsYkmVS/T5v/ChxaSGpAt9TrJ3nMYfk2PV8DwLRNTOfJgq
 mfcVzdm6wccNA==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 1176A4414F3;
 Tue, 18 Feb 2025 12:01:40 -0500 (EST)
Received: from alfajor (unknown [104.247.242.5])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id DDCB112028D;
 Tue, 18 Feb 2025 12:01:39 -0500 (EST)
From: Stefan Monnier <monnier@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#76313: New function `replace-region`
In-Reply-To: <86msej8du2.fsf@HIDDEN> (Eli Zaretskii's message of "Tue, 18 Feb
 2025 17:36:21 +0200")
Message-ID: <jwvtt8ryyzl.fsf-monnier+emacs@HIDDEN>
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86seoecung.fsf@HIDDEN>
 <jwvr03xzuvz.fsf-monnier+emacs@HIDDEN> <86mselbsbi.fsf@HIDDEN>
 <jwv1pvx5mtw.fsf-monnier+emacs@HIDDEN> <86h64sbw57.fsf@HIDDEN>
 <jwvzfik398m.fsf-monnier+emacs@HIDDEN> <865xl8blam.fsf@HIDDEN>
 <jwvy0y49w9z.fsf-monnier+emacs@HIDDEN> <86ldu3a18y.fsf@HIDDEN>
 <jwvpljf1jh5.fsf-monnier+emacs@HIDDEN> <86msej8du2.fsf@HIDDEN>
Date: Tue, 18 Feb 2025 12:01:38 -0500
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.640 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76313
Cc: 76313 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

>> `replace-region-contents` is a bad API
> Why is it bad?

- REPLACE-FN is never useful, it's always just as easy (and marginally
  more efficient) to compute the replacement beforehand.
- It defaults to being expensive, whereas most potential users of
  `replace-region` currently use insert+delete-region and thus would
  need to pass an extra "cheaply" argument for fear of being impacted by
  a slowdown.
- MAX-COSTS is ill-defined.

Also, personally I must say that I'd be happier calling `replace-region`
than `replace-region-contents`, just because it's shorter.

Given that `replace-region-contents` is fairly new and very little used,
I don't see much gain in trying to fit within its API.


        Stefan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 18 Feb 2025 15:36:34 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Feb 18 10:36:34 2025
Received: from localhost ([127.0.0.1]:59183 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tkPeE-0000CZ-1B
	for submit <at> debbugs.gnu.org; Tue, 18 Feb 2025 10:36:34 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:47544)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tkPe9-0000Bz-GF
 for 76313 <at> debbugs.gnu.org; Tue, 18 Feb 2025 10:36:31 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1tkPe3-0001mj-9P; Tue, 18 Feb 2025 10:36:23 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=9DiR7dmpY80Ko+T8o8JA+kzBETP0ec+XdQiap1xAX20=; b=csQqC80TSQWG
 d9mQUaDThgAu6td4u6o0uzzEI6EcnqHoy2XbjQphcETlbm2e99VlNhU/f9sCdcAwSvrxWFKvpBWT2
 DW+XpYrouA7JC+z9RklkTrXe0EqbtAuPlfFz65vPW9JNMV1k4POuy6femYeUdOuh9mLbNxw8X9Nwr
 Wz4m3yAI6HohAAyJphH5aOTJmg2eAg0otMt93sbv+f11PGrLViVVYXwv0T/di4hF/SZcIWGaTDeWa
 cmvZB3noez8yuHcy/KJkZtmgeSwokg6jrciyZ74+kpMgR5SZgOglM/wX6TR9QXmnUSCyPyY+jtnaD
 wQzB9E453BcBfPJ8nHLpHA==;
Date: Tue, 18 Feb 2025 17:36:21 +0200
Message-Id: <86msej8du2.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
In-Reply-To: <jwvpljf1jh5.fsf-monnier+emacs@HIDDEN> (message from Stefan
 Monnier on Tue, 18 Feb 2025 08:30:16 -0500)
Subject: Re: bug#76313: New function `replace-region`
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86seoecung.fsf@HIDDEN>
 <jwvr03xzuvz.fsf-monnier+emacs@HIDDEN> <86mselbsbi.fsf@HIDDEN>
 <jwv1pvx5mtw.fsf-monnier+emacs@HIDDEN> <86h64sbw57.fsf@HIDDEN>
 <jwvzfik398m.fsf-monnier+emacs@HIDDEN> <865xl8blam.fsf@HIDDEN>
 <jwvy0y49w9z.fsf-monnier+emacs@HIDDEN> <86ldu3a18y.fsf@HIDDEN>
 <jwvpljf1jh5.fsf-monnier+emacs@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76313
Cc: 76313 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Stefan Monnier <monnier@HIDDEN>
> Cc: 76313 <at> debbugs.gnu.org
> Date: Tue, 18 Feb 2025 08:30:16 -0500
> 
> >  (replace-buffer-contents SOURCE &optional MAX-SECS MAX-COSTS CHEAP-AND-RECKLESS)
> 
> Hmm... I don't think people will be happy to replace their
> 
>     (insert foo)
>     (delete-region from to)
> 
> with
> 
>     (save-restriction
>       (narrow-to-region from to)
>       (replace-buffer-contents foo nil nil 'cheap))
> 
> Without mentioning that it would be a backward-incompatible change because
> currently `replace-buffer-contents` considers a string argument as the
> name of a buffer.

Then how about reimplementing replace-region-contents in C, and making
a similar change (an additional optional arg) to it instead?

> `replace-region-contents` is a bad API

Why is it bad?




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 18 Feb 2025 13:30:31 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Feb 18 08:30:31 2025
Received: from localhost ([127.0.0.1]:56449 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tkNgF-0002KA-FF
	for submit <at> debbugs.gnu.org; Tue, 18 Feb 2025 08:30:31 -0500
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:65317)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1tkNgB-0002Ho-4o
 for 76313 <at> debbugs.gnu.org; Tue, 18 Feb 2025 08:30:28 -0500
Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 3FD6D441204;
 Tue, 18 Feb 2025 08:30:19 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1739885418;
 bh=N3DxsGMVOyic2rL/UTRlXe3mcxaSaFaY0oz8S6JYlJE=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=Sn+EZy6crAkc7IG2BAXCJIfsosd6AiJ0CKyxwPzpNyyeGTDYhzLgU4hWsQNeO9diV
 vllW1DJT56un8Qp/FbGBrFqyjm+ifwPwgxtBosankOByjt+MyeyN3/m48bneRQzIiw
 mPmwGeScLvpipcnUJHPSRRTHcDl6e0A9f26JhhXnPc3Nr2SoqM2uf+DW9YXDPpBdd0
 dJrOJrCINWdrnAFL6QorsVSyCjUiTBqQeh3gT/BJOl2d2uQeVX+lgUzFZSb3Ly+Fjh
 Z14Mz/0FYwru3pAXahQediMpNy15HOxmrumcdu6T3Phqli10UNeG2JKABqUQPjnlhB
 VKTfrapuzwbTw==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 3954A441054;
 Tue, 18 Feb 2025 08:30:18 -0500 (EST)
Received: from alfajor (unknown [104.247.242.5])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 110C81201BB;
 Tue, 18 Feb 2025 08:30:18 -0500 (EST)
From: Stefan Monnier <monnier@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#76313: New function `replace-region`
In-Reply-To: <86ldu3a18y.fsf@HIDDEN> (Eli Zaretskii's message of "Tue, 18 Feb
 2025 14:25:17 +0200")
Message-ID: <jwvpljf1jh5.fsf-monnier+emacs@HIDDEN>
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86seoecung.fsf@HIDDEN>
 <jwvr03xzuvz.fsf-monnier+emacs@HIDDEN> <86mselbsbi.fsf@HIDDEN>
 <jwv1pvx5mtw.fsf-monnier+emacs@HIDDEN> <86h64sbw57.fsf@HIDDEN>
 <jwvzfik398m.fsf-monnier+emacs@HIDDEN> <865xl8blam.fsf@HIDDEN>
 <jwvy0y49w9z.fsf-monnier+emacs@HIDDEN> <86ldu3a18y.fsf@HIDDEN>
Date: Tue, 18 Feb 2025 08:30:16 -0500
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.676 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76313
Cc: 76313 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

>  (replace-buffer-contents SOURCE &optional MAX-SECS MAX-COSTS CHEAP-AND-RECKLESS)

Hmm... I don't think people will be happy to replace their

    (insert foo)
    (delete-region from to)

with

    (save-restriction
      (narrow-to-region from to)
      (replace-buffer-contents foo nil nil 'cheap))

Without mentioning that it would be a backward-incompatible change because
currently `replace-buffer-contents` considers a string argument as the
name of a buffer.

> where, if CHEAP-AND-RECKLESS is non-nil, we call replace_region
> disregarding what will that do to markers and overlays?  If you want
> to support INHERIT, CHEAP-AND-RECKLESS could be also non-nil and non-t
> to indicate that.

FWIW, `minibuffer--replace` seems to want INHERIT at the same time as
"fancy".  Tho I must admit that I can't remember why I needed
INHERIT there.  Maybe because of insertion in a field?

> I can live with that; at least we stay with the
> same 2 APIs, of which one is implemented on top of the other.

`replace-region-contents` is a bad API (the REPLACE-FN part is a bad
idea, all the callers I could find would be better served if they could
pass a string instead): we should obsolete it.


        Stefan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 18 Feb 2025 13:05:14 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Feb 18 08:05:14 2025
Received: from localhost ([127.0.0.1]:56281 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tkNHm-0008QG-EP
	for submit <at> debbugs.gnu.org; Tue, 18 Feb 2025 08:05:14 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:55084)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tkNHh-0008N1-A6
 for 76313 <at> debbugs.gnu.org; Tue, 18 Feb 2025 08:05:11 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1tkNHb-0004HU-Ll; Tue, 18 Feb 2025 08:05:03 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=iboGCZ7soOThGIrofPfzrwaedNAWhxWXO9NbBiiGYts=; b=N24EivtttDO8
 8uxMljsR195wjYF4cb141/VuCXkG8xLEis/pAZeAK369kQsimeW+Qi5RJQqxWOhsTlw4ST3cXfWGy
 JgnDqYvh+rtoJAt9GhcYKJdXOOC23NUpInyM36Y7/uVLudBrj5Jf7BCUKQbqINaHQIXP6ULfGOPR6
 lS29vGtmp0bP5J/iUS5s0/AoijuEdy4fnxHEdRdDFmMQgiwbum+3/H32zdZUx9XG0Agffq6s6gvTY
 4VG0zbCMyogeS5oUgEt2esNmmaKCVgyZSv90KZfftJxbJQ26JaeNytYXbNdF7cHHPZ+qdioJBSyzH
 N6KttmbGy2c+EtNi0mu39g==;
Date: Tue, 18 Feb 2025 15:04:58 +0200
Message-Id: <86bjuz9zet.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
In-Reply-To: <jwv1pvv3ovs.fsf-monnier+emacs@HIDDEN> (message from Stefan
 Monnier on Mon, 17 Feb 2025 22:38:22 -0500)
Subject: Re: bug#76313: New function `replace-region`
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86seoecung.fsf@HIDDEN>
 <jwvr03xzuvz.fsf-monnier+emacs@HIDDEN> <86mselbsbi.fsf@HIDDEN>
 <jwv1pvx5mtw.fsf-monnier+emacs@HIDDEN> <86h64sbw57.fsf@HIDDEN>
 <jwvzfik398m.fsf-monnier+emacs@HIDDEN> <865xl8blam.fsf@HIDDEN>
 <jwvy0y49w9z.fsf-monnier+emacs@HIDDEN>
 <jwv1pvv3ovs.fsf-monnier+emacs@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76313
Cc: 76313 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Stefan Monnier <monnier@HIDDEN>
> Cc: 76313 <at> debbugs.gnu.org
> Date: Mon, 17 Feb 2025 22:38:22 -0500
> 
> Stefan Monnier [2025-02-17 15:55:04] wrote:
> > I just want a simple function which does the same as
> > `insert+delete-region`, just as efficiently, without having to think
> > about which way is best (should I delete first, or insert first?
> > If I insert first, should I insert at FROM, or at TO, or in the
> > middle?  You can find pretty much all variations out there, several
> > times with comments showing that the coders did have to waste time
> > thinking about it).
> 
> IOW, just like `oddp/evenp` saves coders the trouble of wondering
> whether to implement it using `%` or `logand` or whatnot.

Assuming that people will know what is "odd" and what is "even" better
and easier than they know their mathematical definitions...




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 18 Feb 2025 12:25:33 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Feb 18 07:25:33 2025
Received: from localhost ([127.0.0.1]:55994 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tkMfM-0001le-PK
	for submit <at> debbugs.gnu.org; Tue, 18 Feb 2025 07:25:33 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:42760)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tkMfI-0001l3-Ni
 for 76313 <at> debbugs.gnu.org; Tue, 18 Feb 2025 07:25:29 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1tkMfB-0005w8-7y; Tue, 18 Feb 2025 07:25:21 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=SkdPFHAXle+QzBI73CKTi5FO2LEi7lMMnbiJMAaVqnU=; b=RdH9H22+mGPC
 rXYu/LBIVfWUe5KzZ3L8feDeshg9wqCcgPS2HaRE8F3P9UNErYKCsvzTxWoeIPKRJK03AxWofWhOp
 FKdCygaUNsRzSCrsLB9luemrbAeUb7fggFPAXMXOIRM/I1g+Uf710MGBi1jQ+pFP7DXdaRXWqtSwc
 AdBGHiRaoKz7WQUaqcee+p8jvSx91sKaOzO5H4X1dshssLgVoADkYzlOgOm6+jOMARLK1LgXsgIbL
 mMognBzNI8Rg6HIRzKMNpNvFZpM3HmBcqSVgnQxK+4B1R4QowULnNT2uPaQpfw0D8AVzU1NWHZ94I
 8foKvRiU5F0v9qUCW5hD1w==;
Date: Tue, 18 Feb 2025 14:25:17 +0200
Message-Id: <86ldu3a18y.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
In-Reply-To: <jwvy0y49w9z.fsf-monnier+emacs@HIDDEN> (message from Stefan
 Monnier on Mon, 17 Feb 2025 15:55:04 -0500)
Subject: Re: bug#76313: New function `replace-region`
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86seoecung.fsf@HIDDEN>
 <jwvr03xzuvz.fsf-monnier+emacs@HIDDEN> <86mselbsbi.fsf@HIDDEN>
 <jwv1pvx5mtw.fsf-monnier+emacs@HIDDEN> <86h64sbw57.fsf@HIDDEN>
 <jwvzfik398m.fsf-monnier+emacs@HIDDEN> <865xl8blam.fsf@HIDDEN>
 <jwvy0y49w9z.fsf-monnier+emacs@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76313
Cc: 76313 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Stefan Monnier <monnier@HIDDEN>
> Cc: 76313 <at> debbugs.gnu.org
> Date: Mon, 17 Feb 2025 15:55:04 -0500
> 
> >> So does that mean you're OK with my new `replace-region`, and that
> >> I should open a new bug-report with a proposal for how to merge
> >> `replace-region-contents` and `replace-buffer-contents`?
> >> 
> >> Or something else?
> >
> > You suggested to merge replace-region-contents with
> > replace-buffer-contents when replace-region was not on the table at
> > all.  I'm still not sure we want a 3rd API for this purpose.
> 
> I just want a simple function which does the same as
> `insert+delete-region`, just as efficiently, without having to think
> about which way is best (should I delete first, or insert first?
> If I insert first, should I insert at FROM, or at TO, or in the
> middle?  You can find pretty much all variations out there, several
> times with comments showing that the coders did have to waste time
> thinking about it).

How come we never needed it until now, even though insdel.c can
replace buffer text since day one?  And are you sure that the way you
implement it by calling replace_region, this will produce exactly the
variation that everyone wants?

I thought at some point you suggested allowing to extend the
REPLACE-FN argument of replace-region-contents to be a string, and I
agreed to that (had the same idea, actually, while reading your OP).
But now you are going back to basically your original proposal? why?

> `replace-buffer/region-contents` is not a valid answer because it's
> a lot more costly.  Do you want me to merge them all into a single
> monster `replace-region` function and mark the other two as obsolete:

No, but how about

 (replace-buffer-contents SOURCE &optional MAX-SECS MAX-COSTS CHEAP-AND-RECKLESS)

where, if CHEAP-AND-RECKLESS is non-nil, we call replace_region
disregarding what will that do to markers and overlays?  If you want
to support INHERIT, CHEAP-AND-RECKLESS could be also non-nil and non-t
to indicate that.  I can live with that; at least we stay with the
same 2 APIs, of which one is implemented on top of the other.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 18 Feb 2025 03:38:35 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Feb 17 22:38:34 2025
Received: from localhost ([127.0.0.1]:52524 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tkERO-00020b-JL
	for submit <at> debbugs.gnu.org; Mon, 17 Feb 2025 22:38:34 -0500
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:17618)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1tkERK-000204-Hj
 for 76313 <at> debbugs.gnu.org; Mon, 17 Feb 2025 22:38:33 -0500
Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 45BB2100040;
 Mon, 17 Feb 2025 22:38:23 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1739849902;
 bh=1DmWmsq7t0sC+2JMd5q+sbg4Wj/p73EORpKWCMdquXA=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=OeRXv1C/emSx2uRBWW+mGXQyJbSmRDWvilcwvezCOtMpTvxObEAHEUKmcI5PoDZCA
 VWsawcs7NItLYCvixQQC3Q1+tyipHebnixzyL1OOeVL5MgPBzPtweFCnQx0H3L+ui5
 JpCeUUvCs+lAfd8v9kCpfSI3IxdiBj8XcQ4hMFkXITWgcfJ96aYNu6vwXWz660NNb3
 ogw5QWaDbMZK7MM9rW2EJNASAY4quE65QMhnqveW9OZ9sTDzpjhFvFEkh6ALgnHLv6
 Yr384twz7xukyR3HiIcBK9befQfalkPkxZgNHOB/vD1tkWDCc4QBuw7oiICdfaYJUp
 9QBDkKtmyoi/Q==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 76A2A10002E;
 Mon, 17 Feb 2025 22:38:22 -0500 (EST)
Received: from alfajor (unknown [104.247.242.5])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 506B21204A7;
 Mon, 17 Feb 2025 22:38:22 -0500 (EST)
From: Stefan Monnier <monnier@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#76313: New function `replace-region`
In-Reply-To: <jwvy0y49w9z.fsf-monnier+emacs@HIDDEN> (Stefan Monnier's message
 of "Mon, 17 Feb 2025 15:55:04 -0500")
Message-ID: <jwv1pvv3ovs.fsf-monnier+emacs@HIDDEN>
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86seoecung.fsf@HIDDEN>
 <jwvr03xzuvz.fsf-monnier+emacs@HIDDEN> <86mselbsbi.fsf@HIDDEN>
 <jwv1pvx5mtw.fsf-monnier+emacs@HIDDEN> <86h64sbw57.fsf@HIDDEN>
 <jwvzfik398m.fsf-monnier+emacs@HIDDEN> <865xl8blam.fsf@HIDDEN>
 <jwvy0y49w9z.fsf-monnier+emacs@HIDDEN>
Date: Mon, 17 Feb 2025 22:38:22 -0500
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.164 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76313
Cc: 76313 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Stefan Monnier [2025-02-17 15:55:04] wrote:
> I just want a simple function which does the same as
> `insert+delete-region`, just as efficiently, without having to think
> about which way is best (should I delete first, or insert first?
> If I insert first, should I insert at FROM, or at TO, or in the
> middle?  You can find pretty much all variations out there, several
> times with comments showing that the coders did have to waste time
> thinking about it).

IOW, just like `oddp/evenp` saves coders the trouble of wondering
whether to implement it using `%` or `logand` or whatnot.


        Stefan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 17 Feb 2025 20:55:16 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Feb 17 15:55:16 2025
Received: from localhost ([127.0.0.1]:49991 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tk896-00085M-9o
	for submit <at> debbugs.gnu.org; Mon, 17 Feb 2025 15:55:16 -0500
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:11753)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1tk891-00080J-3s
 for 76313 <at> debbugs.gnu.org; Mon, 17 Feb 2025 15:55:14 -0500
Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 8EA2C100066;
 Mon, 17 Feb 2025 15:55:05 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1739825704;
 bh=WBUtc4eoXEkzUmkWVKo+15LFeJG0eKuWlZkDv3MI8K8=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=L4eE95JABZG4yjViIFRMrvbUk+AJC9/+i/dQYnzrh+2/JaAz8HVoNVt09tWq/vkz4
 SQp6acpBcyO96sTe9Pr9tH3pcYB1/S7Pi2h/ajpgBq8pd8E6k1+sDvBeObeFTb3hqG
 peU9QQ92bIrFY1ZG2bbaVxsi5wRi74gWjs3AkWLOAtib7bpjwC0HFPsYiPWc7yO52K
 2jRnQeouYzu3H093pyXASCkFv9zfpPEs927NiWgMtGf5b6IqV+L8tqcA6XWDnmKb40
 NDm3Iw4EVgqOIx1iU/eCgrvwyLZUxvKBC5kaALWS8d8UdBDAxjeDlBWzZQS5u4kmfX
 UkG7ZPrImZmlQ==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id D6FD7100035;
 Mon, 17 Feb 2025 15:55:04 -0500 (EST)
Received: from lechazo (lechon.iro.umontreal.ca [132.204.27.242])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id BAACF120401;
 Mon, 17 Feb 2025 15:55:04 -0500 (EST)
From: Stefan Monnier <monnier@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#76313: New function `replace-region`
In-Reply-To: <865xl8blam.fsf@HIDDEN> (Eli Zaretskii's message of "Mon, 17 Feb
 2025 18:14:41 +0200")
Message-ID: <jwvy0y49w9z.fsf-monnier+emacs@HIDDEN>
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86seoecung.fsf@HIDDEN>
 <jwvr03xzuvz.fsf-monnier+emacs@HIDDEN> <86mselbsbi.fsf@HIDDEN>
 <jwv1pvx5mtw.fsf-monnier+emacs@HIDDEN> <86h64sbw57.fsf@HIDDEN>
 <jwvzfik398m.fsf-monnier+emacs@HIDDEN> <865xl8blam.fsf@HIDDEN>
Date: Mon, 17 Feb 2025 15:55:04 -0500
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL 0.055 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76313
Cc: 76313 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

>> So does that mean you're OK with my new `replace-region`, and that
>> I should open a new bug-report with a proposal for how to merge
>> `replace-region-contents` and `replace-buffer-contents`?
>> 
>> Or something else?
>
> You suggested to merge replace-region-contents with
> replace-buffer-contents when replace-region was not on the table at
> all.  I'm still not sure we want a 3rd API for this purpose.

I just want a simple function which does the same as
`insert+delete-region`, just as efficiently, without having to think
about which way is best (should I delete first, or insert first?
If I insert first, should I insert at FROM, or at TO, or in the
middle?  You can find pretty much all variations out there, several
times with comments showing that the coders did have to waste time
thinking about it).

`replace-buffer/region-contents` is not a valid answer because it's
a lot more costly.  Do you want me to merge them all into a single
monster `replace-region` function and mark the other two as obsolete:

    (replace-region FROM TO REPLACEMENT &optional INHERIT CAREFULLY)

- REPLACEMENT can be a string or a buffer object (not a buffer name!).
  I'd drop support for `replace-region-contents`s function
  because one can just as easily run the function before calling
  `replace-region(-contents)` (which may also save us from building
  a closure).
-  INHERIT would specify whether to "insert-and-inherit" (used by
  `minibuffer--replace`).
- CAREFULLY if non-nil requests a costly replacement which minimizes
  impact on markers and such.  It can be a symbol or a list (MAX-SECS
  MAX-COSTS), tho I hate that ill-defined MAX-COSTS thingy, so if we
  could replace it with something better defined that would be sweet.
- I'd make it return nil since it seems that the return value of
  `replace-buffer-contents` is not used anywhere (well, except in
  `files-tests-revert-buffer-with-fine-grain` where we could replace it
  with a test that some marker was indeed properly preserved rather
  than blindly believing the return value of `revert-buffer-with-fine-grain`).

I can do that.


        Stefan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 17 Feb 2025 16:14:52 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Feb 17 11:14:52 2025
Received: from localhost ([127.0.0.1]:47995 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tk3lk-0001NL-2O
	for submit <at> debbugs.gnu.org; Mon, 17 Feb 2025 11:14:52 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:41706)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tk3lh-0001N4-MU
 for 76313 <at> debbugs.gnu.org; Mon, 17 Feb 2025 11:14:50 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1tk3lb-00035C-FP; Mon, 17 Feb 2025 11:14:43 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=bUQrvd7OMrTOOZL6FrhmfZoVPvpKIbMLzteCxnS5hMA=; b=LNfkf+XYnABo
 Wwbo8a/2nki0mHmU84gPOi/dTW5NVbMiAgAN3jzC2f86XDxMDiwf4Ow2ZeQrqaNFXaInnmmtgraUf
 6U6I8PpaqnILUinvh8Q2bVwHtXJouBBGnWPGjeSLh6IM4S5axGpITyjojycnGM46y8dMVCdtKOR/x
 8H4j3rTnZ0Q154yfggmwZXtpmxLZ7scZfEs6qUPSFIAO6prcASRLWolAzZFvNcTZ/pqMBNEPgjbYp
 5m7Yy+2BkkNmhjNr2NfKqx0Ho9v5sL4vZOZ9eS07Mw1skwPgFOLRG/LFXRCHThTxeiyIupG/8z82z
 HNih2deZuIfyJPt04Qup7Q==;
Date: Mon, 17 Feb 2025 18:14:41 +0200
Message-Id: <865xl8blam.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
In-Reply-To: <jwvzfik398m.fsf-monnier+emacs@HIDDEN> (message from Stefan
 Monnier on Mon, 17 Feb 2025 10:03:26 -0500)
Subject: Re: bug#76313: New function `replace-region`
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86seoecung.fsf@HIDDEN>
 <jwvr03xzuvz.fsf-monnier+emacs@HIDDEN> <86mselbsbi.fsf@HIDDEN>
 <jwv1pvx5mtw.fsf-monnier+emacs@HIDDEN> <86h64sbw57.fsf@HIDDEN>
 <jwvzfik398m.fsf-monnier+emacs@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76313
Cc: 76313 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Stefan Monnier <monnier@HIDDEN>
> Cc: 76313 <at> debbugs.gnu.org
> Date: Mon, 17 Feb 2025 10:03:26 -0500
> 
> >> >> I'm not sure it'd be a good idea, tho: `replace-region-contents` is
> >> >> a "heavy" operation, involving narrowing and another buffer, whereas
> >> >> `replace-region` is meant to be a low-level operation (if we implement
> >> >> it in C, we could arguably use it as *the* low-level operation and
> >> >> define `insert` and `delete-region` on top of it).
> >> >
> >> > On the downside, we already have 2 APIs for this, so having a 3rd one
> >> > will only make the confusion more prominent.
> >> 
> >> We could start by merging `replace-region-contents` and
> >> `replace-buffer-contents`.
> >
> > Fine by me, thanks.
> 
> So does that mean you're OK with my new `replace-region`, and that
> I should open a new bug-report with a proposal for how to merge
> `replace-region-contents` and `replace-buffer-contents`?
> 
> Or something else?

You suggested to merge replace-region-contents with
replace-buffer-contents when replace-region was not on the table at
all.  I'm still not sure we want a 3rd API for this purpose.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 17 Feb 2025 15:03:39 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Feb 17 10:03:39 2025
Received: from localhost ([127.0.0.1]:47520 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tk2ep-0004Ng-3W
	for submit <at> debbugs.gnu.org; Mon, 17 Feb 2025 10:03:39 -0500
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:57131)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1tk2ek-0004N1-AR
 for 76313 <at> debbugs.gnu.org; Mon, 17 Feb 2025 10:03:36 -0500
Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 4ACAD441554;
 Mon, 17 Feb 2025 10:03:28 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1739804607;
 bh=xZRgDDfynT2TsCLsZDKSlD27D9IwZY2JSIzbbVFYn5s=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=h+tZyNZ+iBrp7G/nTnFmBfyXmn1LoLW962ZzdSCzXFM5JAD3jECjSjErg52IUTlUE
 OGq/enCHvkiax372Oi/zfCIa61h/XM2ThsgoiDtd4vSKqrkcJYgo1TDHmryLSnSzk9
 siLK25nE9Aq2fYUAv0qj11SKzopCQSVMgYd+iNfjx47j0CMvVfyqzgcjYowlV6/u6W
 86i31jIB3OJJHObBPLoBjTeS+EexKNaRHR+88hTwb7S7p9YcGnlruasTX6D+Aa+bdq
 Gt+wCuhPo1V/C51/fCKGAycjuDn4ygKsru7K07vE1nWR4B02cPP7kjHmx7TNZ0aW0o
 5jIQ6qGeL8TyQ==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 4A1C44414DC;
 Mon, 17 Feb 2025 10:03:27 -0500 (EST)
Received: from alfajor (unknown [104.247.242.5])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 231781202F7;
 Mon, 17 Feb 2025 10:03:27 -0500 (EST)
From: Stefan Monnier <monnier@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#76313: New function `replace-region`
In-Reply-To: <86h64sbw57.fsf@HIDDEN> (Eli Zaretskii's message of "Mon, 17 Feb
 2025 14:20:20 +0200")
Message-ID: <jwvzfik398m.fsf-monnier+emacs@HIDDEN>
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86seoecung.fsf@HIDDEN>
 <jwvr03xzuvz.fsf-monnier+emacs@HIDDEN> <86mselbsbi.fsf@HIDDEN>
 <jwv1pvx5mtw.fsf-monnier+emacs@HIDDEN> <86h64sbw57.fsf@HIDDEN>
Date: Mon, 17 Feb 2025 10:03:26 -0500
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.685 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76313
Cc: 76313 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

>> >> I'm not sure it'd be a good idea, tho: `replace-region-contents` is
>> >> a "heavy" operation, involving narrowing and another buffer, whereas
>> >> `replace-region` is meant to be a low-level operation (if we implement
>> >> it in C, we could arguably use it as *the* low-level operation and
>> >> define `insert` and `delete-region` on top of it).
>> >
>> > On the downside, we already have 2 APIs for this, so having a 3rd one
>> > will only make the confusion more prominent.
>> 
>> We could start by merging `replace-region-contents` and
>> `replace-buffer-contents`.
>
> Fine by me, thanks.

So does that mean you're OK with my new `replace-region`, and that
I should open a new bug-report with a proposal for how to merge
`replace-region-contents` and `replace-buffer-contents`?

Or something else?


        Stefan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 17 Feb 2025 12:20:34 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Feb 17 07:20:34 2025
Received: from localhost ([127.0.0.1]:44199 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tk070-0004W5-7y
	for submit <at> debbugs.gnu.org; Mon, 17 Feb 2025 07:20:34 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:59408)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tk06y-0004VW-3h
 for 76313 <at> debbugs.gnu.org; Mon, 17 Feb 2025 07:20:32 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1tk06r-0005xJ-BG; Mon, 17 Feb 2025 07:20:25 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=RW6V+EKKolZgpHfXdlchg1DS7j1mng7Xcc7MMOYB8E0=; b=ILMwPukxAzJ5
 hB6rXFyNhL/Z4/8xw/k0mdYyOVAtbaPZkbm7JO7/MhFZLOKtKqcnMIPEMjqA78x2EmSF4/XxWfU9i
 WyApjg9WJGk9Xm+41lDu0cVFDiHi8dbXuMU11ow4HOhijm8/24RKkt1K5mFZ596+kemsGHa/N9LdL
 U1IHmdBCfWbMBtteMhz9Ese+n9mRG2lpmPn4pQRrpsAa+qxQGHhk0dBQsmiklc814SLEgNadBMeYK
 3X5mzVZfbcdw/nShFDi8sFYG9NSSwsz5xR8eulBbFBKNA9TWLasXcnkbx0kVQu4bgX0KO72+BdXXP
 WGH6udWImzNZw/WTqjyawQ==;
Date: Mon, 17 Feb 2025 14:20:20 +0200
Message-Id: <86h64sbw57.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
In-Reply-To: <jwv1pvx5mtw.fsf-monnier+emacs@HIDDEN> (message from Stefan
 Monnier on Sun, 16 Feb 2025 21:45:03 -0500)
Subject: Re: bug#76313: New function `replace-region`
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86seoecung.fsf@HIDDEN>
 <jwvr03xzuvz.fsf-monnier+emacs@HIDDEN> <86mselbsbi.fsf@HIDDEN>
 <jwv1pvx5mtw.fsf-monnier+emacs@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76313
Cc: 76313 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Stefan Monnier <monnier@HIDDEN>
> Cc: 76313 <at> debbugs.gnu.org
> Date: Sun, 16 Feb 2025 21:45:03 -0500
> 
> >> I'm not sure it'd be a good idea, tho: `replace-region-contents` is
> >> a "heavy" operation, involving narrowing and another buffer, whereas
> >> `replace-region` is meant to be a low-level operation (if we implement
> >> it in C, we could arguably use it as *the* low-level operation and
> >> define `insert` and `delete-region` on top of it).
> >
> > On the downside, we already have 2 APIs for this, so having a 3rd one
> > will only make the confusion more prominent.
> 
> We could start by merging `replace-region-contents` and
> `replace-buffer-contents`.

Fine by me, thanks.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 17 Feb 2025 04:37:10 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Feb 16 23:37:10 2025
Received: from localhost ([127.0.0.1]:40794 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tjssX-00065d-TZ
	for submit <at> debbugs.gnu.org; Sun, 16 Feb 2025 23:37:10 -0500
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:32258)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1tjssT-00064K-Uj
 for 76313 <at> debbugs.gnu.org; Sun, 16 Feb 2025 23:37:07 -0500
Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id C1525100154;
 Sun, 16 Feb 2025 23:36:59 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1739767018;
 bh=L+UKXx8hXhoyk8YooGErTN9CYtQDkNSTr+DAYBYSZCA=;
 h=From:To:Subject:In-Reply-To:References:Date:From;
 b=XdfiaE3LT3ESWOzNTbOMODez8dkRCt/5F5M/TQ0pvHMDM9uiNCM+0HYosmv+Z3+hg
 UrwH/3jRb13fMfliBHlZ3TtHF8jwuRZBCKa1TeM50WIpavaePcVHL/wuBwaEh7mu7P
 NQCQn/RGCv3OHuLIMNfrX1lv6tGWaLXa876F2sxVH/ZDC1IPf166cxTrUMuViPlpfA
 3o6IPZ7UGZ9BCtFDx9SlmJ+J6kpJw4IW8dsEcIRWI0c/3At9VtL0dFQPnfXSvH3br7
 MSjCJUDx+Eta3jVFQNwaAe1wYdr6dO+QZXGR98aISH/3Y8g9/h9SvEe4+2hFmrt/Bw
 EKKFFbi8K4wpA==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id D0991100034;
 Sun, 16 Feb 2025 23:36:58 -0500 (EST)
Received: from alfajor (unknown [104.247.242.5])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id ACA981202CB;
 Sun, 16 Feb 2025 23:36:58 -0500 (EST)
From: Stefan Monnier <monnier@HIDDEN>
To: 76313 <at> debbugs.gnu.org
Subject: Re: bug#76313: New function `replace-region`
In-Reply-To: <jwv4j0u50tn.fsf-monnier+@gnu.org> (Stefan Monnier's message of
 "Sat, 15 Feb 2025 17:18:15 -0500")
Message-ID: <jwvo6z142dx.fsf-monnier+emacs@HIDDEN>
References: <jwv4j0u50tn.fsf-monnier+@gnu.org>
Date: Sun, 16 Feb 2025 23:36:57 -0500
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.097 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76313
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

--=-=-=
Content-Type: text/plain

> So I suggest the patch below.  Comments?  Objections?

Here's a better implementation, in C.
One advantage is that it runs the `after/before-change-functions` only once.
Also, I made it take an optional `inherit` argument so it can do the
same as `insert-and-inherit` (as is used in `minibuffer--replace`).
This version does not move point to the end of the new text.


        Stefan

--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline; filename=replace-region.patch

diff --git a/src/editfns.c b/src/editfns.c
index f9258392146..c86d0b890a2 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -2654,6 +2654,22 @@ DEFUN ("delete-and-extract-region", Fdelete_and_extract_region,
     return empty_unibyte_string;
   return del_range_1 (XFIXNUM (start), XFIXNUM (end), 1, 1);
 }
+
+DEFUN ("replace-region", Freplace_region, Sreplace_region, 3, 4, 0,
+       doc: /* Replace region FROM..TO with STRING.
+Does not move point, like `delete-region' but unlike `insert'.
+If optional arg INHERIT, then text properties are inherited from
+context like `insert-and-inherit'.  */)
+  (Lisp_Object from, Lisp_Object to, Lisp_Object string, Lisp_Object inherit)
+{
+  validate_region (&from, &to);
+  CHECK_STRING (string);
+  /* SET_PT (XFIXNUM (to)); */
+  replace_range (XFIXNUM (from), XFIXNUM (to), string,
+		 /* FIXME: Should we update search regs?  */
+		 true, !NILP (inherit), true, false, false);
+  return Qnil;
+}
 
 /* Alist of buffers in which labeled restrictions are used.  The car
    of each list element is a buffer, the cdr is a list of triplets
@@ -4929,6 +4945,7 @@ syms_of_editfns (void)
   defsubr (&Stranslate_region_internal);
   defsubr (&Sdelete_region);
   defsubr (&Sdelete_and_extract_region);
+  defsubr (&Sreplace_region);
   defsubr (&Swiden);
   defsubr (&Snarrow_to_region);
   defsubr (&Sinternal__labeled_narrow_to_region);
diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el
index 8d4e7bc48fa..1b0fe30f8ce 100644
--- a/test/src/editfns-tests.el
+++ b/test/src/editfns-tests.el
@@ -305,6 +305,29 @@ replace-buffer-contents-bug31837
   (should (equal (buffer-substring-no-properties (point-min) (point-max))
                  (concat (string (char-from-name "SMILE")) "1234"))))
 
+(ert-deftest editfns-tests--replace-region ()
+  (with-temp-buffer
+    (insert "here is some text")
+    (let ((m5n (copy-marker (+ (point-min) 5)))
+          (m5a (copy-marker (+ (point-min) 5) t))
+          (m6n (copy-marker (+ (point-min) 6)))
+          (m6a (copy-marker (+ (point-min) 6) t))
+          (m7n (copy-marker (+ (point-min) 7)))
+          (m7a (copy-marker (+ (point-min) 7) t)))
+      (replace-region (+ (point-min) 5) (+ (point-min) 7) "was")
+      (should (equal (buffer-string) "here was some text"))
+      (should (equal (point) (point-max)))
+      ;; Markers before the replaced text stay before.
+      (should (= m5n (+ (point-min) 5)))
+      (should (= m5a (+ (point-min) 5)))
+      ;; Markers in the replaced text can end up at either end, depending
+      ;; on whether they're advance-after-insert or not.
+      (should (= m6n (+ (point-min) 5)))
+      (should (<= (+ (point-min) 5) m6a (+ (point-min) 8)))
+      ;; Markers after the replaced text stay after.
+      (should (= m7n (+ (point-min) 8)))
+      (should (= m7a (+ (point-min) 8))))))
+
 (ert-deftest delete-region-undo-markers-1 ()
   "Make sure we don't end up with freed markers reachable from Lisp."
   ;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=30931#40

--=-=-=--





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 17 Feb 2025 02:45:21 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Feb 16 21:45:21 2025
Received: from localhost ([127.0.0.1]:40238 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tjr8K-0005ZH-50
	for submit <at> debbugs.gnu.org; Sun, 16 Feb 2025 21:45:20 -0500
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:22375)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1tjr8B-0005T2-7V
 for 76313 <at> debbugs.gnu.org; Sun, 16 Feb 2025 21:45:17 -0500
Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 2B091100154;
 Sun, 16 Feb 2025 21:45:05 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1739760304;
 bh=20AYmCTrmjzeJc4qEuEG2JPsnZWZlaVnONoIhbh1qxk=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=dbZph9X0CTfPf7zkC2QUGHVVBLBLXmxbY8G8fP/XMKkEkRJgLUQPlFPcs0raMogC+
 aAg+xbI3b5dd8qFAim2XraziVcDwQjlLXuvv/KLhdchwdgpMBMRAzfrneuPQW8hhAE
 tr1mEVZfmN3nx6iR74nLXakOYEp/PEueRZ9AIRHJED//6CuZjOvtW4JaXqJct0WJgF
 a3M+qOqKdRQLj0nzuJIIkMA1PZqpoyPM3Yq+1pJvwAF/S9QJqOr3y3XYUN3JOIlegn
 YXXqEnNGs3P5nFaA+prcgL2sS6FDebSyfyrDLXjJHkCgw1/cUsyW+GQnucvz0H2gcc
 ysr/xK1c0M1Ag==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 67965100034;
 Sun, 16 Feb 2025 21:45:04 -0500 (EST)
Received: from alfajor (unknown [104.247.242.5])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 3DF5D1203D7;
 Sun, 16 Feb 2025 21:45:04 -0500 (EST)
From: Stefan Monnier <monnier@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#76313: New function `replace-region`
In-Reply-To: <86mselbsbi.fsf@HIDDEN> (Eli Zaretskii's message of "Sun, 16 Feb
 2025 21:30:41 +0200")
Message-ID: <jwv1pvx5mtw.fsf-monnier+emacs@HIDDEN>
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86seoecung.fsf@HIDDEN>
 <jwvr03xzuvz.fsf-monnier+emacs@HIDDEN> <86mselbsbi.fsf@HIDDEN>
Date: Sun, 16 Feb 2025 21:45:03 -0500
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.111 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76313
Cc: 76313 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

>> I'm not sure it'd be a good idea, tho: `replace-region-contents` is
>> a "heavy" operation, involving narrowing and another buffer, whereas
>> `replace-region` is meant to be a low-level operation (if we implement
>> it in C, we could arguably use it as *the* low-level operation and
>> define `insert` and `delete-region` on top of it).
>
> On the downside, we already have 2 APIs for this, so having a 3rd one
> will only make the confusion more prominent.

We could start by merging `replace-region-contents` and
`replace-buffer-contents`.
[ We should also improve their docstrings to give some hint about what
  kind of "diff" they're able to find.  E.g. do they use char/word/line
  granularity?  ]

> Who, apart of you and maybe me, will know or remember that those two
> are "heavy" whereas the 3rd one isn't,

Indeed, their name should be upfront about it.
I'd have expected a name like `replace-region-carefully`.

> And how to apply that knowledge to any concrete use case?

Apparently current callers don't have much difficulty choosing between
insert+delete-region and `replace-region-contents`, so I'm not
too worried.
I think the complexity of the API described in the docstring does the
trick to make sure people use the more expensive ones only when they
care enough about the difference.

> Also, if someone wants a "simple" implementation that doesn't care
> about being destructive and clobbering markers, properties, etc., why
> can't they indeed do the delete-region + insert dance?

They can.  But using the new `replace-region` is simpler for them, with
the side benefit that it will behave (slightly) better.
That's kind of the point of `replace-region`: to be a no-brainer
replacement for insert+delete-region.


        Stefan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 16 Feb 2025 19:30:54 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Feb 16 14:30:54 2025
Received: from localhost ([127.0.0.1]:37608 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tjkLt-0001eb-Oo
	for submit <at> debbugs.gnu.org; Sun, 16 Feb 2025 14:30:54 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:53472)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tjkLq-0001eA-Rr
 for 76313 <at> debbugs.gnu.org; Sun, 16 Feb 2025 14:30:51 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1tjkLk-0008H6-Uw; Sun, 16 Feb 2025 14:30:44 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=UFwqqh6XhSHvAksf7bvNv32ckzoINK6EH41dRVwVIjw=; b=GpXp9RPhWnGW
 /lhsSkSyRCccl8GGtTgkjLa18ftU70lQJ5LKYpA4Q6eSG7V9R74+br0lqQmVu9CMQC9oiZzgX0HGr
 8zTPHmNhcj+OlOexHZp2pbXZbDpV2x8UKN/i0M2pxJ0fFVvP5WOHR3aqSLTc00ekIAtCwFNH8X3ux
 9IV6Dbdie8m+uaDZYlL/Ai0H8WoB5jFp8POzXR1+jap9Q+ZDkaSn7a6RIxWgZhcFGOkO9KwyFYmDv
 nSMA2t1h46EXsWeEJcin5cc8XZLYUVFzt+aOMiQhw8+o8G/YKKH0R1sDcX04Y8DQs/mvr36mYVUwn
 YUurFv0gcD0noh17TtTgmA==;
Date: Sun, 16 Feb 2025 21:30:41 +0200
Message-Id: <86mselbsbi.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
In-Reply-To: <jwvr03xzuvz.fsf-monnier+emacs@HIDDEN> (message from Stefan
 Monnier on Sun, 16 Feb 2025 12:17:04 -0500)
Subject: Re: bug#76313: New function `replace-region`
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86seoecung.fsf@HIDDEN>
 <jwvr03xzuvz.fsf-monnier+emacs@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76313
Cc: 76313 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Stefan Monnier <monnier@HIDDEN>
> Cc: 76313 <at> debbugs.gnu.org
> Date: Sun, 16 Feb 2025 12:17:04 -0500
> 
> >> So I suggest the patch below.  Comments?  Objections?
> > What's wrong with replace-buffer-contents or replace-region-contents?
> 
> Yeah, I'm not super happy about that situation, but here are my reasons:
> 
> - On the API side: They're inconvenient replacements because they require
>   either changing the narrowing or wrapping the replacement string into
>   a closure.  Not the end of the world, but AFAICT, `replace-region` is
>   a quite common operation (the patch I sent only replaces a couple of
>   use-cases, but I know there are much more).
> 
> - On the implementation side: They are significantly more expensive (fancier).
> 
> Maybe we should merge some of them.  E.g. we could merge my
> proposed `replace-region` with `replace-region-contents` as follow:
> 
> - Allow REPLACE-FN to be a string rather than a function.

I immediately thought of this extension when I saw your proposal.

> I'm not sure it'd be a good idea, tho: `replace-region-contents` is
> a "heavy" operation, involving narrowing and another buffer, whereas
> `replace-region` is meant to be a low-level operation (if we implement
> it in C, we could arguably use it as *the* low-level operation and
> define `insert` and `delete-region` on top of it).

On the downside, we already have 2 APIs for this, so having a 3rd one
will only make the confusion more prominent.  Who, apart of you and
maybe me, will know or remember that those two are "heavy" whereas the
3rd one isn't, especially given that replace-buffer-contents is
implemented in C?  And how to apply that knowledge to any concrete use
case?

Also, if someone wants a "simple" implementation that doesn't care
about being destructive and clobbering markers, properties, etc., why
can't they indeed do the delete-region + insert dance?




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 16 Feb 2025 17:17:18 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Feb 16 12:17:18 2025
Received: from localhost ([127.0.0.1]:36711 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tjiGc-0004h3-3b
	for submit <at> debbugs.gnu.org; Sun, 16 Feb 2025 12:17:18 -0500
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:39791)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1tjiGW-0004gE-DM
 for 76313 <at> debbugs.gnu.org; Sun, 16 Feb 2025 12:17:16 -0500
Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id B06BF808F0;
 Sun, 16 Feb 2025 12:17:06 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1739726225;
 bh=bCDf2WTPjHjpKDAZcl3drpM84Elsb9/BUp03F7XtpKA=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=MwXsaMrbKZoA357wZyMRncqXctDgDarQG8XVXzgWREIOhQQQO9vtXsJWLKj9dANj7
 fxaPEnWjhMVP9LBeLMWTA0oBGx2XzLk/Pu8Tn41C/Mn91DcjPJePnPsRWItZqTVBAP
 NZ9y5rJoyT0VKRwZnaTJR/G6lKNKHRJEj1+zpkUQ9HEgQ0qGZsj3pmQyrPiuI+v8o1
 T3aG5uKEfpoxaGmw4bjNRPov1ENKTX66pPU8JSlBSWnWL8LYVPPJSdq7KaMl2Cx7F6
 7oJcITybN/bAqnKNZtvawPiU+Pr17K/HHqlAXYjoH4YvQT78gNK7uiAqSLDiCJ5pxc
 pglVubLQpB7lw==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id E641E801F6;
 Sun, 16 Feb 2025 12:17:05 -0500 (EST)
Received: from pastel (unknown [104.247.242.5])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id BE932120384;
 Sun, 16 Feb 2025 12:17:05 -0500 (EST)
From: Stefan Monnier <monnier@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#76313: New function `replace-region`
In-Reply-To: <86seoecung.fsf@HIDDEN> (Eli Zaretskii's message of "Sun, 16 Feb
 2025 07:42:43 +0200")
Message-ID: <jwvr03xzuvz.fsf-monnier+emacs@HIDDEN>
References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <86seoecung.fsf@HIDDEN>
Date: Sun, 16 Feb 2025 12:17:04 -0500
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.009 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76313
Cc: 76313 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

>> So I suggest the patch below.  Comments?  Objections?
> What's wrong with replace-buffer-contents or replace-region-contents?

Yeah, I'm not super happy about that situation, but here are my reasons:

- On the API side: They're inconvenient replacements because they require
  either changing the narrowing or wrapping the replacement string into
  a closure.  Not the end of the world, but AFAICT, `replace-region` is
  a quite common operation (the patch I sent only replaces a couple of
  use-cases, but I know there are much more).

- On the implementation side: They are significantly more expensive (fancier).

Maybe we should merge some of them.  E.g. we could merge my
proposed `replace-region` with `replace-region-contents` as follow:

- Allow REPLACE-FN to be a string rather than a function.
- If MAX-SECS/COSTS are both nil, then use the cheap implementation.
  I.e. only do the fancy diffing when one of MAX-SECS/COSTS is specified
  (could allow a `t` value to mean "do it the fancy way with default
  settings").

I'm not sure it'd be a good idea, tho: `replace-region-contents` is
a "heavy" operation, involving narrowing and another buffer, whereas
`replace-region` is meant to be a low-level operation (if we implement
it in C, we could arguably use it as *the* low-level operation and
define `insert` and `delete-region` on top of it).


        Stefan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at 76313 <at> debbugs.gnu.org:


Received: (at 76313) by debbugs.gnu.org; 16 Feb 2025 05:42:58 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Feb 16 00:42:58 2025
Received: from localhost ([127.0.0.1]:59490 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tjXQg-0004r3-CX
	for submit <at> debbugs.gnu.org; Sun, 16 Feb 2025 00:42:58 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:36884)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tjXQc-0004ql-AF
 for 76313 <at> debbugs.gnu.org; Sun, 16 Feb 2025 00:42:56 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1tjXQW-00071C-84; Sun, 16 Feb 2025 00:42:48 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=5qL5Tyry4QJ4pW/lFkEByCSGWtsil6zMwx8bNoytZ4k=; b=m8KbOn1Tz9JQ
 NoWMcz0KHePxvOw/PWdNoc9WDaFj7FhP20FgWmLuncAaGfe/PL/ynFmCASnHYqzuI5DVGxWa2g+oK
 g/2Z+urqOii9UAwPfbQ092jnpgUhA3sde0JOubcq0c+3GPvb6LqYnF/K8nf3oz98zwJcq6WDcYZub
 3NEkWzDjF160ZVvahfNQ9B3Bejzy4qeCSxpx1nqYb7c1xRonoxg35FZRK4OEPeQAjoMqkjRu8fl4s
 diVrIIkmV56zyf6pr8HKvANjpuKf++6ZfqbObAzPl0kCixkWki5YkoIXgWg7tLL6TfNbz+21EAKcs
 Wg71ADmraQQJFLnplowBAA==;
Date: Sun, 16 Feb 2025 07:42:43 +0200
Message-Id: <86seoecung.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
In-Reply-To: <jwv4j0u50tn.fsf-monnier+@gnu.org> (bug-gnu-emacs@HIDDEN)
Subject: Re: bug#76313: New function `replace-region`
References: <jwv4j0u50tn.fsf-monnier+@gnu.org>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 76313
Cc: 76313 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> Cc: monnier@HIDDEN
> Date: Sat, 15 Feb 2025 17:18:15 -0500
> From:  Stefan Monnier via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs@HIDDEN>
> 
> We often need to replace a chunk of buffer text with something else.
> It is easy enough to do with `insert` + `delete-region`, but that
> has suboptimal behavior w.r.t markers, so rather than let coders
> reinvent a slightly-better replacement I propose we add a dedicated
> function for it.
> 
> So I suggest the patch below.  Comments?  Objections?

What's wrong with replace-buffer-contents or replace-region-contents?




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 15 Feb 2025 22:18:40 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Feb 15 17:18:40 2025
Received: from localhost ([127.0.0.1]:58403 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tjQUh-0005lE-Vi
	for submit <at> debbugs.gnu.org; Sat, 15 Feb 2025 17:18:40 -0500
Received: from lists.gnu.org ([2001:470:142::17]:52774)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1tjQUf-0005kr-7o
 for submit <at> debbugs.gnu.org; Sat, 15 Feb 2025 17:18:37 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <monnier@HIDDEN>)
 id 1tjQUZ-0003ok-2z
 for bug-gnu-emacs@HIDDEN; Sat, 15 Feb 2025 17:18:31 -0500
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <monnier@HIDDEN>)
 id 1tjQUW-0004HR-LS
 for bug-gnu-emacs@HIDDEN; Sat, 15 Feb 2025 17:18:30 -0500
Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id F09A7804D9;
 Sat, 15 Feb 2025 17:18:25 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1739657904;
 bh=Oc3J4tcNtyauzsTdyKjqmU6RCMAC3cPYggWKa5IgT/s=;
 h=From:To:Subject:Date:From;
 b=JLdM0jc6+KImodlg+IZfk83yJWFRZSfni5Imzzyn0LplVzrzH0qzCzOOcrgaW8cUN
 vC/NmG5EFhhGdGvZJ3yGGPOINHzZjIa4X6N/dwUplg/wCuGSY02Lx3r3iiVKxEuwV3
 Pdg02jh7H+Lh06fVZEEFVpPw+EsTAiRF7qEE3x/W0mJuUY9ObCgZ+VXf2Eq4xJzinN
 D8mKbxNWCKxf1t0L4G80JHlgxRYQ3i+om5kUFikYHXw7DEWXAEdyq2dtNWYporManr
 umZ7jjU6GvyzFcj+T6OrCLlfI+zvX+L9ECxYrtqV9i3YQOmHFi5aerYwvrppUMbbTT
 gZ/FogkC+puTA==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id A61878056D;
 Sat, 15 Feb 2025 17:18:24 -0500 (EST)
Received: from pastel (unknown [104.247.242.5])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 8470312030F;
 Sat, 15 Feb 2025 17:18:24 -0500 (EST)
From: Stefan Monnier <monnier@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: New function `replace-region`
Message-ID: <jwv4j0u50tn.fsf-monnier+@gnu.org>
X-Debbugs-Cc: monnier@HIDDEN
Date: Sat, 15 Feb 2025 17:18:15 -0500
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL 0.079 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
Received-SPF: pass client-ip=132.204.25.50;
 envelope-from=monnier@HIDDEN; helo=mailscanner.iro.umontreal.ca
X-Spam_score_int: -42
X-Spam_score: -4.3
X-Spam_bar: ----
X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3,
 RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001,
 SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--=-=-=
Content-Type: text/plain

Tags: patch

We often need to replace a chunk of buffer text with something else.
It is easy enough to do with `insert` + `delete-region`, but that
has suboptimal behavior w.r.t markers, so rather than let coders
reinvent a slightly-better replacement I propose we add a dedicated
function for it.

So I suggest the patch below.  Comments?  Objections?


        Stefan

--=-=-=
Content-Type: text/patch
Content-Disposition: attachment; filename=replace-region.patch

diff --git a/etc/NEWS b/etc/NEWS
index 6d934b2029c..189ee92dac8 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1265,6 +1265,9 @@ restore the old behavior, you can set 'eshell-pwd-convert-function' to
 
 * Lisp Changes in Emacs 31.1
 
+** New function 'replace-region'.
+Acts like delete-region+insert, but preserves markers more carefully.
+
 ** Time & Date
 
 +++
diff --git a/lisp/language/japan-util.el b/lisp/language/japan-util.el
index c61e98c8fca..2be202ce5fe 100644
--- a/lisp/language/japan-util.el
+++ b/lisp/language/japan-util.el
@@ -215,11 +215,7 @@ japanese-zenkaku
     (or (get-char-code-property obj 'jisx0208)
 	obj)))
 
-(defun japanese-replace-region (from to string)
-  "Replace the region specified by FROM and TO to STRING."
-  (goto-char from)
-  (insert string)
-  (delete-char (- to from)))
+(define-obsolete-function-alias 'japanese-replace-region #'replace-region "31")
 
 ;;;###autoload
 (defun japanese-katakana-region (from to &optional hankaku)
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 19b78173792..dc436bf65fa 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -1421,6 +1421,7 @@ completion--replace
       (setq end (- end suffix-len))
       (setq newtext (substring newtext 0 (- suffix-len))))
     (goto-char beg)
+    ;; FIXME: Use `replace-region'?
     (let ((length (- end beg)))         ;Read `end' before we insert the text.
       (insert-and-inherit newtext)
       (delete-region (point) (+ (point) length)))
diff --git a/lisp/progmodes/flymake-proc.el b/lisp/progmodes/flymake-proc.el
index df6571311e4..0da85e1c053 100644
--- a/lisp/progmodes/flymake-proc.el
+++ b/lisp/progmodes/flymake-proc.el
@@ -331,7 +331,7 @@ flymake-proc--find-possible-master-files
       (setq dirs (cdr dirs)))
     (when files
       (let ((flymake-proc--included-file-name (file-name-nondirectory file-name)))
-	(setq files (sort files 'flymake-proc--master-file-compare))))
+	(setq files (sort files #'flymake-proc--master-file-compare))))
     (flymake-log 3 "found %d possible master file(s)" (length files))
     files))
 
@@ -407,9 +407,10 @@ flymake-proc--check-patch-master-file-buffer
                   ;;  replace-match is not used here as it fails in
                   ;; XEmacs with 'last match not a buffer' error as
                   ;; check-includes calls replace-in-string
-                  (flymake-proc--replace-region
-                   match-beg match-end
-                   (file-name-nondirectory patched-source-file-name))))
+                  (save-excursion
+                    (replace-region
+                     match-beg match-end
+                     (file-name-nondirectory patched-source-file-name)))))
               (forward-line 1)))
           (when found
             (flymake-proc--save-buffer-in-file patched-master-file-name)))
@@ -424,11 +425,9 @@ flymake-proc--check-patch-master-file-buffer
 ;;; XXX: remove
 (defun flymake-proc--replace-region (beg end rep)
   "Replace text in BUFFER in region (BEG END) with REP."
+  (declare (obsolete replace-region "31"))
   (save-excursion
-    (goto-char end)
-    ;; Insert before deleting, so as to better preserve markers's positions.
-    (insert rep)
-    (delete-region beg end)))
+    (replace-region beg end rep)))
 
 (defun flymake-proc--read-file-to-temp-buffer (file-name)
   "Insert contents of FILE-NAME into newly created temp buffer."
diff --git a/lisp/subr.el b/lisp/subr.el
index 77e909d1bf6..267ae741052 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -4680,6 +4680,24 @@ insert-into-buffer
     (with-current-buffer buffer
       (insert-buffer-substring current start end))))
 
+(defun replace-region (from to string)
+  "Replace text in buffer between FROM and TO with STRING.
+Moves point to the end of STRING."
+  (let ((to (+ to 0)))             ;Convert to integer if it's a marker.
+    (goto-char to)
+    (if (= from to)
+        (insert string)
+      ;; FIXME: Arguably, move-after-insertion markers found inside the
+      ;; FROM..TO region should be moved to the new end of the region
+      ;; rather than to the beginning.
+      ;; FIXME: We should call the before/after-change-functions only once
+      ;; (the best way to do that is probably to move it to `insdel.c').
+      ;; FIXME: Should we be careful to notice when a prefix/suffix of STRING
+      ;; is already a prefix/suffix of the FROM..TO region and refrain
+      ;; from touching it?
+      (insert-before-markers string)
+      (delete-region from to))))
+
 (defun replace-string-in-region (string replacement &optional start end)
   "Replace STRING with REPLACEMENT in the region from START to END.
 The number of replaced occurrences are returned, or nil if STRING
@@ -4703,8 +4721,7 @@ replace-string-in-region
       (let ((matches 0)
             (case-fold-search nil))
         (while (search-forward string nil t)
-          (delete-region (match-beginning 0) (match-end 0))
-          (insert replacement)
+          (replace-region (match-beginning 0) (match-end 0) replacement)
           (setq matches (1+ matches)))
         (and (not (zerop matches))
              matches)))))
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el
index 5b17c598efa..642071f825b 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -996,6 +996,29 @@ test-buffer-local-boundp
     (should-not (buffer-local-boundp 'test-not-boundp buf))
     (should (buffer-local-boundp 'test-global-boundp buf))))
 
+(ert-deftest subr-tests--replace-region ()
+  (with-temp-buffer
+    (insert "here is some text")
+    (let ((m5n (copy-marker (+ (point-min) 5)))
+          (m5a (copy-marker (+ (point-min) 5) t))
+          (m6n (copy-marker (+ (point-min) 6)))
+          (m6a (copy-marker (+ (point-min) 6) t))
+          (m7n (copy-marker (+ (point-min) 7)))
+          (m7a (copy-marker (+ (point-min) 7) t)))
+      (replace-region (+ (point-min) 5) (+ (point-min) 7) "was")
+      (should (equal (buffer-string) "here was some text"))
+      (should (equal (point) (+ (point-min) 8)))
+      ;; Markers before the replaced text stay before.
+      (should (= m5n (+ (point-min) 5)))
+      (should (= m5a (+ (point-min) 5)))
+      ;; Markers in the replaced text can end up at either end, depending
+      ;; on whether they're advance-after-insert or not.
+      (should (= m6n (+ (point-min) 5)))
+      (should (<= (+ (point-min) 5) m6a (+ (point-min) 8)))
+      ;; Markers after the replaced text stay after.
+      (should (= m7n (+ (point-min) 8)))
+      (should (= m7a (+ (point-min) 8))))))
+
 (ert-deftest test-replace-string-in-region ()
   (with-temp-buffer
     (insert "foo bar zot foobar")

--=-=-=--





Acknowledgement sent to Stefan Monnier <monnier@HIDDEN>:
New bug report received and forwarded. Copy sent to monnier@HIDDEN, bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to monnier@HIDDEN, bug-gnu-emacs@HIDDEN:
bug#76313; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sat, 8 Mar 2025 10:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.