Received: (at 76313) by debbugs.gnu.org; 31 Mar 2025 13:10:55 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Mon Mar 31 09:10:55 2025 Received: from localhost ([127.0.0.1]:40322 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tzEuj-0002Po-Dv for submit <at> debbugs.gnu.org; Mon, 31 Mar 2025 09:10:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36046) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tzEug-0002OL-Mp for 76313 <at> debbugs.gnu.org; Mon, 31 Mar 2025 09:10:51 -0400 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 1tzEua-0003SK-N1; Mon, 31 Mar 2025 09:10:44 -0400 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=Z3yIWUQ+nVSP/XmfOtsRYWQ2VmyO7nNAsoksD+ZSLBU=; b=ibyqj2xR8/CC ig2j+6ur5CdSrD2N6zWYFGF/gAuCCSrfrZyF9Yf4JIfpCj0KnHc6qEvEKp8+7qGRh3vP6EW82pVPS G9y3+TeL4q+iFiA1pyEmm1LLGzCpqrPMHb1f+FXp3QIVkgHRnBvg6uHO5kj8iCC57IktlahVwypDo w8Vof8U6D/iqHyPdHqt4Fcz0YRdf9r+4Y7V4qXfBWNiuzIIzL7xpWS8vX0LPh6k04r97aYMlI+S0W 6GEif1bbtx2tuvQzHKORWwj5n0tdKAj6hBXiZUg/l8BQVKZ/xCk8SQn6kwuNgDJQldN+U8MGO3Ytw wxbKo0zGbgp+Z0oOJQnrUw==; Date: Mon, 31 Mar 2025 16:10:29 +0300 Message-Id: <86a5914a7u.fsf@HIDDEN> From: Eli Zaretskii <eliz@HIDDEN> To: Tassilo Horn <tsdh@HIDDEN> In-Reply-To: <87zfh1zpmj.fsf@HIDDEN> (message from Tassilo Horn on Mon, 31 Mar 2025 08:21:56 +0200) Subject: Re: bug#76313: New function `replace-region` 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> <jwvr02hhi77.fsf-monnier+emacs@HIDDEN> <jwvv7rtxlmz.fsf-monnier+emacs@HIDDEN> <86r02g88e7.fsf@HIDDEN> <jwv4izbfqhj.fsf-monnier+emacs@HIDDEN> <87zfh1zpmj.fsf@HIDDEN> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 76313 Cc: phst@HIDDEN, 76313 <at> debbugs.gnu.org, monnier@HIDDEN, 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: Tassilo Horn <tsdh@HIDDEN> > Cc: Eli Zaretskii <eliz@HIDDEN>, stefankangas@HIDDEN, > phst@HIDDEN, 76313 <at> debbugs.gnu.org > Date: Mon, 31 Mar 2025 08:21:56 +0200 > > Stefan Monnier <monnier@HIDDEN> writes: > > > But I've changed my mind: I don't think we should unify > > `replace-region-contents` and my proposed `replace-region`. > > > > [...] > > > > While that was partly true, some of the problems were a lot more > > delicate: while `replace-region` is "easy" to use to do what I would > > describe as "edits", `replace-region-contents` is a good bit more > > delicate because its effect on point is less predictable. > > I think that's a very good point. Stefan's `replace-region` can be use > to replace text with some arbitrary other text with predictable > positioning of point. And the same cannot be done by calling replace-region-contents with MAX-SECS of zero? If not, why not?
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.Received: (at 76313) by debbugs.gnu.org; 31 Mar 2025 06:23:58 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Mon Mar 31 02:23:57 2025 Received: from localhost ([127.0.0.1]:39342 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tz8Yt-0007hb-Mc for submit <at> debbugs.gnu.org; Mon, 31 Mar 2025 02:23:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50074) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <tsdh@HIDDEN>) id 1tz8XD-0007Vo-G6 for 76313 <at> debbugs.gnu.org; Mon, 31 Mar 2025 02:22:13 -0400 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 1tz8X7-0008JU-3F; Mon, 31 Mar 2025 02:22:05 -0400 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=bbZ1CY8XV6JiqJTGN/kB8p5MYniwPx+IRfPsX2OUILQ=; b=pH4Ks1IyfSBESk8omjaB SgKqBwD8NYSwve6NxE3UqKlEIFgRgtiK+k4SWO2WcjRfRpQxR4yvpmMNeINeEcx23JUtdSKWOYFqo PeOfKhjrLRFvEbTjOndOVWJiof9JUrwTso6LGaBvPtKTDlk03HMGSdyBVgbU7nNGQyqFueXAuCGhk VMkzjMytKEKqVaY3lHIvTecWYe9SQRkgDp572B+/qnYZQWLNsTP8mYFDR/SfNV8LgEPCRTjxgg5jw zVDebwJPx4ooq1hukS5F1Ky38GALyje100PMXSEsGVVZ/Lg3JvUpFNtaomusMIDh1MkhbnYxIvXk3 UyuPQyXBxXgzrA==; X-ME-Sender: <xms:hzTqZ2fNOJ9FANCKsFjsZGMRMoj34EzVywWsMqgRcyIzko3rN4jihA> <xme:hzTqZwMbpMjcNRSOD8pqERdPudG43MRuPThGrsOupHvYEwdecijmCCkkfqRxf8kmM Khr0sE0FwS3yg> X-ME-Received: <xmr:hzTqZ3iKSFZmjqnnDqOafKyZ6OMqgJ9mV3FQ6CJ5-kZZrS5eaZGwo16AaY-0D8X6_rThzAlMw41GnUCn5M1o6jSOSrK9L2Q> X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddujeeludekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhephffvvefujghffgffkfggtgesthdtredttder tdenucfhrhhomhepvfgrshhsihhlohcujfhorhhnuceothhsughhsehgnhhurdhorhhgqe enucggtffrrghtthgvrhhnpeeluddvgeefuddvjeekfeetleegtefgveehhfeuffeuffeg hefgueefgfdvffegtdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehthhhorhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdek ieejfeekjeekgedqieefhedvleekqdhtshguhheppehgnhhurdhorhhgsehfrghsthhmrg hilhdrfhhmpdhnsggprhgtphhtthhopeehpdhmohguvgepshhmthhpohhuthdprhgtphht thhopeejieefudefseguvggssghughhsrdhgnhhurdhorhhgpdhrtghpthhtohepphhhsh htsehgohhoghhlvgdrtghomhdprhgtphhtthhopehsthgvfhgrnhhkrghnghgrshesghhm rghilhdrtghomhdprhgtphhtthhopegvlhhiiiesghhnuhdrohhrghdprhgtphhtthhope hmohhnnhhivghrsehirhhordhumhhonhhtrhgvrghlrdgtrg X-ME-Proxy: <xmx:hzTqZz8xzuRuIquCvO6gDMcdDJcbadgvao0_m9ZQb43XkPabZuERUw> <xmx:hzTqZytWYfDkq_fyya2v27f7r83k_1kivso1XWprSfq6a0BFlPm4og> <xmx:hzTqZ6HuZgf7Nc0V7uoxrwjHU_8zwyu9trfK2fNW74xtR3jtaxpvqg> <xmx:hzTqZxPSQa6qLoQA-Md8gdzvMrwsHPtbZRInoL0bCDAoiS8loPSqQg> <xmx:hzTqZ_NQ-IBKcmWNwctUXrmB6vudXEeBFtAjqYr8HVb4TRM6mKQsU6d1> Feedback-ID: ib2b94485:Fastmail From: Tassilo Horn <tsdh@HIDDEN> To: Stefan Monnier <monnier@HIDDEN> Subject: Re: bug#76313: New function `replace-region` In-Reply-To: <jwv4izbfqhj.fsf-monnier+emacs@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> <jwvr02hhi77.fsf-monnier+emacs@HIDDEN> <jwvv7rtxlmz.fsf-monnier+emacs@HIDDEN> <86r02g88e7.fsf@HIDDEN> <jwv4izbfqhj.fsf-monnier+emacs@HIDDEN> User-Agent: mu4e 1.12.9; emacs 31.0.50 Date: Mon, 31 Mar 2025 08:21:56 +0200 Message-ID: <87zfh1zpmj.fsf@HIDDEN> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 76313 Cc: phst@HIDDEN, 76313 <at> debbugs.gnu.org, Eli Zaretskii <eliz@HIDDEN>, 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 (---) Stefan Monnier <monnier@HIDDEN> writes: > But I've changed my mind: I don't think we should unify > `replace-region-contents` and my proposed `replace-region`. > > [...] > > While that was partly true, some of the problems were a lot more > delicate: while `replace-region` is "easy" to use to do what I would > describe as "edits", `replace-region-contents` is a good bit more > delicate because its effect on point is less predictable. I think that's a very good point. Stefan's `replace-region` can be use to replace text with some arbitrary other text with predictable positioning of point. `replace-region-contents` has always had the assumption that the replacing text is very similar to the text it replaces, e.g., a differently formatted version it. Only in this context it's sensible and intended that point doesn't move "out of the middle" because only here we can assume the thing point is on is also there in the replacing text. (And, yes, the name `replace-region-contents` doesn't transport that intention well.) Bye, Tassilo
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.Received: (at 76313) by debbugs.gnu.org; 30 Mar 2025 15:30:28 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sun Mar 30 11:30:28 2025 Received: from localhost ([127.0.0.1]:37758 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tyucG-0006S5-33 for submit <at> debbugs.gnu.org; Sun, 30 Mar 2025 11:30:28 -0400 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:61453) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <monnier@HIDDEN>) id 1tyucD-0006Rp-TH for 76313 <at> debbugs.gnu.org; Sun, 30 Mar 2025 11:30:26 -0400 Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 4E832440C7A; Sun, 30 Mar 2025 11:30:20 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1743348619; bh=PTSo5H/IpTD8dZDcWnJEzV8RTqesGGss8KMhHvKw7Yo=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=cuUlHaN8RCyRMYO1NCiGMuu9L/0C4XTOEpe2qkCCPNiDF/KvJHwIpu8OoMN15MppO hObEb+paF5An1xo3D3Wu3IaVrK3f5fbwzP4J9tB8Ckdndr1hwEapa5iuk/9uYLCtgy Kv18X2X1AhQQ8DwEcGiqpEbtdqX5mGOpzKt0Pcc4O0qT6k6S1HshLIUu0e1vMQOSxG T9/PlMRf95cRxZrMZuQ7Ph3m02pPKLvls9b+o8p0uW4Wn7Nsq8rh4TToeaPUVcGWp7 VO1LqImzsb8Rk5IoEzmpMEryR7jLbBtJi1kf1y8jlBeac81NJSZONcbCSNsKiX+Ml4 eCZoT5hwWlUog== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 12E8744089E; Sun, 30 Mar 2025 11:30:19 -0400 (EDT) Received: from pastel (unknown [104.247.242.5]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id D876912033B; Sun, 30 Mar 2025 11:30:18 -0400 (EDT) From: Stefan Monnier <monnier@HIDDEN> To: Eli Zaretskii <eliz@HIDDEN> Subject: Re: bug#76313: New function `replace-region` In-Reply-To: <86r02f5cgi.fsf@HIDDEN> Message-ID: <jwvbjtid0j5.fsf-monnier+emacs@HIDDEN> References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <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> <jwvr02hhi77.fsf-monnier+emacs@HIDDEN> <jwvv7rtxlmz.fsf-monnier+emacs@HIDDEN> <86r02g88e7.fsf@HIDDEN> <jwv4izbfqhj.fsf-monnier+emacs@HIDDEN> <86r02f5cgi.fsf@HIDDEN> Date: Sun, 30 Mar 2025 11:30:18 -0400 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.388 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, stefankangas@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 (---) >> > I'd prefer a completely backward-compatible change of passing a >> > special value of MAX-SECS to indicate that the potentially costly >> > algorithm is to be bypassed. >> We already have that: pass a 0 for MAX-SECS. > So we should probably mention this in the documentation? I think that's already implied by the doc of MAX-SECS: The MAX-SECS argument, if given, defines a hard limit on the time used for comparing the buffers. If it takes longer than MAX-SECS, the function falls back to a plain =E2=80=98delete-region=E2=80=99 and =E2=80=98insert-buffer-substring=E2=80=99. (Note that the checks are n= ot performed too evenly over time, so in some cases it may run a bit longer than allowed). >> IOW, if you have code that uses >>=20 >> (replace-region-contents BEG END SOURCE 0) >>=20 >> and you change it to: >>=20 >> (replace-region-contents BEG END SOURCE 0.1) >>=20 >> thinking "oh, I can afford to spend a bit more time here, let's >> enable the fancy diff algorithm", you may end up breaking your code. > > So maybe these subtleties should be described in the manual? And if > the caller doesn't care, or has point in a place that won't bump into > these issues, then replace-region-contents can still be used as a Lisp > API to replace_region? I feel like this is setting up a trap for the average coder. > For example, a loop like you describe above could carefully place > point before each call to re-search-forward, to avoid the > problems, no? Of course, the careful coder will find a solution. I still can't understand why you're so opposed to having 2 different functions. In comparison, we have: On the insertion side: - insert - insert-and-inherit - insert-before-markers - insert-buffer-substring - insert-buffer - insert-into-buffer On the deletion side: - delete-region - delete-char - delete-and-extract-region - erase-buffer I mean, I understand that the above functions all cover somewhat different calling cases [side note: `replace-region-contents` tries to unify them], whereas `replace-region` and `replace-region-carefully` would be called with the same arguments to "do the same". But I don't think coders would have any difficulty understanding that one of them is the low-level, deterministic, O(N) primitive while the other is a "smart" O(almost N=C2=B2) alternative, with a much larger consta= nt factor, which decomposes the replacement into smaller calls to `replace-region`, using heuristics, with the uncertainty this entails. Stefan
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.Received: (at 76313) by debbugs.gnu.org; 30 Mar 2025 05:12:29 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sun Mar 30 01:12:29 2025 Received: from localhost ([127.0.0.1]:34039 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tykyC-0002md-NU for submit <at> debbugs.gnu.org; Sun, 30 Mar 2025 01:12:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34236) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tyky9-0002mL-Hd for 76313 <at> debbugs.gnu.org; Sun, 30 Mar 2025 01:12:26 -0400 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 1tyky4-0005Uf-8R; Sun, 30 Mar 2025 01:12:20 -0400 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=p12ntvIMkPBXVJ0iuViCHfrmTDko7VWazLm69oQs81A=; b=aUA9UjRktM1t K3FNIk0taLFYphTJChs9Ugex766JlJOUPXQ4BHNEiAPLe6tv0FcuHK72SYdbGcEotelOrzJgec8Yj RCmVh0uHZUeVD4Asbjl9cZi/yWYuc6Gxs49fDiTysmXy2wYRvybCVpbqMunoJBQ4Z5JFVRrjYwkOJ sBHeQAJLCf/jO0WWa1czCBGfjSgQKJJZlQh9HZ0MZfFr8MEKc6o+cykWZcBUHo4TQc1ZWoDlyCgbM KnxHSBHRa+yDp0TWjzVufZQl1bPXSkMPLSNBu3hCkhl8EQt+JA2hlliJBDeACcKMs/TyM23wqbwUy 97iAs3/h5Ab0+HfSXw7+Rw==; Date: Sun, 30 Mar 2025 08:12:13 +0300 Message-Id: <86r02f5cgi.fsf@HIDDEN> From: Eli Zaretskii <eliz@HIDDEN> To: Stefan Monnier <monnier@HIDDEN> In-Reply-To: <jwv4izbfqhj.fsf-monnier+emacs@HIDDEN> (message from Stefan Monnier on Sat, 29 Mar 2025 18:20:15 -0400) Subject: Re: bug#76313: New function `replace-region` References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <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> <jwvr02hhi77.fsf-monnier+emacs@HIDDEN> <jwvv7rtxlmz.fsf-monnier+emacs@HIDDEN> <86r02g88e7.fsf@HIDDEN> <jwv4izbfqhj.fsf-monnier+emacs@HIDDEN> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 76313 Cc: 76313 <at> debbugs.gnu.org, stefankangas@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 Monnier <monnier@HIDDEN> > Cc: stefankangas@HIDDEN, phst@HIDDEN, 76313 <at> debbugs.gnu.org, > tsdh@HIDDEN > Date: Sat, 29 Mar 2025 18:20:15 -0400 > > > I'd prefer a completely backward-compatible change of passing a > > special value of MAX-SECS to indicate that the potentially costly > > algorithm is to be bypassed. > > We already have that: pass a 0 for MAX-SECS. So we should probably mention this in the documentation? > But I've changed my mind: I don't think we should unify > `replace-region-contents` and my proposed `replace-region`. > > When I sent the patches there were still some tests failing, and > I assumed these were just the result of idiotic errors on my part which > I'd fix the next day (it was late). > > While that was partly true, some of the problems were a lot more > delicate: while `replace-region` is "easy" to use to do what I would > describe as "edits", `replace-region-contents` is a good bit more > delicate because its effect on point is less predictable. > > When point is "in the middle" of the modified text, all is fine callers > usually don't expect any specific position for point after wards, in > that case. But if point is at the beginning (resp. at the end) of the text > being replaced, most callers expect it to still be at the beginning > (resp. the end) of the new text afterwards. > > This does hold when point is at the beginning of the text but *not* when > it's at the end. So in a typical loop scanning a buffer with > `re-search-forward` and then calling `replace-region-contents`, it's > easy to get bitten by it when occasionally we'll end up finding a match > in the text we just inserted because the "careful" version of > `replace-region-contents` moved point back somewhat. > > IOW, if you have code that uses > > (replace-region-contents BEG END SOURCE 0) > > and you change it to: > > (replace-region-contents BEG END SOURCE 0.1) > > thinking "oh, I can afford to spend a bit more time here, let's > enable the fancy diff algorithm", you may end up breaking your code. So maybe these subtleties should be described in the manual? And if the caller doesn't care, or has point in a place that won't bump into these issues, then replace-region-contents can still be used as a Lisp API to replace_region? For example, a loop like you describe above could carefully place point before each call to re-search-forward, to avoid the problems, no?
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.Received: (at 76313) by debbugs.gnu.org; 30 Mar 2025 04:16:12 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sun Mar 30 00:16:12 2025 Received: from localhost ([127.0.0.1]:33946 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tyk5i-00088b-IP for submit <at> debbugs.gnu.org; Sun, 30 Mar 2025 00:16:12 -0400 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:40722) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <monnier@HIDDEN>) id 1tyk5c-00087m-Ux for 76313 <at> debbugs.gnu.org; Sun, 30 Mar 2025 00:16:09 -0400 Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 4E495100045; Sun, 30 Mar 2025 00:15:58 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1743308156; bh=cbFSCEbhoWr6GDPGhzWMK3Y+jB3X39NBPMJreX/hKMg=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=PZuq/xAUiV/Pe7a/OxT8LUJR4Auk1oCGT6o3PnQ/4g3FP2ly4mmCGHsE7B0JMUoKf QA3gRd5GvsLeIqo3cYAr5EO2XAM+6QWuCDoshMe8HmyD8t4xcw8fk0EaEq0uw+0nEb sV+pZcjrtkffYUBPzVlK6/GXa7UkxRyxhXeIUAXnuNcXyux4dQSh7+GDpiJBO/kDUo UAswVcJWoEkTdVbnnnmyDLtgVP6csa3H5lWawKmC5PVVaOUiVZK9NAr/7Nk7wGbmZ5 10n7PTUTflp/ccb753bJNLVFZbdpr17+rewFemkmAddq3QQWxaFbwBWR0yJDh5bJd+ x16TPPFOEK8lg== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id C8862100034; Sun, 30 Mar 2025 00:15:56 -0400 (EDT) Received: from pastel (unknown [104.247.242.5]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 8E6BF1203FF; Sun, 30 Mar 2025 00:15:56 -0400 (EDT) From: Stefan Monnier <monnier@HIDDEN> To: Eli Zaretskii <eliz@HIDDEN> Subject: Re: bug#76313: New function `replace-region` In-Reply-To: <864izb7vxo.fsf@HIDDEN> Message-ID: <jwvy0wndyoo.fsf-monnier+emacs@HIDDEN> References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <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> <jwvr02hhi77.fsf-monnier+emacs@HIDDEN> <jwvv7rtxlmz.fsf-monnier+emacs@HIDDEN> <86r02g88e7.fsf@HIDDEN> <CADwFkmn3g7q==-yjyHz7PCM2jsH7cvfktby8xeLtgPPLrNNh5Q@HIDDEN> <86a5946l8j.fsf@HIDDEN> <CADwFkmnBMRTpA+-QSM-9EzEOaBnUUhdRVxiFz5=mYJWnhFnu9g@HIDDEN> <864izb7vxo.fsf@HIDDEN> Date: Sun, 30 Mar 2025 00:15:54 -0400 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.378 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, Stefan Kangas <stefankangas@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 (---) --=-=-= Content-Type: text/plain >> That would be the best way to do it, if the normal case is that you want >> the costly algorithm. But my understanding so far is that, in the >> overwhelming majority of cases, you do not want this. > I don't think this assumption is true. The slow and costly algorithm > keeps the markers and other properties, whereas bypassing it will not > do so. So the trade-off is not clear and depends on the context. My guts agree with Stefan, but I think none of us have hard data to confirm our intuition. This said, I did a quick: grep -C1 delete-region **/*.el | sed 's/-\([0-9]\+\)-/:\1:/' | grep insert and this gives a crapload of matches. A completely unscientific random sampling suggests that the majority of them could make use of `replace-region`, but that only a smaller proportion of them are likely to benefit from the fancy diff of `replace-region-contents`. See the (untested) patch below resulting from my random sampling (can you spot which ones use the fancy diff algo and which ones don't). To me the strongest argument in favor of having 2 separate functions is that the semantics is sufficiently different that callers need to know which is which (mostly because of the difference in algorithmic complexity but also because of where point is (guaranteed or not) after the call). [ I noticed also that some of them could benefit from an `and-extract` option (i.e. return the old text), e.g. in `transpose-subr-1`. It would be easy/cheap to add such an option to `replace-region`, but not to `replace-region-contents`. ] >> Personally, I would feel reluctant to use this function. For example, I >> don't know how to specify a meaningful value for MAX-COSTS. It is >> documented as specifying "the quality of the difference computation", >> which does not help much. I think our users will feel this even more. >> >> No other buffer editing primitives have anything resembling the MAX-SECS >> and MAX-COSTS arguments. I find the design choice to expose those >> arguments a bit unusual in a specialized function, and inappropriate in >> a function intended for general use. > > The original version of replace-buffer-contents didn't have any such > arguments. You called the function and had to wait for however long it > took to do its job. We added these arguments to give Lisp programs > more control, depending on the context and the importance of keeping > the text which doesn't need to be changed. Now we are discussing how > to give Lisp programs even more control. [ Note: This sub-discussion is only very remotely related to `replace-region`. ] FWIW, I find the MAX-COSTS very problematic, because nobody knows what it does. The only thing we know about it is that it's an integer and it defaults to 10k. Based on the name we can assume that a larger value pushes the limit further, so a smaller value may shorten the time to complete (while reducing the quality of the output), but we have no idea about the proportion. To make it usable, the programmer would need to know things like: - How does it relate to the size of the replaced text? E.g. If the replacement is "zoomed" by a factor 4 (i.e. e.g. just replace each char in both the old and the new text with 4 repetitions of that char), does the same MAX-COSTS lead to finding the same diff in both cases (modulo the zoom factor)? - If I reduce MAX-COSTS by half, is the max runtime reduced by half? Much less than half? Much more than half? Something else altogether? >> That said, I understand that they are occasionally useful, or they >> wouldn't exist. I would make them internal to the function, with >> sensible defaults that users could override with some variable when they >> need to. That change could be done in a backwards-compatible way with >> advertised-calling-convention', and I would suggest we do that. > I'm not sure I see how this would be better than what we have now. I'd tend to agree: Dynbound implicit args aren't great, so I think the current setup is not bad choice in this regard. The MAX-SECS arg tends to depend on the specific call, AFAICT, so I'm not sure there'd be much benefit to a global, overridable, default. As for MAX-COSTS, I don't think we can guess what setup is best without being able to answer the questions above. Stefan --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=replace-region.patch diff --git a/admin/admin.el b/admin/admin.el index 542556a65e0..a34e4adb9e1 100644 --- a/admin/admin.el +++ b/admin/admin.el @@ -517,8 +517,7 @@ manual-html-fix-headers (setq opoint (point)) (search-forward "</head>") (goto-char (match-beginning 0)) - (delete-region opoint (point)) - (insert manual-style-string) + (replace-region-contents opoint (point) manual-style-string 0) ;; Remove Texinfo 5 hard-coding bgcolor, text, link, vlink, alink. (when (re-search-forward "<body lang=\"[^\"]+\"" nil t) (setq opoint (point)) @@ -603,9 +602,10 @@ manual-html-fix-index-2 (setq opoint (match-beginning 0)) (while (and (looking-at " *—") (zerop (forward-line 1)))) - (delete-region opoint (point)) - (insert "</table>\n\n\ -<h2>Detailed Node Listing</h2>\n\n<p>") + (replace-region-contents opoint (point) + "</table>\n\n\ +<h2>Detailed Node Listing</h2>\n\n<p>" + 0) ;; FIXME Fragile! ;; The Emacs and Elisp manual have some text at the ;; start of the detailed menu that is not part of the menu. @@ -651,14 +651,15 @@ manual-html-fix-index-2 (save-excursion (forward-char -1) (skip-chars-backward " ") - (delete-region (point) (line-end-position)) - (insert "</td>\n </tr>"))) - (insert " <tr>\n ") - (if table-workaround - ;; This works around a Firefox bug in the mono file. - (insert "<td bgcolor=\"white\">") - (insert "<td>")) - (insert tag "</td>\n <td>" (or desc "")) + (replace-region-contents (point) (progn (end-of-line) (point)) + "</td>\n </tr>" 0) + )) + (insert " <tr>\n " + (if table-workaround + ;; This works around a Firefox bug in the mono file. + "<td bgcolor=\"white\">" + "<td>") + tag "</td>\n <td>" (or desc "")) (setq open-td t)) ((eq (char-after) ?\n) (delete-char 1) diff --git a/admin/gitmerge.el b/admin/gitmerge.el index 5bfb23dc3a2..ec2e5dd267b 100644 --- a/admin/gitmerge.el +++ b/admin/gitmerge.el @@ -324,12 +324,8 @@ gitmerge-resolve ;; match-3's first. (let ((match3 (buffer-substring start3 end3)) (match1 (buffer-substring start1 end1))) - (delete-region start3 end3) - (goto-char start3) - (insert match1) - (delete-region start1 end1) - (goto-char start1) - (insert match3))))) + (replace-region-contents start3 end3 match1 0) + (replace-region-contents start1 end1 match3 0))))) ;; (pop-to-buffer (current-buffer)) (debug 'before-resolve) )) ;; Try to resolve the conflicts. diff --git a/admin/tree-sitter/treesit-admin.el b/admin/tree-sitter/treesit-admin.el index 86174ed2625..516fd7bb700 100644 --- a/admin/tree-sitter/treesit-admin.el +++ b/admin/tree-sitter/treesit-admin.el @@ -187,8 +187,7 @@ treesit-admin--verify-major-mode-queries (forward-line -1)) (setq beg (point)) (search-forward "\n\n") - (delete-region beg (point)) - (insert ";;\n") + (replace-region-contents beg (point) ";;\n" 0) (dolist (mode modes) (insert (format ";; %s has been tested with the following grammars and version:\n" mode)) (dolist (lang (alist-get mode mode-language-alist)) diff --git a/lisp/abbrev.el b/lisp/abbrev.el index 93eb086da7a..cf3af3ea4e5 100644 --- a/lisp/abbrev.el +++ b/lisp/abbrev.el @@ -1106,9 +1106,9 @@ unexpand-abbrev (unless (stringp val) (error "Value of abbrev-symbol must be a string")) ;; Don't inherit properties here; just copy from old contents. - (insert last-abbrev-text) - ;; Delete after inserting, to better preserve markers. - (delete-region (point) (+ (point) (length val))) + (forward-char (length val)) + (replace-region-contents last-abbrev-location (point) + last-abbrev-text 0) (setq last-abbrev-text nil)))))) (defun abbrev--write (sym) diff --git a/lisp/mail/rmailedit.el b/lisp/mail/rmailedit.el index 60916818caf..32b5e0d3da3 100644 --- a/lisp/mail/rmailedit.el +++ b/lisp/mail/rmailedit.el @@ -350,8 +350,7 @@ rmail-abort-edit "Abort edit of current message; restore original contents." (interactive) (widen) - (delete-region (point-min) (point-max)) - (insert rmail-old-text) + (replace-region-contents (point-min) (point-max) rmail-old-text) (rmail-cease-edit t) (rmail-highlight-headers)) diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el index 7052ac75817..d2379ecac78 100644 --- a/lisp/progmodes/cperl-mode.el +++ b/lisp/progmodes/cperl-mode.el @@ -5829,9 +5829,10 @@ cperl-fix-line-spacing cperl-extra-newline-before-brace))) (setq pp (point)) (skip-chars-forward " \t\n") - (delete-region pp (point)) - (insert - (make-string cperl-indent-region-fix-constructs ?\ ))) + (replace-region-contents + pp (point) + (make-string cperl-indent-region-fix-constructs ?\ ) + 0)) ((and (looking-at "[\t ]*{") (if ml cperl-extra-newline-before-brace-multiline cperl-extra-newline-before-brace)) diff --git a/lisp/simple.el b/lisp/simple.el index 7037158df8d..26513d52430 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -8834,18 +8834,19 @@ transpose-subr-1 (atomic-change-group ;; This sequence of insertions attempts to preserve marker ;; positions at the start and end of the transposed objects. - (let* ((word (buffer-substring (car pos2) (cdr pos2))) + ;; FIXME: Why don't we use `transpose-regions', which has extra code + ;; to "transpose" the markers together with the text!? + (let* ((word2 (buffer-substring (car pos2) (cdr pos2))) (len1 (- (cdr pos1) (car pos1))) - (len2 (length word)) - (boundary (make-marker))) - (set-marker boundary (car pos2)) + (len2 (length word2)) + (boundary (copy-marker (car pos2)))) (goto-char (cdr pos1)) - (insert-before-markers word) - (setq word (delete-and-extract-region (car pos1) (+ (car pos1) len1))) - (goto-char boundary) - (insert word) - (goto-char (+ boundary len1)) - (delete-region (point) (+ (point) len2)) + ;; FIXME: We could use `replace-region-contents' but at the cost of + ;; not benefiting from `delete-and-extract-region'. + (insert-before-markers word2) + (let ((word1 (delete-and-extract-region (car pos1) (+ (car pos1) len1)))) + (goto-char (+ boundary len2)) + (replace-region-contents boundary (+ boundary len2) word1 0)) (set-marker boundary nil)))) (defun backward-word (&optional arg) diff --git a/lisp/tar-mode.el b/lisp/tar-mode.el index 3b9898bd2f4..a235dd4ab83 100644 --- a/lisp/tar-mode.el +++ b/lisp/tar-mode.el @@ -1425,31 +1425,30 @@ tar-alter-one-field ;; ;; update the header-line. (let ((col (current-column))) - (delete-region (line-beginning-position) - (prog2 (forward-line 1) - (point) - ;; Insert the new text after the old, before deleting, - ;; to preserve markers such as the window start. - (insert (tar-header-block-summarize descriptor) "\n"))) - (forward-line -1) (move-to-column col)) + (replace-region-contents + (line-beginning-position) (line-end-position) + (tar-header-block-summarize descriptor) 0) + (move-to-column col)) (cl-assert (tar-data-swapped-p)) (with-current-buffer tar-data-buffer (let* ((start (- (tar-header-data-start descriptor) 512))) - ;; - ;; delete the old field and insert a new one. - (goto-char (+ start data-position)) - (delete-region (point) (+ (point) (length new-data-string))) ; <-- - (cl-assert (not (or enable-multibyte-characters - (multibyte-string-p new-data-string)))) - (insert new-data-string) - ;; - ;; compute a new checksum and insert it. - (let ((chk (tar-header-block-checksum + ;; + (cl-assert (not (or enable-multibyte-characters + (multibyte-string-p new-data-string)))) + ;; delete the old field and insert a new one. + (replace-region-contents + (+ start data-position) + (+ start data-position (length new-data-string)) + new-data-string 0) + ;; + ;; compute a new checksum and insert it. + (let ((chk (tar-header-block-checksum (buffer-substring start (+ start 512))))) - (goto-char (+ start tar-chk-offset)) - (delete-region (point) (+ (point) 8)) - (insert (format "%6o\0 " chk)) + (replace-region-contents + (+ start tar-chk-offset) + (+ start tar-chk-offset 8) + (format "%6o\0 " chk) 0) (setf (tar-header-checksum descriptor) chk) ;; ;; ok, make sure we didn't botch it. diff --git a/lisp/term.el b/lisp/term.el index 862103d88e6..05001de098c 100644 --- a/lisp/term.el +++ b/lisp/term.el @@ -4054,7 +4054,6 @@ term-erase-in-line (unless (and (eq saved-point (1- (point))) (eq (char-before) ?\n) (not wrapped)) - ;; Insert before deletion to preserve markers. ;; wrapped is true if we're at the beginning of screen line, ;; but not a buffer line. If we delete the current screen line ;; that will make the previous line no longer wrap, and (because @@ -4064,10 +4063,8 @@ term-erase-in-line ;; contain a space, to force the previous line to continue to wrap. ;; We could do this always, but it seems preferable to not add the ;; extra space when wrapped is false. - (when wrapped - (insert-before-markers ? )) - (insert-before-markers ?\n) - (delete-region saved-point (point))) + (replace-region-contents saved-point (point) + (if wrapped " \n" "\n") 0)) (put-text-property saved-point (point) 'font-lock-face 'default) (goto-char saved-point)))) diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 459154f534b..84c735502be 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -2139,9 +2139,8 @@ diff-apply-hunk (t ;; Apply the hunk (with-current-buffer buf - (goto-char (car pos)) - (delete-region (car pos) (cdr pos)) - (insert (car new))) + (goto-char (cdr pos)) + (replace-region-contents (car pos) (cdr pos) (car new))) ;; Display BUF in a window (set-window-point (display-buffer buf) (+ (car pos) (cdr new))) (diff-hunk-status-msg line-offset (xor switched reverse) nil) --=-=-=--
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.Received: (at 76313) by debbugs.gnu.org; 29 Mar 2025 22:20:30 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 29 18:20:29 2025 Received: from localhost ([127.0.0.1]:33306 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tyeXV-0004Q5-F1 for submit <at> debbugs.gnu.org; Sat, 29 Mar 2025 18:20:29 -0400 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:6718) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <monnier@HIDDEN>) id 1tyeXP-0004Pf-Pi for 76313 <at> debbugs.gnu.org; Sat, 29 Mar 2025 18:20:25 -0400 Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 49B15808B1; Sat, 29 Mar 2025 18:20:18 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1743286817; bh=X7XmWl7pFnwhc00meW6kphr7DezF2UNXDgbpj4Fv9zw=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=HtXwNpamUBePmLqWI4EFp7IYWaB21UfJoJeZUlAZ9c8eeiOTDW/CpB28E+l+s6Jt3 AEy5VShGvvBceMhKG4gvXPsPO+SIWKkqoyuT68q1G+wpktJG0ufkzhNx0qgOrb/hWn YKPgBOR7S3CY8WuMxSCtaEwE3a07D/QN9L533KFWoeh5+qotkHG+6TpHrcl/UXuGoL 4GOsq9gmIDD/uHnLe6OKTD/KrnF8X/Ru+FC7XFOtkIjPD740cg6qS0RCr/G+iBwrEY vSgUtsEnU7R+DAdgZ3HAW6u91YDuqmghUG4VdsYSXdodEcEi1x6TRSDC2PM2UdhtSw E4FmmC7+WyduA== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 37C2F8045E; Sat, 29 Mar 2025 18:20:17 -0400 (EDT) Received: from pastel (unknown [104.247.242.5]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id F15A21203C3; Sat, 29 Mar 2025 18:20:16 -0400 (EDT) From: Stefan Monnier <monnier@HIDDEN> To: Eli Zaretskii <eliz@HIDDEN> Subject: Re: bug#76313: New function `replace-region` In-Reply-To: <86r02g88e7.fsf@HIDDEN> Message-ID: <jwv4izbfqhj.fsf-monnier+emacs@HIDDEN> References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <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> <jwvr02hhi77.fsf-monnier+emacs@HIDDEN> <jwvv7rtxlmz.fsf-monnier+emacs@HIDDEN> <86r02g88e7.fsf@HIDDEN> Date: Sat, 29 Mar 2025 18:20:15 -0400 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.363 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: phst@HIDDEN, 76313 <at> debbugs.gnu.org, stefankangas@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 Monnier <monnier@HIDDEN> >> Cc: Stefan Kangas <stefankangas@HIDDEN>, phst@HIDDEN, >> 76313 <at> debbugs.gnu.org, tsdh@HIDDEN >> Date: Fri, 28 Mar 2025 11:38:19 -0400 >> >> Any chance we could consider a breaking change and force a non-nil value of >> one of MAX-SECS or MAX-COSTS before the function is allowed to use the >> costly algorithm? > > I'd prefer a completely backward-compatible change of passing a > special value of MAX-SECS to indicate that the potentially costly > algorithm is to be bypassed. We already have that: pass a 0 for MAX-SECS. But I've changed my mind: I don't think we should unify `replace-region-contents` and my proposed `replace-region`. When I sent the patches there were still some tests failing, and I assumed these were just the result of idiotic errors on my part which I'd fix the next day (it was late). While that was partly true, some of the problems were a lot more delicate: while `replace-region` is "easy" to use to do what I would describe as "edits", `replace-region-contents` is a good bit more delicate because its effect on point is less predictable. When point is "in the middle" of the modified text, all is fine callers usually don't expect any specific position for point after wards, in that case. But if point is at the beginning (resp. at the end) of the text being replaced, most callers expect it to still be at the beginning (resp. the end) of the new text afterwards. This does hold when point is at the beginning of the text but *not* when it's at the end. So in a typical loop scanning a buffer with `re-search-forward` and then calling `replace-region-contents`, it's easy to get bitten by it when occasionally we'll end up finding a match in the text we just inserted because the "careful" version of `replace-region-contents` moved point back somewhat. IOW, if you have code that uses (replace-region-contents BEG END SOURCE 0) and you change it to: (replace-region-contents BEG END SOURCE 0.1) thinking "oh, I can afford to spend a bit more time here, let's enable the fancy diff algorithm", you may end up breaking your code. Stefan
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.Received: (at 76313) by debbugs.gnu.org; 29 Mar 2025 21:59:07 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 29 17:59:07 2025 Received: from localhost ([127.0.0.1]:33280 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tyeCp-0003G9-6p for submit <at> debbugs.gnu.org; Sat, 29 Mar 2025 17:59:07 -0400 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:1735) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <monnier@HIDDEN>) id 1tyeCm-0003FU-QP for 76313 <at> debbugs.gnu.org; Sat, 29 Mar 2025 17:59:05 -0400 Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id B8F9480037; Sat, 29 Mar 2025 17:58:58 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1743285537; bh=m9Q2u/kz9mz+UMTH+CZaWLwCllmWKGBJH5YBXb9rfIE=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=PLAQ9aPHyBYDIjU4R8KPVNtoaLJB6Ou9weq3KAuk1npu+WQPsoREXS9n7h79PWZuC jiDhXbPK6M3SHPZmCw79cDAKSny9F7JxWvAQqSb8DOy7kUGNZ5mLUjQ0iaIP4OMXnS 1LfHf6XQX1G6JbmPP21AFOxAqGaksjtrfJ2faGxD98wmKbP5MReWHy93DqMx91GgEq E6z51FmNC0/ZKg7iYvj+Jzvy4QgU59M1opg4r18t2dE29xrxCjrba26cPIv+tGAqrG KMXB1gtB4uOZKQ3VdlcUMS2QTEKr2efiFDU3bV+hQ8ctLXRjKwsaLE/aUwdnX5GlRv rIunF3eBjhxZA== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 5A46A8075E; Sat, 29 Mar 2025 17:58:57 -0400 (EDT) Received: from pastel (unknown [104.247.242.5]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id DD8821203DA; Sat, 29 Mar 2025 17:58:56 -0400 (EDT) From: Stefan Monnier <monnier@HIDDEN> To: Eli Zaretskii <eliz@HIDDEN> Subject: Re: bug#76313: New function `replace-region` In-Reply-To: <86semw88uq.fsf@HIDDEN> Message-ID: <jwvbjtjfshc.fsf-monnier+emacs@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> <jwvr02hhi77.fsf-monnier+emacs@HIDDEN> <86semw88uq.fsf@HIDDEN> Date: Sat, 29 Mar 2025 17:58:55 -0400 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.365 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: phst@HIDDEN, 76313 <at> debbugs.gnu.org, stefankangas@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 (---) >> +(defun replace-buffer-contents (source &optional max-secs max-costs) >> + "Replace accessible portion of current buffer with that of SOURCE. >> +SOURCE can be a buffer or a string that names a buffer. >> +Interactively, prompt for SOURCE. >> + >> +The replacement is performed using `replace-region-contents' >> +which also describes the MAX-SECS and MAX-COSTS arguments and the >> +return value." >> + (declare (obsolete replace-region-contents "31.1")) >> + (interactive "bSource buffer: ") >> + (replace-region-contents (point-min) (point-max) >> + (if (stringp source) (get-buffer source) sou= rce) >> + max-secs max-costs)) > > Since this is an interactive function, shouldn't it test SOURCE to be > of a valid type, instead of delegating to replace-region-contents? I was being sloppy because it's obsolete anyway, but actually it's simpler to always pass the arg to `get-buffer`, so you're quite right! >> +Note: If the replacement is a string, it=E2=80=99ll usually be placed i= nternally >> +in a temporary buffer. Therefore, if you already have the replacement >> +in a buffer, it makes no sense to convert it to a string using >> +=E2=80=98buffer-substring=E2=80=99 or similar. > > This uses Unicode quotes in a doc string; please use ASCII characters > instead. Hmm... copy/paste from *Help*. I think I'm going to turn off those fancy quotes because it's not the first it bites me. >> + b =3D XBUFFER (AREF (source, 0)); >> + min_b =3D XFIXNUM (AREF (source, 1)); >> + size_b =3D XFIXNUM (insend) - min_b; >> + if (size_b < 0) >> + error ("Negative sized source range"); > > Shouldn't we support here any order of SBEG and SEND, as we do in many > other places? Hmm... I must admit I'm not a big fan of this "feature", but OK, I changed the code to use `validate_region` as elsewhere. >> + if (! (BUF_BEGV (b) <=3D min_b && min_b + size_b <=3D BUF_ZV (b))) >> + args_out_of_range_3 (AREF (source, 0), AREF (source, 0), AREF (source,= 1)); > > Should this error message show all 3 values, instead of showing one of > them twice? Or maybe show BEGV, ZV, and the offending position > (either SBEG or SEND)? Fixed, thanks. >> + bool b_empty =3D size_b =3D=3D 0; >> + if (b && !BUFFER_LIVE_P (b)) >> error ("Selecting deleted buffer"); > > What if b is NULL? can we continue? Yes: `b` is NULL here iff source is a string, in which case it's set later to a locally-created temp buffer. >> + /* The rest of the code is not prepared to handle a string SOURCE. */ >> + if (!b) >> + { >> + Lisp_Object name >> + =3D Fgenerate_new_buffer_name (build_string (" *replace-workbuf*"), Qn= il); >> + Lisp_Object workbuf =3D Fget_buffer_create (name, Qt); >> + b =3D XBUFFER (workbuf); >> + record_unwind_protect (kill_buffer, workbuf); >> + record_unwind_current_buffer (); >> + set_buffer_internal (b); >> + Fset_buffer_multibyte (STRING_MULTIBYTE (source) ? Qt : Qnil); > > coding.c:code_conversion_save does something similar; perhaps some of > the buffer-local settings we use there could also be a good idea here? Even better: I changed the code to call `code_conversion_save`! > Please update the commentary to replace_range to describe this type of NE= W. Done, thanks, and pushed. Stefan
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.Received: (at 76313) by debbugs.gnu.org; 29 Mar 2025 14:28:54 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 29 10:28:54 2025 Received: from localhost ([127.0.0.1]:60673 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tyXB6-0004h5-Qt for submit <at> debbugs.gnu.org; Sat, 29 Mar 2025 10:28:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50140) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tyXB1-0004gn-Mz for 76313 <at> debbugs.gnu.org; Sat, 29 Mar 2025 10:28:49 -0400 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 1tyXAs-00029y-SY; Sat, 29 Mar 2025 10:28:40 -0400 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=ITkgAXnQByLlD6G7GNUYEl/s58qcpjfDz3gr/ZRn2uI=; b=hUh7IOoZsUXk IxZc5D5KWLdho7Q3zSHIrVzsfDIVuJgJ22m9fn988XGOHKQTBgElaHufxOH8qWLKYqMZm3NRTGKW1 c/iQwQDKyu0W7mMdRVcJUiHiDIyP5C5pzp+jX4snQbDXf6j51XuBwcLaNZAvrpuaBmB/O/fbKeYwa ilHAhAA9NEuNRNHm3TWq5l+rc/2AbcDjJfGUTRpBcJ2itxV7dFpe+JImmmtuW2ivG3M+C+OfMKx1n fYRoAKBOz80J8qQZ3SzvX6fWpZll26bfbyhtYbiPu0JXf7j1Gj2jkZefPqeewyetrdzM+cUKNPK/R MOymG3UN8sIwsQ50+64erg==; Date: Sat, 29 Mar 2025 17:28:35 +0300 Message-Id: <864izb7vxo.fsf@HIDDEN> From: Eli Zaretskii <eliz@HIDDEN> To: Stefan Kangas <stefankangas@HIDDEN> In-Reply-To: <CADwFkmnBMRTpA+-QSM-9EzEOaBnUUhdRVxiFz5=mYJWnhFnu9g@HIDDEN> (message from Stefan Kangas on Sat, 29 Mar 2025 06:57:48 -0700) Subject: Re: bug#76313: New function `replace-region` References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <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> <jwvr02hhi77.fsf-monnier+emacs@HIDDEN> <jwvv7rtxlmz.fsf-monnier+emacs@HIDDEN> <86r02g88e7.fsf@HIDDEN> <CADwFkmn3g7q==-yjyHz7PCM2jsH7cvfktby8xeLtgPPLrNNh5Q@HIDDEN> <86a5946l8j.fsf@HIDDEN> <CADwFkmnBMRTpA+-QSM-9EzEOaBnUUhdRVxiFz5=mYJWnhFnu9g@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: Sat, 29 Mar 2025 06:57:48 -0700 > Cc: monnier@HIDDEN, 76313 <at> debbugs.gnu.org, tsdh@HIDDEN > > Eli Zaretskii <eliz@HIDDEN> writes: > > >> We can keep trying to shoe-horn `replace-region-contents` into something > >> that looks like a function intended for general use, and document it as > >> such. If we go that route, I think it would make sense to make the > >> change Stefan M proposes. > > > > Can you explain why it does NOT make sense to do what I proposed? It > > gives us what Stefan wanted, but avoids the backward incompatibility > > (unless I'm missing something). > > My understanding is that your proposal means that the potentially costly > algorithm is used by default, and that users should explicitly say so if > they don't want it. > > That would be the best way to do it, if the normal case is that you want > the costly algorithm. But my understanding so far is that, in the > overwhelming majority of cases, you do not want this. I don't think this assumption is true. The slow and costly algorithm keeps the markers and other properties, whereas bypassing it will not do so. So the trade-off is not clear and depends on the context. > >> Alternatively, we let it live on as a proper citizen of subr-x.el and > >> consequently remove it from the manual. We've managed without > >> `replace-region` for decades already, so there's no urgent need to > >> elevate a design that has more than a few rough edges. > > > > ??? I'm confused: Stefan made replace-region-contents our preferred > > API, and demoted replace-buffer. Are you suggesting to do the > > opposite now? > > I agree that it's a step forward to demote `replace-buffer-contents`. > > I submit that it's worth considering that we might better off with just > a function in subr-x.el, for when you need it, than officially blessing > a problematic or suboptimal function for general use. I don't see any blessing. We have 2 functions before; after Stefan's changes we will have one function and another one obsolete. > Personally, I would feel reluctant to use this function. For example, I > don't know how to specify a meaningful value for MAX-COSTS. It is > documented as specifying "the quality of the difference computation", > which does not help much. I think our users will feel this even more. > > No other buffer editing primitives have anything resembling the MAX-SECS > and MAX-COSTS arguments. I find the design choice to expose those > arguments a bit unusual in a specialized function, and inappropriate in > a function intended for general use. The original version of replace-buffer-contents didn't have any such arguments. You called the function and had to wait for however long it took to do its job. We added these arguments to give Lisp programs more control, depending on the context and the importance of keeping the text which doesn't need to be changed. Now we are discussing how to give Lisp programs even more control. > That said, I understand that they are occasionally useful, or they > wouldn't exist. I would make them internal to the function, with > sensible defaults that users could override with some variable when they > need to. That change could be done in a backwards-compatible way with > advertised-calling-convention', and I would suggest we do that. I'm not sure I see how this would be better than what we have now. It has to be significantly better to justify incompatible changes like that. If we add an easy way to bypass the costly part, for the Lisp programs that don't care enough about the consequences, I think we will have the best of all worlds.
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.Received: (at 76313) by debbugs.gnu.org; 29 Mar 2025 13:58:00 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 29 09:57:59 2025 Received: from localhost ([127.0.0.1]:60611 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tyWhD-00038Y-Ab for submit <at> debbugs.gnu.org; Sat, 29 Mar 2025 09:57:59 -0400 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]:45457) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from <stefankangas@HIDDEN>) id 1tyWh9-00038E-Dy for 76313 <at> debbugs.gnu.org; Sat, 29 Mar 2025 09:57:57 -0400 Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-5e5e63162a0so1096522a12.3 for <76313 <at> debbugs.gnu.org>; Sat, 29 Mar 2025 06:57:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743256669; x=1743861469; 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=WBZ3LH25/PaGU6nXRjnZRG8Q2mQk3S5HEq+faI+YLZM=; b=BJY4goIPLZ+3RpeEvR8Axv2y2iYhWL4nBk8CmiR7LifvK+4Q5d40f9jQQxtDIQ0mJj 0gC5x1/apNlsScuYM9+QEtI2qSEoFH1LTlNo6EnW7Xmjw+vwvbakuHkENXuWpTSLUMme eFsYhRY9n+f6gc8r/6UdhXc4tZJPrXTrmRR2eDyAsEeW8vbyTt/e7j6aggbmYO5K09an UwGGzHl3nWUgj92wBIjMZaaNT4v0NUm1xQ5dmjs24Q/AFTK0KfWi0XBEeybHJFWLRKDF bQFLC6+kaeEwD8m87rXuC+S/kubCsEvKLQE2b2IpJ7OwRDpTPHrYRb9g7bFxNgqo1uhx XvYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743256669; x=1743861469; 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=WBZ3LH25/PaGU6nXRjnZRG8Q2mQk3S5HEq+faI+YLZM=; b=UbaNh9bWPisl7xgqQrs8W54gYI+YNviduzFc0VMkV+ZM5fbztzEOt+kQzN83uX6Ptd 6cS+XzHWUVoTpwIFMJxJosrZpg4COLuYBNLS8O7EgA03sUK1UnPdup9bb28C/hEEoO+4 6LoeDouEMhhOjymBa2PZigNYs/gZRHmJHTHEQjq1HjR7t7vTvqT29g4L0aZfLGIahBwb pBDpeEYYpHZSGdWE7pJ44nA9wPSCrKkfFZydQWOxduoqn6DHdjdoFEBVAAgGX7FcQzoI KHU88qsjb3EdK8eFbFmK2gQG/QECmyPGbtnN52nhyT5Sqrdu0zmSxhzApcTOSY56GnQk dypg== X-Forwarded-Encrypted: i=1; AJvYcCXwfAWIKm69ltuAK7xE6UfurnyJgAhsNWOaK4V/GNQHP2gM6I8ShYv8v5cSgyTMo+TqySW/sg==@debbugs.gnu.org X-Gm-Message-State: AOJu0YyMYuGZ8sBaeOnYbRBS8KUxiVa58wiQxyuT2ywuE/nKH/nXP3uG Squ3lCi7WIgqoFrspnSmmHv6JqRT+OD3Rg+cjNMqd78kpzdKnyDSzB/1XMi9lvGElo87iptFJ5x V2v81o3qH2zN87Gv3WfTJxVCyJn0= X-Gm-Gg: ASbGnctWegy7vZlGElmWGqZYVVQ+bpH7qF5XX+pmAcdEdt784HdHk3nAr55Nuka2zPv BC2hw/h0YpBy1x1YtYqGoX4UsjaPXIanjOdjFvhKTVoR+rfOF4W0WdfqIlQwZTToGLPfkUYkEqO woBH9Q54CRqKGtl17s9pzfaillprHXS2KPYBMZPA== X-Google-Smtp-Source: AGHT+IEPyVPU5Eok2pQoPir3ifeavUxCtcu7Q6y1yjZfZjp4B2svGPgil9RddnOT22Wo7s7cguztrIe+drtpFL7tfW4= X-Received: by 2002:a05:6402:34d1:b0:5e0:9959:83cd with SMTP id 4fb4d7f45d1cf-5edfda0295bmr2540249a12.21.1743256668983; Sat, 29 Mar 2025 06:57:48 -0700 (PDT) Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Sat, 29 Mar 2025 06:57:48 -0700 From: Stefan Kangas <stefankangas@HIDDEN> In-Reply-To: <86a5946l8j.fsf@HIDDEN> References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <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> <jwvr02hhi77.fsf-monnier+emacs@HIDDEN> <jwvv7rtxlmz.fsf-monnier+emacs@HIDDEN> <86r02g88e7.fsf@HIDDEN> <CADwFkmn3g7q==-yjyHz7PCM2jsH7cvfktby8xeLtgPPLrNNh5Q@HIDDEN> <86a5946l8j.fsf@HIDDEN> MIME-Version: 1.0 Date: Sat, 29 Mar 2025 06:57:48 -0700 X-Gm-Features: AQ5f1Jp9Cux6Zyldkn_cxmfdPGHtADQkyxLeFEYU8JtvnQRecRAA8oVmsSPIeI0 Message-ID: <CADwFkmnBMRTpA+-QSM-9EzEOaBnUUhdRVxiFz5=mYJWnhFnu9g@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: Sat, 29 Mar 2025 05:46:51 -0700 >> Cc: phst@HIDDEN, 76313 <at> debbugs.gnu.org, tsdh@HIDDEN >> >> Eli Zaretskii <eliz@HIDDEN> writes: >> >> >> From: Stefan Monnier <monnier@HIDDEN> >> >> Cc: Stefan Kangas <stefankangas@HIDDEN>, phst@HIDDEN, >> >> 76313 <at> debbugs.gnu.org, tsdh@HIDDEN >> >> Date: Fri, 28 Mar 2025 11:38:19 -0400 >> >> >> >> Any chance we could consider a breaking change and force a non-nil value of >> >> one of MAX-SECS or MAX-COSTS before the function is allowed to use the >> >> costly algorithm? >> > >> > I'd prefer a completely backward-compatible change of passing a >> > special value of MAX-SECS to indicate that the potentially costly >> > algorithm is to be bypassed. >> >> We can keep trying to shoe-horn `replace-region-contents` into something >> that looks like a function intended for general use, and document it as >> such. If we go that route, I think it would make sense to make the >> change Stefan M proposes. > > Can you explain why it does NOT make sense to do what I proposed? It > gives us what Stefan wanted, but avoids the backward incompatibility > (unless I'm missing something). My understanding is that your proposal means that the potentially costly algorithm is used by default, and that users should explicitly say so if they don't want it. That would be the best way to do it, if the normal case is that you want the costly algorithm. But my understanding so far is that, in the overwhelming majority of cases, you do not want this. >> Alternatively, we let it live on as a proper citizen of subr-x.el and >> consequently remove it from the manual. We've managed without >> `replace-region` for decades already, so there's no urgent need to >> elevate a design that has more than a few rough edges. > > ??? I'm confused: Stefan made replace-region-contents our preferred > API, and demoted replace-buffer. Are you suggesting to do the > opposite now? I agree that it's a step forward to demote `replace-buffer-contents`. I submit that it's worth considering that we might better off with just a function in subr-x.el, for when you need it, than officially blessing a problematic or suboptimal function for general use. Personally, I would feel reluctant to use this function. For example, I don't know how to specify a meaningful value for MAX-COSTS. It is documented as specifying "the quality of the difference computation", which does not help much. I think our users will feel this even more. No other buffer editing primitives have anything resembling the MAX-SECS and MAX-COSTS arguments. I find the design choice to expose those arguments a bit unusual in a specialized function, and inappropriate in a function intended for general use. That said, I understand that they are occasionally useful, or they wouldn't exist. I would make them internal to the function, with sensible defaults that users could override with some variable when they need to. That change could be done in a backwards-compatible way with advertised-calling-convention', and I would suggest we do that. With that change, and the one proposed by Stefan Monnier above, I can see that keeping `replace-region-contents` is okay. I would also suggest adding the alias `replace-region` for improved ergonomics and consistency (e.g., with `delete-region`), but that is less important. We can live with a long name.
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.Received: (at 76313) by debbugs.gnu.org; 29 Mar 2025 13:05:21 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 29 09:05:21 2025 Received: from localhost ([127.0.0.1]:57489 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tyVsH-0008EZ-88 for submit <at> debbugs.gnu.org; Sat, 29 Mar 2025 09:05:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34336) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tyVsA-0008Cq-Bl for 76313 <at> debbugs.gnu.org; Sat, 29 Mar 2025 09:05:19 -0400 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 1tyVs4-00075M-7s; Sat, 29 Mar 2025 09:05:08 -0400 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=BR2fsBhOHRVWdFBxU7WL2xf0xfgTh5yh3THALXIXGRc=; b=VqLKKQZ5pyI4 vgJYFYV20CjqHjX3KdWjQUZpRYKoc/0jM+xF1lyOD7BwWNIEi18ARZe+5NgrkkZtT80Hv7rw9uZ/W TmcY6UCv7FmbvWyC8q1pX+NUcm1HpcExOtwlhESXoRVEWmuSpyge2Nc2am6dn88JO0AzeDowq+Xt5 ZnulOPsVlzpOHz90fa1CG9hxd8V+SdeWGljpp3N6R9DW12oImK4Aq+rxAizC5Ywf5lHT899WfUNmJ yhEIpc4mbfYF02wjcw3VeEymJ/32+HJ15d9eQsCOsSpTAzD+uDyAI0GrzhXKCgJITSoHAnIcOm/ix ELhQNslz9hj9wiY8Lpf74g==; Date: Sat, 29 Mar 2025 16:05:00 +0300 Message-Id: <86a5946l8j.fsf@HIDDEN> From: Eli Zaretskii <eliz@HIDDEN> To: Stefan Kangas <stefankangas@HIDDEN> In-Reply-To: <CADwFkmn3g7q==-yjyHz7PCM2jsH7cvfktby8xeLtgPPLrNNh5Q@HIDDEN> (message from Stefan Kangas on Sat, 29 Mar 2025 05:46:51 -0700) Subject: Re: bug#76313: New function `replace-region` References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <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> <jwvr02hhi77.fsf-monnier+emacs@HIDDEN> <jwvv7rtxlmz.fsf-monnier+emacs@HIDDEN> <86r02g88e7.fsf@HIDDEN> <CADwFkmn3g7q==-yjyHz7PCM2jsH7cvfktby8xeLtgPPLrNNh5Q@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: Sat, 29 Mar 2025 05:46:51 -0700 > Cc: phst@HIDDEN, 76313 <at> debbugs.gnu.org, tsdh@HIDDEN > > Eli Zaretskii <eliz@HIDDEN> writes: > > >> From: Stefan Monnier <monnier@HIDDEN> > >> Cc: Stefan Kangas <stefankangas@HIDDEN>, phst@HIDDEN, > >> 76313 <at> debbugs.gnu.org, tsdh@HIDDEN > >> Date: Fri, 28 Mar 2025 11:38:19 -0400 > >> > >> Any chance we could consider a breaking change and force a non-nil value of > >> one of MAX-SECS or MAX-COSTS before the function is allowed to use the > >> costly algorithm? > > > > I'd prefer a completely backward-compatible change of passing a > > special value of MAX-SECS to indicate that the potentially costly > > algorithm is to be bypassed. > > We can keep trying to shoe-horn `replace-region-contents` into something > that looks like a function intended for general use, and document it as > such. If we go that route, I think it would make sense to make the > change Stefan M proposes. Can you explain why it does NOT make sense to do what I proposed? It gives us what Stefan wanted, but avoids the backward incompatibility (unless I'm missing something). > Alternatively, we let it live on as a proper citizen of subr-x.el and > consequently remove it from the manual. We've managed without > `replace-region` for decades already, so there's no urgent need to > elevate a design that has more than a few rough edges. ??? I'm confused: Stefan made replace-region-contents our preferred API, and demoted replace-buffer. Are you suggesting to do the opposite now?
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.Received: (at 76313) by debbugs.gnu.org; 29 Mar 2025 12:47:02 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 29 08:47:02 2025 Received: from localhost ([127.0.0.1]:57466 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tyVaX-0007Ic-Ng for submit <at> debbugs.gnu.org; Sat, 29 Mar 2025 08:47:02 -0400 Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]:50418) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from <stefankangas@HIDDEN>) id 1tyVaU-0007IE-Gg for 76313 <at> debbugs.gnu.org; Sat, 29 Mar 2025 08:46:59 -0400 Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-5e6f4b3ebe5so5637323a12.0 for <76313 <at> debbugs.gnu.org>; Sat, 29 Mar 2025 05:46:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743252412; x=1743857212; 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=wb7lc/70J9j8X+JaKK3CCT3svmaAtKAVpEBSFXYihrA=; b=lTZ47D7WlqxAhtURy1CqySrVPkvI80Xi/wpTMFPUMxun/ou9xhdoB+PnxeoRzYSlh6 jNFiSgom5hAP++4vB5CNZppbWXO3gNHn5CWs9g6llzqzKGm+dxan3anFVRNWF8JRHFB6 FO3BR6CbR21tUqBavCP7txtWP1ijiXDuhGtAomv46ubNcuHGdc+ve3nCvUfWFZs4Kpl0 OCFThiAD7SmhGwndm5pxKaBqBskhHTuDlxuUupRAiQKISzg3jC9ldbQjyW3g4GSTHd3T ZPQW3oN3/7efFlhJJYbYrmMuZT1RQW5QOAH8U6j/VBo97iCKJKlkx0pkIeEfSEX4hyiG JY6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743252412; x=1743857212; 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=wb7lc/70J9j8X+JaKK3CCT3svmaAtKAVpEBSFXYihrA=; b=Emqz9EeCFaEmYqe/fJpkJuwJzokVE7JRm16lSZoMSF/gH971nkCdQ0xeFUxZW4HYeV WEeDzp9vYyuFBh8Inrh975g8ThXl2kZY9gsx8t7K6qXBzLKH35KekjE+ecYjp2Lhpkty byUlAYC9obBmdfCA2c9eg87WRBkSuO7CFG4fG1o33oUO+bJGeZWL2qaQ2tC1oFYLm1Mb 9H58ckQTzvmmMqhlS6ELA1AVeYaiYeB06TGCHf4+RiZQPApxpDeO3aOmYrOncwUFdg6b mRXmZ8g01pkyx19312t/BH1sNsj10uhGwUB3NPgBc+SCwlDpow6X3nVTsjk+6CpfFT29 gZTg== X-Forwarded-Encrypted: i=1; AJvYcCWrFlIDeT7s1uNEYdnmhwdgN2X1I7iLTuGfju2P0YyAZUTXTS0Y1YlKS+WuWwSaoZOSmMhAcQ==@debbugs.gnu.org X-Gm-Message-State: AOJu0YzwxpqgIObsVDCfA0wge6mkZNR9b0Vw/0+WUyU59TgvLwWz/27J Tp3dm9Gcl283NJCM2VE2sTn3S5+ZU6/A/wY024DNznoElhnHdjYRz4zqS/WEJTzbDRseh5ivzXQ s4WaKEQz8ocUaw7BgpxWFh9PB+r0= X-Gm-Gg: ASbGncsZyvlRJ31fCFC3tStDNFjn4lDutG8BJ32bCIRuIJbdO5FTxQKxVdZVwUbidxr nSw2ePVu8jQTe/2zBUX3CxS9n/VqMLh8hzrKcLtwQPwuB7C3mHH5DADTw2XT9NIsgQQ/3wU40OG jKzW/JzeNYUCmILRQPBk5KXe+3vjE3in6/vffGBg== X-Google-Smtp-Source: AGHT+IFsZ2YEhf/obu3xHx8/CrlegaeNwtxbHaj8YYhmIJH+PZ3g97qagLP3IPF6bn/+NqrjDLS8WbFW4Ak+GAxk8GU= X-Received: by 2002:a05:6402:2744:b0:5ed:79cb:116f with SMTP id 4fb4d7f45d1cf-5edfdafccefmr2399714a12.25.1743252412331; Sat, 29 Mar 2025 05:46:52 -0700 (PDT) Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Sat, 29 Mar 2025 05:46:51 -0700 From: Stefan Kangas <stefankangas@HIDDEN> In-Reply-To: <86r02g88e7.fsf@HIDDEN> References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <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> <jwvr02hhi77.fsf-monnier+emacs@HIDDEN> <jwvv7rtxlmz.fsf-monnier+emacs@HIDDEN> <86r02g88e7.fsf@HIDDEN> MIME-Version: 1.0 Date: Sat, 29 Mar 2025 05:46:51 -0700 X-Gm-Features: AQ5f1JoZL2ZfT2xcO6m4YuRPCKTRa7tH6YuWRs1YJJohV0jUGJfTwFGMAP1NQQI Message-ID: <CADwFkmn3g7q==-yjyHz7PCM2jsH7cvfktby8xeLtgPPLrNNh5Q@HIDDEN> Subject: Re: bug#76313: New function `replace-region` To: Eli Zaretskii <eliz@HIDDEN>, Stefan Monnier <monnier@HIDDEN> Content-Type: text/plain; charset="UTF-8" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 76313 Cc: phst@HIDDEN, 76313 <at> debbugs.gnu.org, 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 Monnier <monnier@HIDDEN> >> Cc: Stefan Kangas <stefankangas@HIDDEN>, phst@HIDDEN, >> 76313 <at> debbugs.gnu.org, tsdh@HIDDEN >> Date: Fri, 28 Mar 2025 11:38:19 -0400 >> >> Any chance we could consider a breaking change and force a non-nil value of >> one of MAX-SECS or MAX-COSTS before the function is allowed to use the >> costly algorithm? > > I'd prefer a completely backward-compatible change of passing a > special value of MAX-SECS to indicate that the potentially costly > algorithm is to be bypassed. We can keep trying to shoe-horn `replace-region-contents` into something that looks like a function intended for general use, and document it as such. If we go that route, I think it would make sense to make the change Stefan M proposes. Alternatively, we let it live on as a proper citizen of subr-x.el and consequently remove it from the manual. We've managed without `replace-region` for decades already, so there's no urgent need to elevate a design that has more than a few rough edges. Personally, I'd prefer the latter, to avoid encouraging wider use of an interface that might not yet be fully thought through.
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.Received: (at 76313) by debbugs.gnu.org; 29 Mar 2025 09:59:45 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 29 05:59:45 2025 Received: from localhost ([127.0.0.1]:56964 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tySye-0006O2-TP for submit <at> debbugs.gnu.org; Sat, 29 Mar 2025 05:59:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51420) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tySyc-0006Ng-0p for 76313 <at> debbugs.gnu.org; Sat, 29 Mar 2025 05:59:42 -0400 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 1tySyW-0001nF-HI; Sat, 29 Mar 2025 05:59:36 -0400 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=UnKcAMs9Kpykxuw66qMq4wtZtm9ymatoyDvneoMfx1s=; b=KPmkCPvv6/q0 u9NKj2yZr4QmOL2AzJ45RYnTbSQ3+9Oi1frY0hva/OpKH6YcoRJ1pFJ1NyVO2glcc0iPhyz7CPKnQ CKDb3YJcppS89N5gGoR8iXc0JlSh/9+zIyq8WP1RBqRCJaxhHVXCeEZFBR8lxBhibukdylj+CmAxh pG2q6P5hFA2KLP4//zQf93KsW1xEFuamBNPb43XUqZKrXfoTMrq1X7yWdR6VLHSkMirLeUKOT2NHA /qyu3NjwDO+sLxI3T4gcdicU0QOESmn4C8jkIHKEcQDoWqoR5GmNuUoeKfBKdsT8GEaWbz5l+Diu/ UIyQHrGzIkgRkfxzeKILaA==; Date: Sat, 29 Mar 2025 12:59:28 +0300 Message-Id: <86r02g88e7.fsf@HIDDEN> From: Eli Zaretskii <eliz@HIDDEN> To: Stefan Monnier <monnier@HIDDEN> In-Reply-To: <jwvv7rtxlmz.fsf-monnier+emacs@HIDDEN> (message from Stefan Monnier on Fri, 28 Mar 2025 11:38:19 -0400) Subject: Re: bug#76313: New function `replace-region` References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <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> <jwvr02hhi77.fsf-monnier+emacs@HIDDEN> <jwvv7rtxlmz.fsf-monnier+emacs@HIDDEN> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 76313 Cc: phst@HIDDEN, 76313 <at> debbugs.gnu.org, stefankangas@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 Monnier <monnier@HIDDEN> > Cc: Stefan Kangas <stefankangas@HIDDEN>, phst@HIDDEN, > 76313 <at> debbugs.gnu.org, tsdh@HIDDEN > Date: Fri, 28 Mar 2025 11:38:19 -0400 > > Any chance we could consider a breaking change and force a non-nil value of > one of MAX-SECS or MAX-COSTS before the function is allowed to use the > costly algorithm? I'd prefer a completely backward-compatible change of passing a special value of MAX-SECS to indicate that the potentially costly algorithm is to be bypassed.
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.Received: (at 76313) by debbugs.gnu.org; 29 Mar 2025 09:49:47 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 29 05:49:47 2025 Received: from localhost ([127.0.0.1]:56923 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tySp0-0005sT-V8 for submit <at> debbugs.gnu.org; Sat, 29 Mar 2025 05:49:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59016) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tySox-0005sF-LF for 76313 <at> debbugs.gnu.org; Sat, 29 Mar 2025 05:49:44 -0400 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 1tySor-0000nG-U9; Sat, 29 Mar 2025 05:49:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=Trbx8TasYsxABPVqzs89ABgmoEESwBXVv1INRxFx3YY=; b=cyOEaxnBTt1R5NS+2ykF kQgfQm5DznKWCZs+YuYDqczaFohGKjbqDTs6ApUOdaL9wOUJMTQ12rT4x+BrNnGb0lpZGSN+syaQE 8oeA2vBhNpzkenVt3xIYGqLIUSpgYV81uSX7lRdnGGkKGVm5Bta0NkpJEc0Og48989+E2xpHhKVD9 dQ0FmTq0BQHV07ihSvmlAAvOaWf1gkklsDGsl6Px0c/8b3osgGRcgirztdJ0h8XfQsXpczL0L5avC WpjVbvFVOKXCvwOKsQ6bu5Nrq7qY1cL8J8Lx5+HCUADRjDXzIGebC1ZYVJAy9RFXGOxi0DVQLhFwA VE7krai5lJnaYw==; Date: Sat, 29 Mar 2025 12:49:33 +0300 Message-Id: <86semw88uq.fsf@HIDDEN> From: Eli Zaretskii <eliz@HIDDEN> To: Stefan Monnier <monnier@HIDDEN> In-Reply-To: <jwvr02hhi77.fsf-monnier+emacs@HIDDEN> (message from Stefan Monnier on Fri, 28 Mar 2025 00:56:45 -0400) 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> <jwvr02hhi77.fsf-monnier+emacs@HIDDEN> MIME-version: 1.0 Content-type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 76313 Cc: phst@HIDDEN, 76313 <at> debbugs.gnu.org, stefankangas@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 Monnier <monnier@HIDDEN> > Cc: Stefan Kangas <stefankangas@HIDDEN>, phst@HIDDEN, > 76313 <at> debbugs.gnu.org, tsdh@HIDDEN > Date: Fri, 28 Mar 2025 00:56:45 -0400 > > I just pushed to `scratch/replace-region-contents` a small series of > patches which consolidate `replace-buffer-contents` and > `replace-region-contents`, marking `replace-buffer-contents` as obsolete > and making `replace-region-contents` usable as a replacement for the > `replace-region` I'd still prefer (the difference is just a mere > `-contents` plus an extra `0` argument, but as argued here before, this > sets a trap for the unwary user who may unwittingly end up calling > a very expensive function). Thanks, a few comments below. > +@defun replace-region-contents beg end source &optional max-secs max-costs inherit > +This function replaces the region between @var{beg} and @var{end} > +of the current buffer with the text found in @var{source} which > +is usually a string or a buffer, in which case it will use the > +accessible portion of that buffer. > > This function attempts to keep point, markers, text properties, and > overlays in the current buffer intact. One potential case where this > -behavior is useful is external code formatting programs: they > -typically write the reformatted text into a temporary buffer or file, > -and using @code{delete-region} and @code{insert-buffer-substring} > -would destroy these properties. However, the latter combination is > -typically faster (@xref{Deletion}, and @ref{Insertion}). > - > -For its working, @code{replace-buffer-contents} needs to compare the > -contents of the original buffer with that of @var{source} which is a > -costly operation if the buffers are huge and there is a high number of > -differences between them. In order to keep > +behavior is useful is external code formatting programs: they typically > +write the reformatted text into a temporary buffer or file, and using > +@code{insert} and @code{delete-region} would destroy these properties. > + > +However, in order to do that, @code{replace-buffer-contents} needs to ^^^^^^^^^^^^^^^^^^^^^^^ The name of the function there is incorrect. > +(defun replace-buffer-contents (source &optional max-secs max-costs) > + "Replace accessible portion of current buffer with that of SOURCE. > +SOURCE can be a buffer or a string that names a buffer. > +Interactively, prompt for SOURCE. > + > +The replacement is performed using `replace-region-contents' > +which also describes the MAX-SECS and MAX-COSTS arguments and the > +return value." > + (declare (obsolete replace-region-contents "31.1")) > + (interactive "bSource buffer: ") > + (replace-region-contents (point-min) (point-max) > + (if (stringp source) (get-buffer source) source) > + max-secs max-costs)) Since this is an interactive function, shouldn't it test SOURCE to be of a valid type, instead of delegating to replace-region-contents? > +Note: If the replacement is a string, it’ll usually be placed internally > +in a temporary buffer. Therefore, if you already have the replacement > +in a buffer, it makes no sense to convert it to a string using > +‘buffer-substring’ or similar. This uses Unicode quotes in a doc string; please use ASCII characters instead. > +SOURCE can also be a function that will be called with no argument ^^^^^^^^^^^ "no arguments", right? > +and with current buffer narrowed to BEG..END and should return ^ A comma is missing there. > + b = XBUFFER (AREF (source, 0)); > + min_b = XFIXNUM (AREF (source, 1)); > + size_b = XFIXNUM (insend) - min_b; > + if (size_b < 0) > + error ("Negative sized source range"); Shouldn't we support here any order of SBEG and SEND, as we do in many other places? > + if (! (BUF_BEGV (b) <= min_b && min_b + size_b <= BUF_ZV (b))) > + args_out_of_range_3 (AREF (source, 0), AREF (source, 0), AREF (source, 1)); Should this error message show all 3 values, instead of showing one of them twice? Or maybe show BEGV, ZV, and the offending position (either SBEG or SEND)? > + bool b_empty = size_b == 0; > + if (b && !BUFFER_LIVE_P (b)) > error ("Selecting deleted buffer"); What if b is NULL? can we continue? > + /* The rest of the code is not prepared to handle a string SOURCE. */ > + if (!b) > + { > + Lisp_Object name > + = Fgenerate_new_buffer_name (build_string (" *replace-workbuf*"), Qnil); > + Lisp_Object workbuf = Fget_buffer_create (name, Qt); > + b = XBUFFER (workbuf); > + record_unwind_protect (kill_buffer, workbuf); > + record_unwind_current_buffer (); > + set_buffer_internal (b); > + Fset_buffer_multibyte (STRING_MULTIBYTE (source) ? Qt : Qnil); coding.c:code_conversion_save does something similar; perhaps some of the buffer-local settings we use there could also be a good idea here? > --- a/src/insdel.c > +++ b/src/insdel.c > @@ -1439,6 +1439,12 @@ replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new, > insbeg = 0; > inschars = SCHARS (new); > } > + else if (BUFFERP (new)) > + { > + insbuf = XBUFFER (new); > + insbeg = BUF_BEGV (insbuf); > + inschars = BUF_ZV (insbuf) - insbeg; > + } Please update the commentary to replace_range to describe this type of NEW.
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.Received: (at 76313) by debbugs.gnu.org; 28 Mar 2025 15:38:31 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Fri Mar 28 11:38:31 2025 Received: from localhost ([127.0.0.1]:55231 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tyBmw-0000w3-Uk for submit <at> debbugs.gnu.org; Fri, 28 Mar 2025 11:38:31 -0400 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:63303) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <monnier@HIDDEN>) id 1tyBmt-0000vp-Sa for 76313 <at> debbugs.gnu.org; Fri, 28 Mar 2025 11:38:29 -0400 Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 73C70100066; Fri, 28 Mar 2025 11:38:21 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1743176300; bh=/fBURxwjkD4BzK57MS20ppdCLqM0ywYXAfCdg0QWet0=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=BWzXvyKCPi+TFiSL2KtJJUSDYEMGEvpbNaKOfMRQU8pQFaPlgMdk8KuiREpWK/TYr Edl+5HyfBcsnON+R5FkW1hrE/UJEczMPaZYAT9tka0T/gg2NqNY8fzjKeLSlqp78LZ u0tLPw/CT9LRj27CrzzSoh/itVv9gooFl0Iv8xezxSPtU5gYSAh0TW59IQHpNMORMk OmV6dbovE/p5VS9UWcddc7FqbSV6Ld9qXSPFyMcU85ASRV8Dn4eod9l/EV2nNQDkxK OdJzCxSG90t1ZXDm0aF38a5iS2Mo/HmwvxtLh0CCfmPFJERAiIg9iHf7K6iJ5Ye0zh 8ozdieUTGQDwQ== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 4F725100040; Fri, 28 Mar 2025 11:38:20 -0400 (EDT) Received: from alfajor (unknown [23.233.149.155]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 23CB0120343; Fri, 28 Mar 2025 11:38:20 -0400 (EDT) From: Stefan Monnier <monnier@HIDDEN> To: Eli Zaretskii <eliz@HIDDEN> Subject: Re: bug#76313: New function `replace-region` In-Reply-To: <jwvr02hhi77.fsf-monnier+emacs@HIDDEN> Message-ID: <jwvv7rtxlmz.fsf-monnier+emacs@HIDDEN> References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <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> <jwvr02hhi77.fsf-monnier+emacs@HIDDEN> Date: Fri, 28 Mar 2025 11:38:19 -0400 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.293 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: phst@HIDDEN, 76313 <at> debbugs.gnu.org, Stefan Kangas <stefankangas@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 (---) > (the difference is just a mere `-contents` plus an extra `0` argument, > but as argued here before, this sets a trap for the unwary user who > may unwittingly end up calling a very expensive function). The main part is not the `-contents` but the extra arg needed to avoid the risk of spending half-an-hour waiting for the command to finish looking for diffs. Any chance we could consider a breaking change and force a non-nil value of one of MAX-SECS or MAX-COSTS before the function is allowed to use the costly algorithm? After all, it's a "soft breakage" since the algorithm doesn't make any promises about what is recognized as "unchanged". I took a look at the uses I could find "out there" (see below my sig) and the overwhelming impression is that the change would have a very minor impact, and of course would be easy to fix in a backward-compatible manner. [ Note that I do not suggest making a similar change to `replace-buffer-contents`. ] Stefan There are currently no uses in Emacs itself. I found one use in GNU ELPA: packages/sketch-mode/sketch-mode.el- (with-current-buffer (print (marker-buffer s)) packages/sketch-mode/sketch-mode.el- (let ((inhibit-read-only t)) packages/sketch-mode/sketch-mode.el: (replace-region-contents s e (lambda () (concat "OPACITY: " packages/sketch-mode/sketch-mode.el- (format (if sketch-opacity packages/sketch-mode/sketch-mode.el- "%.2f" packages/sketch-mode/sketch-mode.el- "%s" packages/sketch-mode/sketch-mode.el- ) packages/sketch-mode/sketch-mode.el- sketch-opacity) packages/sketch-mode/sketch-mode.el- "\n "))) packages/sketch-mode/sketch-mode.el- (put-text-property (1- e) e 'display (svg-image packages/sketch-mode/sketch-mode.el- (let* ((w 220) packages/sketch-mode/sketch-mode.el- (h (default-font-height)) packages/sketch-mode/sketch-mode.el- (half-h (/ h 2)) Having tested this code, I know that careful preservation of markers and such is of no importance so the proposed change would bring only a (minor) improvement in performance. I found one/two use in NonGNU ELPA: packages/parinfer-rust-mode/test/test-helper.el- (goto-line (+ 1 (cdr (assoc 'lineNo change))))) ;; This is normally bad, but we're just doing this in a test packages/parinfer-rust-mode/test/test-helper.el- (forward-char (cdr (assoc 'x change))) ;; and we need to go to the line specified by the current change packages/parinfer-rust-mode/test/test-helper.el: (replace-region-contents (point) packages/parinfer-rust-mode/test/test-helper.el- (+ (point) (length (cdr (assoc 'newText change)))) packages/parinfer-rust-mode/test/test-helper.el- (lambda (&rest _args) (cdr (assoc 'oldText change))))) packages/parinfer-rust-mode/test/test-helper.el- packages/parinfer-rust-mode/test/test-helper.el-(defun apply-changes-in-buffer (change) packages/parinfer-rust-mode/test/test-helper.el- "Given a list of CHANGE apply to the specified area of the buffer." packages/parinfer-rust-mode/test/test-helper.el- (with-no-warnings packages/parinfer-rust-mode/test/test-helper.el- (goto-line (+ 1 (cdr (assoc 'lineNo change))))) packages/parinfer-rust-mode/test/test-helper.el- (forward-char (cdr (assoc 'x change))) packages/parinfer-rust-mode/test/test-helper.el- (setq-local parinfer-rust--test-line-no (line-number-at-pos)) packages/parinfer-rust-mode/test/test-helper.el: (replace-region-contents (point) packages/parinfer-rust-mode/test/test-helper.el- (+ (point) (length (cdr (assoc 'oldText change)))) packages/parinfer-rust-mode/test/test-helper.el- (lambda (&rest _args) (cdr (assoc 'newText change)))) packages/parinfer-rust-mode/test/test-helper.el- (setq-local parinfer-rust--test-line-no nil)) According to my tests, this would not be adversely affected either. I found six/seven uses in MELPA: chroma-20240716.1131.tar- (match-end (match-end 0)) chroma-20240716.1131.tar- (color-string (match-string-no-properties 0))) chroma-20240716.1131.tar: (replace-region-contents (match-beginning 0) (match-end 0) chroma-20240716.1131.tar- (lambda () chroma-20240716.1131.tar- (funcall color-conversion-fn chroma-20240716.1131.tar- color-string))))))) chroma-20240716.1131.tar- (t chroma-20240716.1131.tar- (cl-multiple-value-bind (color-string start end) chroma-20240716.1131.tar- (funcall color-string-at-point-fn (point)) chroma-20240716.1131.tar: (replace-region-contents start end chroma-20240716.1131.tar- (lambda () chroma-20240716.1131.tar- (funcall color-conversion-fn chroma-20240716.1131.tar- color-string))))))))) This is in a function that replaces one color name with another and would not be significantly affected, AFAICT. ekg-20250313.436.tar-(defun ekg-edit-display-metadata () ekg-20250313.436.tar- "Create or edit the overlay to show metadata." ekg-20250313.436.tar- (let ((o (ekg--metadata-overlay)) ekg-20250313.436.tar- (inhibit-read-only t)) ekg-20250313.436.tar- (buffer-disable-undo) ekg-20250313.436.tar: (replace-region-contents (overlay-start o) (overlay-end o) ekg-20250313.436.tar- #'ekg--replace-metadata) ekg-20250313.436.tar- (goto-char (overlay-end o)) ekg-20250313.436.tar- (insert "\n") ekg-20250313.436.tar- (move-overlay o (point-min) (- (overlay-end o) 1)) AFAICT, again this wouldn't be significantly affected either. elisp-demos-20240128.810.tar-(with-temp-buffer elisp-demos-20240128.810.tar- (insert "hello") elisp-demos-20240128.810.tar: (replace-region-contents (point-min) (point-max) (lambda () '"world")) elisp-demos-20240128.810.tar- (buffer-string)) elisp-demos-20240128.810.tar-#+END_SRC elisp-demos-20240128.810.tar- elisp-demos-20240128.810.tar-#+RESULTS: elisp-demos-20240128.810.tar-: "world" elisp-demos-20240128.810.tar- Not affected. hindent-20241128.1601.tar- (progn hindent-20241128.1601.tar- (if (fboundp 'replace-region-contents) hindent-20241128.1601.tar: (replace-region-contents hindent-20241128.1601.tar- beg end (lambda () temp)) hindent-20241128.1601.tar- (let ((line (line-number-at-pos)) hindent-20241128.1601.tar- (col (current-column))) hindent-20241128.1601.tar- (delete-region beg hindent-20241128.1601.tar- end) hindent-20241128.1601.tar- (insert new-str))) hindent-20241128.1601.tar- (message "Formatted.")) hindent-20241128.1601.tar- (message "Already formatted."))))))))))) This one would be affected a bit: the package passes the region through an external indenter/prettyprinter, so the use of careful replacement to better preserves the markers in the mark-ring is relevant. As the code shows, it's not the end of the world: not only it still has the fallback insert+delete code but that fallback wasn't even careful to do the insertion before the delete. Also, this use case would be trivial to fix by passing the additional MAX-SECS argument, of course (there is no backward compatibility in this respect: all version of `replace-region-contents` have accepted the MAX-SECS arg, contrary to `replace-buffer-contents`). jet-20240730.1228.tar-(defun jet-paste-cursor (thing &optional args) jet-20240730.1228.tar- "Run jet for THING at cursor and ARGS pasting to current buffer." jet-20240730.1228.tar- (interactive (jet-menu--interactive-args)) jet-20240730.1228.tar- (let ((result (string-trim (jet-menu--run thing args)))) jet-20240730.1228.tar- (if (use-region-p) jet-20240730.1228.tar: (replace-region-contents (region-beginning) (region-end) (lambda () result)) jet-20240730.1228.tar- (insert result)))) This runs the `jet` command which converts data between different representations (JSON/EDN/Transit?), so it's similar to hindent above: it's nice to preserve things like mark-ring positions along the way, but it's not the end of the world and shouldn't result in actual breakage, just a slightly less refined behavior, which can be recovered by a trivial change to the code. org-mpv-notes-20241222.1958.tar-(defun org-mpv-notes-replace-timestamp-with-link (begin end link) org-mpv-notes-20241222.1958.tar- "Convert hh:mm:ss text within region to link with timestamp. org-mpv-notes-20241222.1958.tar-Region is between `BEGIN' and `END' points, org-mpv-notes-20241222.1958.tar-`LINK' is the new media url/path." org-mpv-notes-20241222.1958.tar- (interactive "r\nsLink:") org-mpv-notes-20241222.1958.tar- (save-excursion org-mpv-notes-20241222.1958.tar- (let (timestamp) org-mpv-notes-20241222.1958.tar- (setq link (org-link-escape link)) org-mpv-notes-20241222.1958.tar- (goto-char end) org-mpv-notes-20241222.1958.tar- (while (re-search-backward "[^0-9]\\([0-9]+:[0-9]+:[0-9]+\\)" begin t) org-mpv-notes-20241222.1958.tar- (setq timestamp (match-string 1)) org-mpv-notes-20241222.1958.tar: (replace-region-contents (match-beginning 1) (match-end 1) org-mpv-notes-20241222.1958.tar- (lambda () (concat "[[mpv:" link "::" timestamp "][" timestamp "]]"))) org-mpv-notes-20241222.1958.tar- (search-backward "[[" begin t))))) AFAICT this code should not affected by my proposed change.
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.Received: (at 76313) by debbugs.gnu.org; 28 Mar 2025 04:57:05 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Fri Mar 28 00:57:05 2025 Received: from localhost ([127.0.0.1]:52320 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1ty1mB-000326-Ew for submit <at> debbugs.gnu.org; Fri, 28 Mar 2025 00:57:05 -0400 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:8110) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <monnier@HIDDEN>) id 1ty1m7-00031R-LI for 76313 <at> debbugs.gnu.org; Fri, 28 Mar 2025 00:57:01 -0400 Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 13DB244014D; Fri, 28 Mar 2025 00:56:53 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1743137806; bh=xbPjMZzaRMAO6m07Xe8NQwKKaHJYKxci+33yDT0jEMs=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=MDzqxxnfAq6dUrONEWGQYlX686SUb2V4gqLPEON53hxOHNvYZDEyIcAHaswyb8kjJ MZBVSG/eT9gv2DXdZXxLl5FKHGRV1zScEvZWw0ZKp9ELOkaqx8Ex5QXFX06RHq0+jw fsWtiTceNhcapxAUTlfdvIl8kxHP0gQ/kZTPjXIA1ubMQADy1O5+iGGTFZJ964f6Ab dh/hL7QxsSFktf+4p9ZLQZ2aDwZ14RZdvp/8lccOzn+hKpD8oHZvSVjzUl9MlVUfj9 junrfZwsgx2eQRDH3fLNynrk6w3cHVsIdGeDNhYBRNxYxzjNJF4xCOE+LUR8cpmV8a 1rhKvVwqvrFYw== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id D0BE344020C; Fri, 28 Mar 2025 00:56:46 -0400 (EDT) Received: from pastel (unknown [104.247.242.5]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 8B8C31203C3; Fri, 28 Mar 2025 00:56:46 -0400 (EDT) From: Stefan Monnier <monnier@HIDDEN> To: Eli Zaretskii <eliz@HIDDEN> Subject: Re: bug#76313: New function `replace-region` In-Reply-To: <864j07pqh7.fsf@HIDDEN> Message-ID: <jwvr02hhi77.fsf-monnier+emacs@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> Date: Fri, 28 Mar 2025 00:56:45 -0400 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.393 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: phst@HIDDEN, 76313 <at> debbugs.gnu.org, Stefan Kangas <stefankangas@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 (---) --=-=-= Content-Type: text/plain I just pushed to `scratch/replace-region-contents` a small series of patches which consolidate `replace-buffer-contents` and `replace-region-contents`, marking `replace-buffer-contents` as obsolete and making `replace-region-contents` usable as a replacement for the `replace-region` I'd still prefer (the difference is just a mere `-contents` plus an extra `0` argument, but as argued here before, this sets a trap for the unwary user who may unwittingly end up calling a very expensive function). The first patch is the one which makes the actual change the subsequent patches just change other code to use the new functionality. Stefan --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: inline; filename=0001-replace-region-contents-Improve-and-promote-bug-7631.patch Content-Transfer-Encoding: quoted-printable From 0dfaa9633304e7529571a765dd2c6a49f84768cb Mon Sep 17 00:00:00 2001 From: Stefan Monnier <monnier@HIDDEN> Date: Fri, 28 Mar 2025 00:46:53 -0400 Subject: [PATCH 1/3] (replace-region-contents): Improve and promote (bug#76313) Swap the role of `replace-region-contents` and `replace-buffer-contents`, so `replace-region-contents` is the main function, implemented in C, and `replace-buffer-contents` is a mere wrapper (marked as obsolete). Also remove the need to rely on narrowing and on describing the new text as a function. Finally, allow MAX-SECS=3D=3D0 to require a cheap replacement, and add an INHERIT argument. * src/editfns.c (kill_buffer): New function. (Freplace_region_contents): Rename from `Freplace_buffer_contents`. Change calling convention to that of `replace-region-contents`. Add more options for the SOURCE argument. Add INHERIT argument. Skip the costly algorithm if MAX-SECS is 0. * src/insdel.c (replace_range): Allow NEW to be a buffer. * lisp/subr.el (replace-buffer-contents): New implementation. * lisp/emacs-lisp/subr-x.el (replace-region-contents): Delete. * doc/lispref/text.texi (Replacing): Document new API for `replace-region-contents`. Remove documentation of `replace-buffer-contents`. * test/src/editfns-tests.el (replace-buffer-contents-1) (replace-buffer-contents-2, replace-buffer-contents-bug31837): Use `replace-region-contents`. (editfns--replace-region): Delete. (editfns-tests--replace-region): Use `replace-region-contents`. Adds tests for new types of SOURCE args. --- doc/lispref/text.texi | 70 ++++++++--------- etc/NEWS | 7 ++ lisp/emacs-lisp/subr-x.el | 29 ------- lisp/subr.el | 14 ++++ src/editfns.c | 154 +++++++++++++++++++++++++++----------- src/insdel.c | 6 ++ test/src/editfns-tests.el | 68 ++++++++--------- 7 files changed, 205 insertions(+), 143 deletions(-) diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi index 18ed71fd1f5..6bf2e616bc8 100644 --- a/doc/lispref/text.texi +++ b/doc/lispref/text.texi @@ -4776,29 +4776,41 @@ Transposition @node Replacing @section Replacing Buffer Text =20 - You can use the following function to replace the text of one buffer -with the text of another buffer: + You can use the following function to replace some the text of the +current buffer: =20 -@deffn Command replace-buffer-contents source &optional max-secs max-costs -This function replaces the accessible portion of the current buffer -with the accessible portion of the buffer @var{source}. @var{source} -may either be a buffer object or the name of a buffer. When -@code{replace-buffer-contents} succeeds, the text of the accessible -portion of the current buffer will be equal to the text of the -accessible portion of the @var{source} buffer. +@defun replace-region-contents beg end source &optional max-secs max-costs= inherit +This function replaces the region between @var{beg} and @var{end} +of the current buffer with the text found in @var{source} which +is usually a string or a buffer, in which case it will use the +accessible portion of that buffer. =20 This function attempts to keep point, markers, text properties, and overlays in the current buffer intact. One potential case where this -behavior is useful is external code formatting programs: they -typically write the reformatted text into a temporary buffer or file, -and using @code{delete-region} and @code{insert-buffer-substring} -would destroy these properties. However, the latter combination is -typically faster (@xref{Deletion}, and @ref{Insertion}). - -For its working, @code{replace-buffer-contents} needs to compare the -contents of the original buffer with that of @var{source} which is a -costly operation if the buffers are huge and there is a high number of -differences between them. In order to keep +behavior is useful is external code formatting programs: they typically +write the reformatted text into a temporary buffer or file, and using +@code{insert} and @code{delete-region} would destroy these properties. + +However, in order to do that, @code{replace-buffer-contents} needs to +compare the contents of the original buffer with that of @var{source}, +using a costly algorithm which makes the operation much slower than +a simple @code{insert} and @code{delete-region}. In many cases, you may +not need that refinement, and you will then want to pass 0 as +@var{max-secs} argument, so as to short-circuit that costly algorithm: +It will then be just as fast as @code{insert} and @code{delete-region} +while still preserving point and markers marginally better. + +Beyond that basic usage, if you need to use as source a subset of the +accessible portion of a buffer, @var{source} can also be a vector +@code{[@var{sbuf} @var{sbeg} @var{send}]} where the region between +@var{sbeg} and @var{send} in buffer @var{sbuf} is the text +you want to use as source. + +If you need the inserted text to inherit text-properties +from the adjoining text, you can pass a non-@code{nil} value as +@var{inherit} argument. + +When you do want the costly refined replacement, in order to keep @code{replace-buffer-contents}'s runtime in bounds, it has two optional arguments. =20 @@ -4813,23 +4825,11 @@ Replacing @code{replace-buffer-contents} returns @code{t} if a non-destructive replacement could be performed. Otherwise, i.e., if @var{max-secs} was exceeded, it returns @code{nil}. -@end deffn =20 -@defun replace-region-contents beg end replace-fn &optional max-secs max-c= osts -This function replaces the region between @var{beg} and @var{end} -using the given @var{replace-fn}. The function @var{replace-fn} is -run in the current buffer narrowed to the specified region and it -should return either a string or a buffer replacing the region. - -The replacement is performed using @code{replace-buffer-contents} (see -above) which also describes the @var{max-secs} and @var{max-costs} -arguments and the return value. - -Note: If the replacement is a string, it will be placed in a temporary -buffer so that @code{replace-buffer-contents} can operate on it. -Therefore, if you already have the replacement in a buffer, it makes -no sense to convert it to a string using @code{buffer-substring} or -similar. +Note: When using the refined replacement algorithm, if the replacement +is a string, it will be internally copied to a temporary buffer. +Therefore, all else being equal, it is preferable to pass a buffer than +a string as @var{source} argument. @end defun =20 @node Decompression diff --git a/etc/NEWS b/etc/NEWS index 1bd2fd6d486..8832873a7dd 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1713,6 +1713,13 @@ Previously, its argument was always evaluated using = dynamic binding. * Lisp Changes in Emacs 31.1 =20 ++++ +** Improve 'replace-region-contents' to accept more forms of sources. +It has been promoted from 'subr-x' to the C code. +You can now directly pass it a string or a buffer rather than a function. +Actually passing it a function is now deprecated. +'replace-buffer-contents' is also marked as obsolete. + +++ ** New macros 'static-when' and 'static-unless'. Like 'static-if', these macros evaluate their condition at diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el index 6414ecab394..eaa8119ead7 100644 --- a/lisp/emacs-lisp/subr-x.el +++ b/lisp/emacs-lisp/subr-x.el @@ -281,35 +281,6 @@ string-chop-newline (declare (pure t) (side-effect-free t)) (string-remove-suffix "\n" string)) =20 -(defun replace-region-contents (beg end replace-fn - &optional max-secs max-costs) - "Replace the region between BEG and END using REPLACE-FN. -REPLACE-FN runs on the current buffer narrowed to the region. It -should return either a string or a buffer replacing the region. - -The replacement is performed using `replace-buffer-contents' -which also describes the MAX-SECS and MAX-COSTS arguments and the -return value. - -Note: If the replacement is a string, it'll be placed in a -temporary buffer so that `replace-buffer-contents' can operate on -it. Therefore, if you already have the replacement in a buffer, -it makes no sense to convert it to a string using -`buffer-substring' or similar." - (save-excursion - (save-restriction - (narrow-to-region beg end) - (goto-char (point-min)) - (let ((repl (funcall replace-fn))) - (if (bufferp repl) - (replace-buffer-contents repl max-secs max-costs) - (let ((source-buffer (current-buffer))) - (with-temp-buffer - (insert repl) - (let ((tmp-buffer (current-buffer))) - (set-buffer source-buffer) - (replace-buffer-contents tmp-buffer max-secs max-costs))))))))) - ;;;###autoload (defmacro named-let (name bindings &rest body) "Looping construct taken from Scheme. diff --git a/lisp/subr.el b/lisp/subr.el index af9289c0216..abdac1080cb 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -7497,6 +7497,20 @@ delete-line "Delete the current line." (delete-region (pos-bol) (pos-bol 2))) =20 +(defun replace-buffer-contents (source &optional max-secs max-costs) + "Replace accessible portion of current buffer with that of SOURCE. +SOURCE can be a buffer or a string that names a buffer. +Interactively, prompt for SOURCE. + +The replacement is performed using `replace-region-contents' +which also describes the MAX-SECS and MAX-COSTS arguments and the +return value." + (declare (obsolete replace-region-contents "31.1")) + (interactive "bSource buffer: ") + (replace-region-contents (point-min) (point-max) + (if (stringp source) (get-buffer source) source) + max-secs max-costs)) + (defun ensure-empty-lines (&optional lines) "Ensure that there are LINES number of empty lines before point. If LINES is nil or omitted, ensure that there is a single empty diff --git a/src/editfns.c b/src/editfns.c index 53d6cce7c82..5dbc39767d5 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -1914,11 +1914,20 @@ #define EARLY_ABORT(ctx) compareseq_early_abort (ct= x) #include "minmax.h" #include "diffseq.h" =20 -DEFUN ("replace-buffer-contents", Freplace_buffer_contents, - Sreplace_buffer_contents, 1, 3, "bSource buffer: ", - doc: /* Replace accessible portion of current buffer with that of S= OURCE. -SOURCE can be a buffer or a string that names a buffer. -Interactively, prompt for SOURCE. +static void +kill_buffer (Lisp_Object buf) +{ + Fkill_buffer (buf); +} + +DEFUN ("replace-region-contents", Freplace_region_contents, + Sreplace_region_contents, 3, 6, 0, + doc: /* Replace the region between BEG and END with that of SOURCE. +SOURCE can be a buffer, a string, or a vector [SBUF SBEG SEND] +denoting the subtring SBEG..SEND of buffer SBUF. + +If optional argument INHERIT is non-nil, the inserted text will inherit +properties from adjoining text. =20 As far as possible the replacement is non-destructive, i.e. existing buffer contents, markers, properties, and overlays in the current @@ -1940,18 +1949,86 @@ DEFUN ("replace-buffer-contents", Freplace_buffer_c= ontents, used to provide a faster but suboptimal solution. The default value is 1000000. =20 +Note: If the replacement is a string, it=E2=80=99ll usually be placed inte= rnally +in a temporary buffer. Therefore, if you already have the replacement +in a buffer, it makes no sense to convert it to a string using +=E2=80=98buffer-substring=E2=80=99 or similar. + This function returns t if a non-destructive replacement could be performed. Otherwise, i.e., if MAX-SECS was exceeded, it returns -nil. */) - (Lisp_Object source, Lisp_Object max_secs, Lisp_Object max_costs) +nil. + +SOURCE can also be a function that will be called with no argument +and with current buffer narrowed to BEG..END and should return +a buffer or a string. But this is deprecated. */) + (Lisp_Object beg, Lisp_Object end, Lisp_Object source, + Lisp_Object max_secs, Lisp_Object max_costs, Lisp_Object inherit) { - struct buffer *a =3D current_buffer; - Lisp_Object source_buffer =3D Fget_buffer (source); - if (NILP (source_buffer)) - nsberror (source); - struct buffer *b =3D XBUFFER (source_buffer); - if (! BUFFER_LIVE_P (b)) + validate_region (&beg, &end); + ptrdiff_t min_a =3D XFIXNUM (beg); + ptrdiff_t size_a =3D XFIXNUM (end) - min_a; + eassume (size_a >=3D 0); + bool a_empty =3D size_a =3D=3D 0; + bool inh =3D !NILP (inherit); + + if (FUNCTIONP (source)) + { + specpdl_ref count =3D SPECPDL_INDEX (); + record_unwind_protect (save_restriction_restore, + save_restriction_save ()); + Fnarrow_to_region (beg, end); + source =3D calln (source); + unbind_to (count, Qnil); + } + ptrdiff_t min_b, size_b; + struct buffer *b; + if (STRINGP (source)) + { + min_b =3D BEG; /* Assuming we'll copy it into a buffer. */ + size_b =3D SCHARS (source); + b =3D NULL; + } + else if (BUFFERP (source)) + { + b =3D XBUFFER (source); + min_b =3D BUF_BEGV (b); + size_b =3D BUF_ZV (b) - min_b; + } + else + { + CHECK_TYPE (VECTORP (source), + list (Qor, Qstring, Qbuffer, Qvector), source); + /* Let `Faref' signal an error if it's too small. */ + Lisp_Object insend =3D Faref (source, make_fixnum (2)); + CHECK_BUFFER (AREF (source, 0)); + CHECK_FIXNUM (AREF (source, 1)); + CHECK_FIXNUM (insend); + b =3D XBUFFER (AREF (source, 0)); + min_b =3D XFIXNUM (AREF (source, 1)); + size_b =3D XFIXNUM (insend) - min_b; + if (size_b < 0) + error ("Negative sized source range"); + if (! (BUF_BEGV (b) <=3D min_b && min_b + size_b <=3D BUF_ZV (b))) + args_out_of_range_3 (AREF (source, 0), AREF (source, 0), AREF (source, 1)= ); + } + bool b_empty =3D size_b =3D=3D 0; + if (b && !BUFFER_LIVE_P (b)) error ("Selecting deleted buffer"); + + /* Handle trivial cases where at least one accessible portion is + empty. */ + + if (a_empty && b_empty) + return Qt; + else if (a_empty || b_empty + || EQ (max_secs, make_fixnum (0)) + || EQ (max_costs, make_fixnum (0))) + { + replace_range (min_a, min_a + size_a, source, true, false, inh); + return Qt; + } + + struct buffer *a =3D current_buffer; if (a =3D=3D b) error ("Cannot replace a buffer with itself"); =20 @@ -1977,36 +2054,8 @@ DEFUN ("replace-buffer-contents", Freplace_buffer_co= ntents, time_limit =3D tlim; } =20 - ptrdiff_t min_a =3D BEGV; - ptrdiff_t min_b =3D BUF_BEGV (b); - ptrdiff_t size_a =3D ZV - min_a; - ptrdiff_t size_b =3D BUF_ZV (b) - min_b; - eassume (size_a >=3D 0); - eassume (size_b >=3D 0); - bool a_empty =3D size_a =3D=3D 0; - bool b_empty =3D size_b =3D=3D 0; - - /* Handle trivial cases where at least one accessible portion is - empty. */ - - if (a_empty && b_empty) - return Qt; - - if (a_empty) - { - Finsert_buffer_substring (source, Qnil, Qnil); - return Qt; - } - - if (b_empty) - { - del_range_both (BEGV, BEGV_BYTE, ZV, ZV_BYTE, true); - return Qt; - } - specpdl_ref count =3D SPECPDL_INDEX (); =20 - ptrdiff_t diags =3D size_a + size_b + 3; ptrdiff_t del_bytes =3D size_a / CHAR_BIT + 1; ptrdiff_t ins_bytes =3D size_b / CHAR_BIT + 1; @@ -2020,6 +2069,22 @@ DEFUN ("replace-buffer-contents", Freplace_buffer_co= ntents, unsigned char *deletions_insertions =3D memset (buffer + 2 * diags, 0, del_bytes + ins_bytes); =20 + /* The rest of the code is not prepared to handle a string SOURCE. */ + if (!b) + { + Lisp_Object name + =3D Fgenerate_new_buffer_name (build_string (" *replace-workbuf*"), Qnil); + Lisp_Object workbuf =3D Fget_buffer_create (name, Qt); + b =3D XBUFFER (workbuf); + record_unwind_protect (kill_buffer, workbuf); + record_unwind_current_buffer (); + set_buffer_internal (b); + Fset_buffer_multibyte (STRING_MULTIBYTE (source) ? Qt : Qnil); + CALLN (Finsert, source); + set_buffer_internal (a); + } + Lisp_Object source_buffer =3D make_lisp_ptr (b, Lisp_Vectorlike); + /* FIXME: It is not documented how to initialize the contents of the context structure. This code cargo-cults from the existing caller in src/analyze.c of GNU Diffutils, which appears to @@ -2053,7 +2118,7 @@ DEFUN ("replace-buffer-contents", Freplace_buffer_con= tents, Lisp_Object src =3D CALLN (Fvector, source_buffer, make_fixnum (BUF_BEGV (b)), make_fixnum (BUF_ZV (b))); - replace_range (BEGV, ZV, src, true, false, false); + replace_range (BEGV, ZV, src, true, false, inh); SAFE_FREE_UNBIND_TO (count, Qnil); return Qnil; } @@ -2102,10 +2167,9 @@ DEFUN ("replace-buffer-contents", Freplace_buffer_co= ntents, eassert (beg_a <=3D end_a); eassert (beg_b <=3D end_b); eassert (beg_a < end_a || beg_b < end_b); - /* FIXME: Use 'replace_range'! */ ASET (src, 1, make_fixed_natnum (beg_b)); ASET (src, 2, make_fixed_natnum (end_b)); - replace_range (beg_a, end_a, src, true, false, false); + replace_range (beg_a, end_a, src, true, false, inh); } --i; --j; @@ -4787,7 +4851,7 @@ syms_of_editfns (void) =20 defsubr (&Sinsert_buffer_substring); defsubr (&Scompare_buffer_substrings); - defsubr (&Sreplace_buffer_contents); + defsubr (&Sreplace_region_contents); defsubr (&Ssubst_char_in_region); defsubr (&Stranslate_region_internal); defsubr (&Sdelete_region); diff --git a/src/insdel.c b/src/insdel.c index 9b770725971..22b6c3e974a 100644 --- a/src/insdel.c +++ b/src/insdel.c @@ -1439,6 +1439,12 @@ replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Ob= ject new, insbeg =3D 0; inschars =3D SCHARS (new); } + else if (BUFFERP (new)) + { + insbuf =3D XBUFFER (new); + insbeg =3D BUF_BEGV (insbuf); + inschars =3D BUF_ZV (insbuf) - insbeg; + } else { CHECK_VECTOR (new); diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el index c3f825c6149..3da9d4e8acd 100644 --- a/test/src/editfns-tests.el +++ b/test/src/editfns-tests.el @@ -289,7 +289,7 @@ replace-buffer-contents-1 (narrow-to-region 8 13) (goto-char 12) (should (looking-at " \\'")) - (replace-buffer-contents source) + (replace-region-contents (point-min) (point-max) source) (should (looking-at " \\'"))) (should (equal (marker-buffer marker) (current-buffer))) (should (equal (marker-position marker) 16))) @@ -306,7 +306,7 @@ replace-buffer-contents-2 (let ((source (current-buffer))) (with-temp-buffer (insert "foo BAR baz qux") - (replace-buffer-contents source) + (replace-region-contents (point-min) (point-max) source) (should (equal-including-properties (buffer-string) "foo bar baz qux")))))) @@ -318,44 +318,44 @@ replace-buffer-contents-bug31837 (switch-to-buffer "b") (insert-char (char-from-name "SMILE")) (insert "5678") - (replace-buffer-contents "a") + (replace-region-contents (point-min) (point-max) (get-buffer "a")) (should (equal (buffer-substring-no-properties (point-min) (point-max)) (concat (string (char-from-name "SMILE")) "1234")))) =20 -(defun editfns--replace-region (from to string) - (save-excursion - (save-restriction - (narrow-to-region from to) - (let ((buf (current-buffer))) - (with-temp-buffer - (let ((str-buf (current-buffer))) - (insert string) - (with-current-buffer buf - (replace-buffer-contents str-buf)))))))) - (ert-deftest editfns-tests--replace-region () ;; :expected-result :failed (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))) - (editfns--replace-region (+ (point-min) 5) (+ (point-min) 7) "be") - (should (equal (buffer-string) "here be some text")) - (should (equal (point) (point-max))) - ;; Markers before the replaced text stay before. - (should (=3D m5n (+ (point-min) 5))) - (should (=3D 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 (=3D m6n (+ (point-min) 5))) - (should (<=3D (+ (point-min) 5) m6a (+ (point-min) 7))) - ;; Markers after the replaced text stay after. - (should (=3D m7n (+ (point-min) 7))) - (should (=3D m7a (+ (point-min) 7)))))) + (let ((tmpbuf (current-buffer))) + (insert " be ") + (narrow-to-region (+ (point-min) 2) (- (point-max) 2)) + (dolist (args `((,tmpbuf) + (,(vector tmpbuf (point-min) (point-max))) + (,"be") + (,(vector tmpbuf (point-min) (point-max)) 0) + (,"be" 0))) + (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))) + (apply #'replace-region-contents + (+ (point-min) 5) (+ (point-min) 7) args) + (should (equal (buffer-string) "here be some text")) + (should (equal (point) (point-max))) + ;; Markers before the replaced text stay before. + (should (=3D m5n (+ (point-min) 5))) + (should (=3D m5a (+ (point-min) 5))) + ;; Markers in the replaced text can end up at either end, depe= nding + ;; on whether they're advance-after-insert or not. + (should (=3D m6n (+ (point-min) 5))) + (should (<=3D (+ (point-min) 5) m6a (+ (point-min) 7))) + ;; Markers after the replaced text stay after. + (should (=3D m7n (+ (point-min) 7))) + (should (=3D m7a (+ (point-min) 7))))) + (widen))))) =20 (ert-deftest delete-region-undo-markers-1 () "Make sure we don't end up with freed markers reachable from Lisp." --=20 2.39.5 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0002-Use-the-new-replace-region-contents.patch From 8a80713a71271130df9d8029a007827da477b88d Mon Sep 17 00:00:00 2001 From: Stefan Monnier <monnier@HIDDEN> Date: Fri, 28 Mar 2025 00:48:28 -0400 Subject: [PATCH 2/3] Use the new `replace-region-contents` * lisp/vc/vc.el (vc-diff-restore-buffer): * lisp/progmodes/python.el (python--do-isort): * lisp/progmodes/eglot.el (eglot--apply-text-edits): * lisp/minibuffer.el (completion--replace): * lisp/help-fns.el (help-fns--signature): * lisp/files.el (revert-buffer-insert-file-contents-delicately): * lisp/emacs-lisp/cl-lib.el (cl--set-buffer-substring): * lisp/json.el (json-pretty-print): Use `replace-region-contents`. --- lisp/emacs-lisp/cl-lib.el | 8 +++----- lisp/emacs-lisp/gv.el | 2 ++ lisp/files.el | 11 ++++++----- lisp/help-fns.el | 2 +- lisp/json.el | 20 +++++++++----------- lisp/minibuffer.el | 31 ++----------------------------- lisp/progmodes/eglot.el | 9 ++++++--- lisp/progmodes/python.el | 2 +- lisp/vc/vc.el | 2 +- 9 files changed, 31 insertions(+), 56 deletions(-) diff --git a/lisp/emacs-lisp/cl-lib.el b/lisp/emacs-lisp/cl-lib.el index 4208160bd12..4645b4dffb1 100644 --- a/lisp/emacs-lisp/cl-lib.el +++ b/lisp/emacs-lisp/cl-lib.el @@ -154,12 +154,10 @@ cl-pushnew `(setq ,place (cl-adjoin ,x ,place ,@keys))) `(cl-callf2 cl-adjoin ,x ,place ,@keys))) -(defun cl--set-buffer-substring (start end val) +(defun cl--set-buffer-substring (start end val &optional inherit) "Delete region from START to END and insert VAL." - (save-excursion (delete-region start end) - (goto-char start) - (insert val) - val)) + (replace-region-contents start end val 0 nil inherit) + val) (defun cl--set-substring (str start end val) (if end (if (< end 0) (incf end (length str))) diff --git a/lisp/emacs-lisp/gv.el b/lisp/emacs-lisp/gv.el index b44f7dc87f3..6c949f1016b 100644 --- a/lisp/emacs-lisp/gv.el +++ b/lisp/emacs-lisp/gv.el @@ -684,6 +684,8 @@ buffer-string `(insert (prog1 ,store (erase-buffer)))) (make-obsolete-generalized-variable 'buffer-string nil "29.1") +;; FIXME: Can't use `replace-region-contents' because it's not +;; expected to be costly, so we need to pass MAX-SECS==0. (gv-define-simple-setter buffer-substring cl--set-buffer-substring) (make-obsolete-generalized-variable 'buffer-substring nil "29.1") diff --git a/lisp/files.el b/lisp/files.el index 4e3aeeb9246..bcab246aeef 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -7261,9 +7261,9 @@ revert-buffer-with-fine-grain-max-seconds The command tries to preserve markers, properties and overlays. If the operation takes more than this time, a single delete+insert is performed. Actually, this value is passed as -the MAX-SECS argument to the function `replace-buffer-contents', +the MAX-SECS argument to the function `replace-region-contents', so it is not ensured that the whole execution won't take longer. -See `replace-buffer-contents' for more details.") +See `replace-region-contents' for more details.") (defun revert-buffer-insert-file-contents-delicately (file-name _auto-save-p) "Optional function for `revert-buffer-insert-file-contents-function'. @@ -7272,11 +7272,11 @@ revert-buffer-insert-file-contents-delicately As with `revert-buffer-insert-file-contents--default-function', FILE-NAME is the name of the file and AUTO-SAVE-P is non-nil if this is an auto-save file. -Since calling `replace-buffer-contents' can take a long time, depending of +Since calling `replace-region-contents' can take a long time, depending of the number of changes made to the buffer, it uses the value of the variable `revert-buffer-with-fine-grain-max-seconds' as a maximum time to try delicately reverting the buffer. If it fails, it does a delete+insert. For more details, -see `replace-buffer-contents'." +see `replace-region-contents'." (cond ((not (file-exists-p file-name)) (error (if buffer-file-number @@ -7299,7 +7299,8 @@ revert-buffer-insert-file-contents-delicately (let ((temp-buf (current-buffer))) (set-buffer buf) (let ((buffer-file-name nil)) - (replace-buffer-contents + (replace-region-contents + (point-min) (point-max) temp-buf revert-buffer-with-fine-grain-max-seconds)))))))) ;; See comments in revert-buffer-with-fine-grain for an explanation. diff --git a/lisp/help-fns.el b/lisp/help-fns.el index cd5a0a6883f..dacf1ecbbd4 100644 --- a/lisp/help-fns.el +++ b/lisp/help-fns.el @@ -777,7 +777,7 @@ help-fns--signature (save-excursion (forward-char -1) (<= (current-column) (- fill-column 12))) - (cl--set-buffer-substring (- beg 3) beg " "))))) + (replace-region-contents (- beg 3) beg " " 0))))) high-doc))))) (defun help-fns--parent-mode (function) diff --git a/lisp/json.el b/lisp/json.el index 6e62e594910..098bf43cd99 100644 --- a/lisp/json.el +++ b/lisp/json.el @@ -803,7 +803,7 @@ json-pretty-print (orig-buf (current-buffer))) ;; Strategy: Repeatedly `json-read' from the original buffer and ;; write the pretty-printed snippet to a temporary buffer. - ;; Use `replace-buffer-contents' to swap the original + ;; Use `replace-region-contents' to swap the original ;; region with the contents of the temporary buffer so that point, ;; marks, etc. are kept. ;; Stop as soon as we get an error from `json-read'. @@ -825,16 +825,14 @@ json-pretty-print (standard-output tmp-buf)) (with-current-buffer tmp-buf (erase-buffer) (json--print json)) - (save-restriction - (narrow-to-region beg (point)) - (replace-buffer-contents - tmp-buf - json-pretty-print-max-secs - ;; FIXME: What's a good value here? Can we use - ;; something better, e.g., by deriving a value - ;; from the size of the region? - 64) - 'keep-going)) + (replace-region-contents + beg (point) tmp-buf + json-pretty-print-max-secs + ;; FIXME: What's a good value here? Can we use + ;; something better, e.g., by deriving a value + ;; from the size of the region? + 64) + 'keep-going) ;; EOF is expected because we json-read until we hit ;; the end of the narrow region. (json-end-of-file nil)))))))))) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index becb2a7faba..ae50574d803 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -1398,35 +1398,8 @@ completion--replace newtext) ;; Remove all text properties. (set-text-properties 0 (length newtext) nil newtext)) - ;; Maybe this should be in subr.el. - ;; You'd think this is trivial to do, but details matter if you want - ;; to keep markers "at the right place" and be robust in the face of - ;; after-change-functions that may themselves modify the buffer. - (let ((prefix-len 0)) - ;; Don't touch markers in the shared prefix (if any). - (while (and (< prefix-len (length newtext)) - (< (+ beg prefix-len) end) - (eq (char-after (+ beg prefix-len)) - (aref newtext prefix-len))) - (setq prefix-len (1+ prefix-len))) - (unless (zerop prefix-len) - (setq beg (+ beg prefix-len)) - (setq newtext (substring newtext prefix-len)))) - (let ((suffix-len 0)) - ;; Don't touch markers in the shared suffix (if any). - (while (and (< suffix-len (length newtext)) - (< beg (- end suffix-len)) - (eq (char-before (- end suffix-len)) - (aref newtext (- (length newtext) suffix-len 1)))) - (setq suffix-len (1+ suffix-len))) - (unless (zerop suffix-len) - (setq end (- end suffix-len)) - (setq newtext (substring newtext 0 (- suffix-len)))) - (goto-char beg) - (let ((length (- end beg))) ;Read `end' before we insert the text. - (insert-and-inherit newtext) - (delete-region (point) (+ (point) length))) - (forward-char suffix-len))) + (goto-char end) + (replace-region-contents beg end newtext 0.1 nil 'inherit)) (defcustom completion-cycle-threshold nil "Number of completion candidates below which cycling is used. diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index bc70db34fb5..d635914e331 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -3845,9 +3845,12 @@ eglot--apply-text-edits (let ((temp (current-buffer))) (with-current-buffer source (save-excursion - (save-restriction - (narrow-to-region beg end) - (replace-buffer-contents temp))) + (if (> emacs-major-version 30) + (replace-region-contents beg end temp) + (save-restriction + (narrow-to-region beg end) + (with-no-warnings + (replace-buffer-contents temp))))) (when reporter (eglot--reporter-update reporter (cl-incf done)))))))) (mapcar (lambda (edit) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index b6db6097d9f..de3745a036c 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -6931,7 +6931,7 @@ python--do-isort (unless (eq 0 status) (error "%s exited with status %s (maybe isort is missing?)" python-interpreter status)) - (replace-buffer-contents temp) + (replace-region-contents (point-min) (point-max) temp) (not (eq tick (buffer-chars-modified-tick))))))))) ;;;###autoload diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index 565eaabff0b..5c401f0bded 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -1970,7 +1970,7 @@ vc-diff-restore-buffer objects, and finally killing buffer ORIGINAL." (with-current-buffer original (let ((inhibit-read-only t)) - (replace-buffer-contents new))) + (replace-region-contents (point-min) (point-max) new))) (with-current-buffer new (buffer-swap-text original)) (kill-buffer original)) -- 2.39.5 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0003-Org-Use-new-replace-region-contents.patch From 701e45bdcd194c3447e51eb1fec50fe252bcec62 Mon Sep 17 00:00:00 2001 From: Stefan Monnier <monnier@HIDDEN> Date: Fri, 28 Mar 2025 00:49:33 -0400 Subject: [PATCH 3/3] Org: Use new `replace-region-contents` * lisp/org/org-compat.el (org-replace-buffer-contents): Delete function. (org-replace-region-contents): New function. * lisp/org/org-src.el (org-edit-src-save, org-edit-src-exit): Use it. --- lisp/org/org-compat.el | 18 ++++++++++++++---- lisp/org/org-src.el | 21 ++++++--------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/lisp/org/org-compat.el b/lisp/org/org-compat.el index 59d34b661c6..297e8f06045 100644 --- a/lisp/org/org-compat.el +++ b/lisp/org/org-compat.el @@ -292,10 +292,20 @@ org-buffer-text-pixel-width (if tree (push tree elems)) (nreverse elems)))) -(if (version< emacs-version "27.1") - (defsubst org-replace-buffer-contents (source &optional _max-secs _max-costs) - (replace-buffer-contents source)) - (defalias 'org-replace-buffer-contents #'replace-buffer-contents)) +(defalias 'org-replace-region-contents + (if (> emacs-major-version 30) + #'replace-region-contents + ;; The `replace-region-contents' in Emacs<31 does not accept a buffer + ;; as SOURCE argument and does not preserve the position well enough. + (lambda (beg end source &optional max-secs max-costs) + (save-restriction + (narrow-to-region beg end) + (let ((eobp (eobp))) + (with-no-warnings + (if (< emacs-major-version 27) + (replace-buffer-contents source) + (replace-buffer-contents source max-secs max-costs))) + (if eobp (goto-char (point-max)))))))) (unless (fboundp 'proper-list-p) ;; `proper-list-p' was added in Emacs 27.1. The function below is diff --git a/lisp/org/org-src.el b/lisp/org/org-src.el index 302c27ac866..d8a928b1f9f 100644 --- a/lisp/org/org-src.el +++ b/lisp/org/org-src.el @@ -1414,13 +1414,9 @@ org-edit-src-save ;; insert new contents. (delete-overlay overlay) (let ((expecting-bol (bolp))) - (if (version< emacs-version "27.1") - (progn (delete-region beg end) - (insert (with-current-buffer write-back-buf (buffer-string)))) - (save-restriction - (narrow-to-region beg end) - (org-replace-buffer-contents write-back-buf 0.1 nil) - (goto-char (point-max)))) + (goto-char end) + (org-replace-region-contents beg end write-back-buf 0.1 nil) + (cl-assert (= (point) (+ beg (buffer-size write-back-buf)))) (when (and expecting-bol (not (bolp))) (insert "\n"))) (kill-buffer write-back-buf) (save-buffer) @@ -1461,14 +1457,9 @@ org-edit-src-exit (undo-boundary) (goto-char beg) (let ((expecting-bol (bolp))) - (if (version< emacs-version "27.1") - (progn (delete-region beg end) - (insert (with-current-buffer write-back-buf - (buffer-string)))) - (save-restriction - (narrow-to-region beg end) - (org-replace-buffer-contents write-back-buf 0.1 nil) - (goto-char (point-max)))) + (goto-char end) + (org-replace-region-contents beg end write-back-buf 0.1 nil) + (cl-assert (= (point) (+ beg (buffer-size write-back-buf)))) (when (and expecting-bol (not (bolp))) (insert "\n"))))) (when write-back-buf (kill-buffer write-back-buf)) ;; If we are to return to source buffer, put point at an -- 2.39.5 --=-=-=--
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.Received: (at 76313) by debbugs.gnu.org; 8 Mar 2025 13:15:53 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 08 08:15:53 2025 Received: from localhost ([127.0.0.1]:53327 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tqu1x-0004t3-6W for submit <at> debbugs.gnu.org; Sat, 08 Mar 2025 08:15:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59878) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tqu1v-0004sq-2o for 76313 <at> debbugs.gnu.org; Sat, 08 Mar 2025 08:15: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 1tqu1p-00020M-1q; Sat, 08 Mar 2025 08:15:45 -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=m3ECedb5bfnthR9t+CeZpRMYXhSlis9qUYWV/Mv75/k=; b=QPc4Qfnk187s qXuEFpWf91usa0MMljD20Y7JGKHx++ySww52Pqi4acVPH0YpwbaNORG0d6vjpgtIvUE6xrvFo7ZrD P592s1EWUnTb7zZ9nC3mnQ/ybsY+jahqpSzGMYzcxStXYmRg55zvvY3S0IImIJ3jiiPiFy1/rnrhQ T+rzj7d3dKYdSkmbYxFtc9CxFnPvk9pbLMzUneetTB16Sm4Pc/m7NA8ry9PpuoZc+jGcE/NgUHA82 bJhb0uV0I/QNwkdvcd3Vmd4ZtvjTuldyy6mP20XwTz0fQ74PpWLHuOPTeXkRxkY6Oy3fju/Yzw7bO ICJVmWXslcjmvxi38UGbOg==; Date: Sat, 08 Mar 2025 15:15:33 +0200 Message-Id: <861pv7k6iy.fsf@HIDDEN> From: Eli Zaretskii <eliz@HIDDEN> To: Stefan Kangas <stefankangas@HIDDEN> In-Reply-To: <CADwFkmnMwhOz+rxhiLeYxapvJsdeWFr7QVnhLnRYsQZhg4=Avw@HIDDEN> (message from Stefan Kangas on Sat, 8 Mar 2025 03:50:17 -0800) Subject: Re: bug#76313: New function `replace-region` References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <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> <CADwFkm=5VjYgFKe5Mp3Nf1aOkxf_=ra0ihRvZ+arh_BBxnyhLA@HIDDEN> <868qpfkbh2.fsf@HIDDEN> <CADwFkmnMwhOz+rxhiLeYxapvJsdeWFr7QVnhLnRYsQZhg4=Avw@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: Sat, 8 Mar 2025 03:50:17 -0800 > Cc: 76313 <at> debbugs.gnu.org, monnier@HIDDEN, tsdh@HIDDEN > > Eli Zaretskii <eliz@HIDDEN> writes: > > >> 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? > > > > I'm not sure I understand: are you suggesting to do the above, and > > Do we agree about points a) and b) above? If yes, can we do that now? > Alternatively, can we do either a) or b)? I don't think it's important. We should discuss this after we solve the real problem. > > I'm not sure I understand: are you suggesting to do the above, and > > _then_ add a new replace-region function? I thought I already > > explained why doing so will not resolve the problems I had with the > > addition of a new API? > > I actually don't have any proposal for how to proceed after a) and b). > I don't know what might be needed. The best proposals that exist have > been detailed in this thread. > > I think it's for you to say, either "here's what I need to feel > comfortable with adding `replace-region`", or "I see no way of making me > feel comfortable with adding `replace-region`". I'm currently reading > you as saying the latter. I already suggested how to add it without adding a new API. And AFAIU, Stefan Monnier almost agreed with that. > If my reading is correct, I think we should close this issue after we > have decided what to do about my a) and b) above. And then move on. If we don't make any changes to incorporate the functionality that Stefan Monnier wanted to add, then I see no reason to do a) or b), either.
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.Received: (at 76313) by debbugs.gnu.org; 8 Mar 2025 11:50:27 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 08 06:50:27 2025 Received: from localhost ([127.0.0.1]:53190 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tqshG-00061B-PV for submit <at> debbugs.gnu.org; Sat, 08 Mar 2025 06:50:27 -0500 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]:45140) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from <stefankangas@HIDDEN>) id 1tqshE-00060Q-5K for 76313 <at> debbugs.gnu.org; Sat, 08 Mar 2025 06:50:25 -0500 Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-5e04cb346eeso4616182a12.2 for <76313 <at> debbugs.gnu.org>; Sat, 08 Mar 2025 03:50:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741434618; x=1742039418; 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=rEwkN8M5Fk4jfxxhJs7EIfDDCdHSHTZBMdHS1+VkTuY=; b=WsgmijZKrekR5XkV44Zn8THYWWgv0l8Jzq+6ARo6AghrkLECgU74nZf/S2HVuckgvi OKco7hn8ejUXtOfgVWBvKktUv53ZYdiLmwwiGj/sGykoJqdX6iDMJTumjNVhksNoaMaz WPKiahbLsBTjcajtwpoAob+QTvgZF1wHzrKKAKxJ33MW929UzcWiKK7xIzyLlrZf5KON Ul5dXA+M13uSJp1exg/wASOzSMW/lIQ4DYgWSiqCUjlNKZlrc7ldTE8YvRg5by5qp3vo dyTncTLVjWpHCgSx+uxY+zWvQP255vXVJLDjbyT5cpjUNVVahWwu7VwL3LyDeWMnB7Tu osPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741434618; x=1742039418; 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=rEwkN8M5Fk4jfxxhJs7EIfDDCdHSHTZBMdHS1+VkTuY=; b=AYVZ9mp3eXGDsWC5RLAvRA/egj8YsWiTB3r8LbHPkF8fIc6PeWB3wpIkyjfTJsxSZ6 8ZmsTrv0tZkFb9aL1HrlKTlo2XnPI0qu7p5cXHphA+cM5/DpsISYTNOHhG8wrqZR8sxS vVSCYiaOtzgJlhcdDIVYa3nRkN0IazkBKIN+Wc7kqC+i9Q3o9vQ3EpCvcTZlIvEq0BUK oKNObVDNC5ukiLtqKKlJ1Do6c2elVboMc0MFJDMdwfXvm2Nj3BiefQOml6ngWbJw/WXU fSMlmiZY8nLJgyDjOBW9Y2ubiuvrn8Un1we2Ucvhxp1Z9ifyDV2FG/yPbM+eeq0RGPfg Nc7w== X-Gm-Message-State: AOJu0YzhicTu9CVZep0lHTPqsu1dHgi8/o0XlCXaKCB6BZuWHY9QorqL k/f8GYJ2nRSB+e7Ii+KmSjnRgVM2qUel2iSe62w3vJ7jBcUb1ykFb3WTOXLtPx7RfwKBYhqQzrh C5iQ9CdplAqy/nEFV2q5ZVoQ1Oss= X-Gm-Gg: ASbGncvR6e1rNPPcjdZmtx8Q6N97K7sHLwWig1gRNN8K8fGl8CwY/t/bhcCJXltJFZN hBh3609Lg3gqZw2s36VBEE+3CfSzPI2pUy13WjXk+keP5xs3vDnFQFkvRvdXaK9oP2nAByQJEHy 08mErbSXNpWpM9nQ8UuoyauURtfPGxOy4OOFEC X-Google-Smtp-Source: AGHT+IGx/r5u+j5KKY5xz9PeyNM0o3xBgVGBYpyTWbOTgT12jEOnneQ68EL6jDhR3budBpg9tbeDQty5d4cy7B8CaRo= X-Received: by 2002:a05:6402:3507:b0:5e4:9726:7779 with SMTP id 4fb4d7f45d1cf-5e5e22a926fmr7143271a12.2.1741434617709; Sat, 08 Mar 2025 03:50:17 -0800 (PST) Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Sat, 8 Mar 2025 03:50:17 -0800 From: Stefan Kangas <stefankangas@HIDDEN> In-Reply-To: <868qpfkbh2.fsf@HIDDEN> References: <jwv4j0u50tn.fsf-monnier+@gnu.org> <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> <CADwFkm=5VjYgFKe5Mp3Nf1aOkxf_=ra0ihRvZ+arh_BBxnyhLA@HIDDEN> <868qpfkbh2.fsf@HIDDEN> MIME-Version: 1.0 Date: Sat, 8 Mar 2025 03:50:17 -0800 X-Gm-Features: AQ5f1JqbW0CTAhUgf3ndp13uOuMF1QtX27wry-Jo1UFz1MjkvGTnCpiS15Rj7jU Message-ID: <CADwFkmnMwhOz+rxhiLeYxapvJsdeWFr7QVnhLnRYsQZhg4=Avw@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: Sat, 8 Mar 2025 01:46:20 -0800 >> Cc: 76313 <at> debbugs.gnu.org, monnier@HIDDEN, tsdh@HIDDEN >> >> 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? > > I'm not sure I understand: are you suggesting to do the above, and Do we agree about points a) and b) above? If yes, can we do that now? Alternatively, can we do either a) or b)? > I'm not sure I understand: are you suggesting to do the above, and > _then_ add a new replace-region function? I thought I already > explained why doing so will not resolve the problems I had with the > addition of a new API? I actually don't have any proposal for how to proceed after a) and b). I don't know what might be needed. The best proposals that exist have been detailed in this thread. I think it's for you to say, either "here's what I need to feel comfortable with adding `replace-region`", or "I see no way of making me feel comfortable with adding `replace-region`". I'm currently reading you as saying the latter. If my reading is correct, I think we should close this issue after we have decided what to do about my a) and b) above. And then move on.
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.Received: (at 76313) by debbugs.gnu.org; 8 Mar 2025 11:28:57 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 08 06:28:57 2025 Received: from localhost ([127.0.0.1]:53142 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tqsMS-0004r2-J3 for submit <at> debbugs.gnu.org; Sat, 08 Mar 2025 06:28:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54608) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tqsMP-0004qi-MN for 76313 <at> debbugs.gnu.org; Sat, 08 Mar 2025 06:28:54 -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 1tqsMJ-0001ug-JT; Sat, 08 Mar 2025 06:28:47 -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=1BJm/YJOvRL//ntrRK6s8Fj7VIEi5sTHySeCoEP0iYU=; b=HwLBVKhHUQ1v w8j+auu9Z9LwrtcF/AdJrfWHm2ucAWjRvdcJ7BkawJwXDsBORmDzsQKjjMFKmCdWQScUgaiJeTcvs bFNg2IWaI26f498E8K8vxMJF/ALGQpyCblcnvMppt3RZkwno6MAXkUrfCxrkVjzIdu9eOzqyhHtfK xSxSaU8PVcF29MOEoEPf7UmroZzIp/eTYfsLxmzIs6/pYNCqSJt8vEByEz/beVxFSCbHXGRdC++JE IxrYm1cyL/IaiMOS2D1bx7u3F7UPLG88UYce4Yw9lOr82mX+AB3fuA1odmmmZmn0GeXIbtF2Gc+R3 P+y8lRTA/+GahQF9H2Blkg==; Date: Sat, 08 Mar 2025 13:28:41 +0200 Message-Id: <868qpfkbh2.fsf@HIDDEN> From: Eli Zaretskii <eliz@HIDDEN> To: Stefan Kangas <stefankangas@HIDDEN> In-Reply-To: <CADwFkm=5VjYgFKe5Mp3Nf1aOkxf_=ra0ihRvZ+arh_BBxnyhLA@HIDDEN> (message from Stefan Kangas on Sat, 8 Mar 2025 01:46:20 -0800) Subject: Re: bug#76313: New function `replace-region` 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> <CADwFkm=5VjYgFKe5Mp3Nf1aOkxf_=ra0ihRvZ+arh_BBxnyhLA@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: Sat, 8 Mar 2025 01:46:20 -0800 > Cc: 76313 <at> debbugs.gnu.org, monnier@HIDDEN, tsdh@HIDDEN > > 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? I'm not sure I understand: are you suggesting to do the above, and _then_ add a new replace-region function? I thought I already explained why doing so will not resolve the problems I had with the addition of a new API?
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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?
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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.
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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.
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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.
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.Debbugs Internal Request <help-debbugs@HIDDEN>
to internal_control <at> debbugs.gnu.org
.
Full text available.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
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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?
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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.)
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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.
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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.
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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.
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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.
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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
Stefan Monnier <monnier@HIDDEN>
:Stefan Monnier <monnier@HIDDEN>
: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?
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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?
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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...
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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.
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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.
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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.
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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 --=-=-=--
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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?
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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?
bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.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") --=-=-=--
Stefan Monnier <monnier@HIDDEN>
:monnier@HIDDEN, bug-gnu-emacs@HIDDEN
.
Full text available.monnier@HIDDEN, bug-gnu-emacs@HIDDEN
:bug#76313
; Package emacs
.
Full text available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997 nCipher Corporation Ltd,
1994-97 Ian Jackson.