GNU bug report logs - #42424
27.0.90; replace-match: point is NOT left at the end of replacement

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

Package: emacs; Reported by: Ren Victor <victorhge@HIDDEN>; Keywords: patch; Done: Lars Ingebrigtsen <larsi@HIDDEN>; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

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


Received: (at 42424) by debbugs.gnu.org; 9 Apr 2024 15:14:59 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Apr 09 11:14:58 2024
Received: from localhost ([127.0.0.1]:51248 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1ruDBa-0004vL-JX
	for submit <at> debbugs.gnu.org; Tue, 09 Apr 2024 11:14:58 -0400
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:17122)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <monnier@HIDDEN>) id 1ruDBX-0004u9-OM
 for 42424 <at> debbugs.gnu.org; Tue, 09 Apr 2024 11:14:57 -0400
Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 027A01000FC;
 Tue,  9 Apr 2024 11:14:42 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1712675676;
 bh=HHs/6tLLATTUqtWvfJre4yIIKZHhn1ht9vZyTBuK4LA=;
 h=From:To:Cc:Subject:Date:From;
 b=pWvmyYgffyxCGWxzgGIG0RalIo1FJEiIeizo3Xh1Y7Hve0flsxN/QJAUV8JDjUWfW
 fQSb0L/XGp4tbmf5BGd4wvmFXEv9qh7nrW5DaCN0k1mzRlY4XvtjdoCo3pqRz1AQsC
 HzR8d6csK+vOCoH+pK2hfWFgQcMwXNxqfIeTXGWMttZ8cOUCCspxnSfCNmZUKt4zuY
 oypJyxYj34kQIUwU1GSfpycSJwmlStmLLFDuvPUnF4HS29Mpt+aA3cSAp89mvVEpuL
 mc9nTVep327cbrhwqsp5QsHKGaOG61pP3QI5Rjz4LhgHtYWru18kk/rw/cMmMoWaUQ
 GqrnqGqMNKJBQ==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 92C7610004A;
 Tue,  9 Apr 2024 11:14:36 -0400 (EDT)
Received: from pastel (unknown [45.72.201.215])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 753DB120223;
 Tue,  9 Apr 2024 11:14:36 -0400 (EDT)
From: Stefan Monnier <monnier@HIDDEN>
To: Ren Victor <victorhge@HIDDEN>
Subject: Re: bug#42424: 27.0.90; replace-match: point is NOT left at the end
 of replacement
Message-ID: <jwv1q7e8t8b.fsf-monnier+emacs@HIDDEN>
Date: Tue, 09 Apr 2024 11:14:35 -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.010 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: 42424
Cc: 42424 <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 (---)

> This issue happens when modification hooks modify the text before the
> end of replacement text.

Modification hooks which modify the buffer text are just getting what
they deserve.

> But the end of replacement might be changed inside of `replace_range'.
> So the final movement of point may end up to a wrong place.

This is just one of the many problems.

> Other types of modification (insert or delete) do not have this issue.
> `point' is adjusted before running modification hooks.

Yes, occasionally doing bad things won't bite you in the rear.
That doesn't justify doing those things.

If you want to modify the buffer in response to other buffer
modifications, then record this fact in the modification hook and then
act on it later, e.g. in a timer.
Anything else *will* cause problems sooner or later.


        Stefan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#42424; Package emacs. Full text available.
bug unarchived. Request was from Stefan Monnier <monnier@HIDDEN> to control <at> debbugs.gnu.org. Full text available.
bug archived. Request was from Debbugs Internal Request <help-debbugs@HIDDEN> to internal_control <at> debbugs.gnu.org. Full text available.
bug marked as fixed in version 28.1, send any further explanations to 42424 <at> debbugs.gnu.org and Ren Victor <victorhge@HIDDEN> Request was from Lars Ingebrigtsen <larsi@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

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


Received: (at 42424) by debbugs.gnu.org; 31 Jul 2021 15:46:01 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Jul 31 11:46:01 2021
Received: from localhost ([127.0.0.1]:34653 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1m9rBZ-0007wq-1G
	for submit <at> debbugs.gnu.org; Sat, 31 Jul 2021 11:46:01 -0400
Received: from quimby.gnus.org ([95.216.78.240]:54872)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <larsi@HIDDEN>) id 1m9rBY-0007wb-1z
 for 42424 <at> debbugs.gnu.org; Sat, 31 Jul 2021 11:46:00 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org;
 s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:
 References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:
 Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender:
 Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:
 List-Subscribe:List-Post:List-Owner:List-Archive;
 bh=847CS9Jt5lGpkpF98W5//BE9IGXFkmPfs8TA4Trsnzw=; b=j5RIEKkzYVoFyrhlfqWFIAu+jd
 9SRCc//DhpYt1BdR6FnFweNJS3pYnTP+8q3fOaFnIT8RgzKlP3EbagPnDqyT/Yz1raIuI4UGLSVKs
 8LnL0lEQA2iKQtPWD+vYzbanS+Zo1UufouC2eK3l93i6GMfdkIuQeV7Drt1j81S8hUEo=;
Received: from 2.149.45.105.tmi.telenormobil.no ([2.149.45.105] helo=elva)
 by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.92) (envelope-from <larsi@HIDDEN>)
 id 1m9rBO-00052j-L4; Sat, 31 Jul 2021 17:45:53 +0200
From: Lars Ingebrigtsen <larsi@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#42424: 27.0.90; replace-match: point is NOT left at the end
 of replacement
References: <CAMks0JH0N=BAEjBnGrU-jfT=aryrC4jEZDOuJMxAd5N3UpSVbg@HIDDEN>
 <87zh4ltc5l.fsf@HIDDEN> <83tuussr1v.fsf@HIDDEN>
 <87tuusj618.fsf@HIDDEN> <87r1fefum7.fsf@HIDDEN>
 <835ywqpntr.fsf@HIDDEN> <871r7eftg9.fsf@HIDDEN>
 <87wnp6edwv.fsf@HIDDEN> <8335ruplir.fsf@HIDDEN>
Date: Sat, 31 Jul 2021 17:45:48 +0200
In-Reply-To: <8335ruplir.fsf@HIDDEN> (Eli Zaretskii's message of "Sat, 31 Jul
 2021 18:10:04 +0300")
Message-ID: <87zgu2cwr7.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 @@CONTACT_ADDRESS@@ for details.
 Content preview: Eli Zaretskii <eliz@HIDDEN> writes: >> replace_range
 (ptrdiff_t
 from, ptrdiff_t to, Lisp_Object new, >> bool prepare, bool inherit, bool
 markers, >> - bool adjust_match_data) >> + bool adjust_match_data,
 bool inhibit_update_compositions [...] 
 Content analysis details:   (-2.9 points, 5.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
 0.0 TVD_RCVD_IP            Message was received from an IP address
 -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%
 [score: 0.0000]
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 42424
Cc: victorhge@HIDDEN, 42424 <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 (---)

Eli Zaretskii <eliz@HIDDEN> writes:

>>  replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new,
>>                 bool prepare, bool inherit, bool markers,
>> -               bool adjust_match_data)
>> +               bool adjust_match_data, bool inhibit_update_compositions)
>
> The name is misleading: the 2 functions whose call you want to bypass
> are not just for updating compositions.

Yup; now renamed and pushed.

It's hard to say whether this might have strange unforeseen effects, but
this change makes `replace-match' do what it's documented to do, at least.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




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

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


Received: (at 42424) by debbugs.gnu.org; 31 Jul 2021 15:10:28 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Jul 31 11:10:28 2021
Received: from localhost ([127.0.0.1]:34625 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1m9qdA-0004xl-3t
	for submit <at> debbugs.gnu.org; Sat, 31 Jul 2021 11:10:28 -0400
Received: from eggs.gnu.org ([209.51.188.92]:50366)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1m9qd7-0004xX-MZ
 for 42424 <at> debbugs.gnu.org; Sat, 31 Jul 2021 11:10:26 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e]:50796)
 by eggs.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <eliz@HIDDEN>)
 id 1m9qd2-0001N5-4y; Sat, 31 Jul 2021 11:10:20 -0400
Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:2013
 helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1m9qd1-0005oP-Pd; Sat, 31 Jul 2021 11:10:20 -0400
Date: Sat, 31 Jul 2021 18:10:04 +0300
Message-Id: <8335ruplir.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Lars Ingebrigtsen <larsi@HIDDEN>
In-Reply-To: <87wnp6edwv.fsf@HIDDEN> (message from Lars Ingebrigtsen on Sat, 
 31 Jul 2021 16:49:52 +0200)
Subject: Re: bug#42424: 27.0.90; replace-match: point is NOT left at the end
 of replacement
References: <CAMks0JH0N=BAEjBnGrU-jfT=aryrC4jEZDOuJMxAd5N3UpSVbg@HIDDEN>
 <87zh4ltc5l.fsf@HIDDEN> <83tuussr1v.fsf@HIDDEN>
 <87tuusj618.fsf@HIDDEN> <87r1fefum7.fsf@HIDDEN>
 <835ywqpntr.fsf@HIDDEN> <871r7eftg9.fsf@HIDDEN> <87wnp6edwv.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 42424
Cc: victorhge@HIDDEN, 42424 <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: Lars Ingebrigtsen <larsi@HIDDEN>
> Cc: 42424 <at> debbugs.gnu.org,  victorhge@HIDDEN
> Date: Sat, 31 Jul 2021 16:49:52 +0200
> 
>  void
>  replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new,
>                 bool prepare, bool inherit, bool markers,
> -               bool adjust_match_data)
> +               bool adjust_match_data, bool inhibit_update_compositions)

The name is misleading: the 2 functions whose call you want to bypass
are not just for updating compositions.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#42424; Package emacs. Full text available.
Added tag(s) patch. Request was from Lars Ingebrigtsen <larsi@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

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


Received: (at 42424) by debbugs.gnu.org; 31 Jul 2021 14:50:06 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Jul 31 10:50:06 2021
Received: from localhost ([127.0.0.1]:34592 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1m9qJR-0002I9-QB
	for submit <at> debbugs.gnu.org; Sat, 31 Jul 2021 10:50:06 -0400
Received: from quimby.gnus.org ([95.216.78.240]:54380)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <larsi@HIDDEN>) id 1m9qJP-0002HW-IJ
 for 42424 <at> debbugs.gnu.org; Sat, 31 Jul 2021 10:50:04 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org;
 s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:
 References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:
 Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender:
 Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:
 List-Subscribe:List-Post:List-Owner:List-Archive;
 bh=EF6n1xQUzuZb/KSaT7QArAs9Nr4wjEaURsMTiojimlo=; b=f4IdaZ2m83glxaIQ0/j1vDpc98
 jsoRYi25Mhp6eij8/9n1SxxugKixAu+SjDNy7g/pZZ0Gh/xxth/DM1r2B71wsODpeXVNKMbVOtHy1
 4rQsOVHvP0GlXHNuSZ462KwBXqnvm2zu1jjW6P+x0F2R2h9WIgmelGNbimXeXuxhtOK0=;
Received: from 2.149.45.105.tmi.telenormobil.no ([2.149.45.105] helo=elva)
 by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.92) (envelope-from <larsi@HIDDEN>)
 id 1m9qJF-0004fG-Me; Sat, 31 Jul 2021 16:49:56 +0200
From: Lars Ingebrigtsen <larsi@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#42424: 27.0.90; replace-match: point is NOT left at the end
 of replacement
References: <CAMks0JH0N=BAEjBnGrU-jfT=aryrC4jEZDOuJMxAd5N3UpSVbg@HIDDEN>
 <87zh4ltc5l.fsf@HIDDEN> <83tuussr1v.fsf@HIDDEN>
 <87tuusj618.fsf@HIDDEN> <87r1fefum7.fsf@HIDDEN>
 <835ywqpntr.fsf@HIDDEN> <871r7eftg9.fsf@HIDDEN>
Date: Sat, 31 Jul 2021 16:49:52 +0200
In-Reply-To: <871r7eftg9.fsf@HIDDEN> (Lars Ingebrigtsen's message of "Sat,
 31 Jul 2021 16:28:54 +0200")
Message-ID: <87wnp6edwv.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 @@CONTACT_ADDRESS@@ for details.
 Content preview:  Lars Ingebrigtsen <larsi@HIDDEN> writes: > But that does
 not seem to call the modification hook at all in the test > case. Am I doing
 something obviously wrong here? Er. I may just have been testing the wrong
 thing or something. I redid the patch by adding a new parameter to
 replace_range
 to inhibit it calling the hook, and now the test case works fine, and it
 doe [...] 
 Content analysis details:   (-2.9 points, 5.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
 0.0 TVD_RCVD_IP            Message was received from an IP address
 -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%
 [score: 0.0000]
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 42424
Cc: victorhge@HIDDEN, 42424 <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 (---)

Lars Ingebrigtsen <larsi@HIDDEN> writes:

> But that does not seem to call the modification hook at all in the test
> case.  Am I doing something obviously wrong here?

Er.  I may just have been testing the wrong thing or something.  I redid
the patch by adding a new parameter to replace_range to inhibit it
calling the hook, and now the test case works fine, and it doesn't break
any tests.  (And it seems to work more logically all over.)

Any comments?  I've tried to imagine how it might regress something for
somebody, but I don't think it should -- we're calling the modification
hook at the same point as before (I think), for instance.

diff --git a/src/cmds.c b/src/cmds.c
index c8a96d918c..00fde0ef79 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -455,7 +455,7 @@ internal_self_insert (int c, EMACS_INT n)
       ptrdiff_t to;
       if (INT_ADD_WRAPV (PT, chars_to_delete, &to))
 	to = PTRDIFF_MAX;
-      replace_range (PT, to, string, 1, 1, 1, 0);
+      replace_range (PT, to, string, 1, 1, 1, 0, false);
       Fforward_char (make_fixnum (n));
     }
   else if (n > 1)
diff --git a/src/editfns.c b/src/editfns.c
index 8ab17ebc9f..c8219decb0 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -2371,7 +2371,7 @@ #define COMBINING_BOTH (COMBINING_BEFORE | COMBINING_AFTER)
 	      /* replace_range is less efficient, because it moves the gap,
 		 but it handles combining correctly.  */
 	      replace_range (pos, pos + 1, string,
-			     false, false, true, false);
+			     false, false, true, false, false);
 	      pos_byte_next = CHAR_TO_BYTE (pos);
 	      if (pos_byte_next > pos_byte)
 		/* Before combining happened.  We should not increment
@@ -2578,7 +2578,7 @@ DEFUN ("translate-region-internal", Ftranslate_region_internal,
 		     but it should handle multibyte characters correctly.  */
 		  string = make_multibyte_string ((char *) str, 1, str_len);
 		  replace_range (pos, pos + 1, string,
-				 true, false, true, false);
+				 true, false, true, false, false);
 		  len = str_len;
 		}
 	      else
@@ -2613,7 +2613,8 @@ DEFUN ("translate-region-internal", Ftranslate_region_internal,
 		= (VECTORP (val)
 		   ? Fconcat (1, &val)
 		   : Fmake_string (make_fixnum (1), val, Qnil));
-	      replace_range (pos, pos + len, string, true, false, true, false);
+	      replace_range (pos, pos + len, string, true, false, true, false,
+			     false);
 	      pos_byte += SBYTES (string);
 	      pos += SCHARS (string);
 	      characters_changed += SCHARS (string);
diff --git a/src/insdel.c b/src/insdel.c
index e66120eb08..92ee2c42ea 100644
--- a/src/insdel.c
+++ b/src/insdel.c
@@ -1392,7 +1392,7 @@ adjust_after_insert (ptrdiff_t from, ptrdiff_t from_byte,
 void
 replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new,
                bool prepare, bool inherit, bool markers,
-               bool adjust_match_data)
+               bool adjust_match_data, bool inhibit_update_compositions)
 {
   ptrdiff_t inschars = SCHARS (new);
   ptrdiff_t insbytes = SBYTES (new);
@@ -1552,8 +1552,11 @@ replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new,
   if (adjust_match_data)
     update_search_regs (from, to, from + SCHARS (new));
 
-  signal_after_change (from, nchars_del, GPT - from);
-  update_compositions (from, GPT, CHECK_BORDER);
+  if (!inhibit_update_compositions)
+    {
+      signal_after_change (from, nchars_del, GPT - from);
+      update_compositions (from, GPT, CHECK_BORDER);
+    }
 }
 
 /* Replace the text from character positions FROM to TO with
diff --git a/src/lisp.h b/src/lisp.h
index 15a42a4456..1206a0d1f6 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -3717,7 +3717,8 @@ verify (FLT_RADIX == 2 || FLT_RADIX == 16);
 				       ptrdiff_t, ptrdiff_t);
 extern void adjust_markers_bytepos (ptrdiff_t, ptrdiff_t,
 				    ptrdiff_t, ptrdiff_t, int);
-extern void replace_range (ptrdiff_t, ptrdiff_t, Lisp_Object, bool, bool, bool, bool);
+extern void replace_range (ptrdiff_t, ptrdiff_t, Lisp_Object, bool, bool,
+			   bool, bool, bool);
 extern void replace_range_2 (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
 			     const char *, ptrdiff_t, ptrdiff_t, bool);
 extern void syms_of_insdel (void);
diff --git a/src/search.c b/src/search.c
index df384e1dcf..a295ca12bd 100644
--- a/src/search.c
+++ b/src/search.c
@@ -30,6 +30,7 @@ Copyright (C) 1985-1987, 1993-1994, 1997-1999, 2001-2021 Free Software
 #include "blockinput.h"
 #include "intervals.h"
 #include "pdumper.h"
+#include "composite.h"
 
 #include "regex-emacs.h"
 
@@ -2725,8 +2726,8 @@ DEFUN ("replace-match", Freplace_match, Sreplace_match, 1, 5, 0,
   newpoint = sub_start + SCHARS (newtext);
 
   /* Replace the old text with the new in the cleanest possible way.  */
-  replace_range (sub_start, sub_end, newtext, 1, 0, 1, true);
-
+  replace_range (sub_start, sub_end, newtext, 1, 0, 1, true, true);
+  
   if (case_action == all_caps)
     Fupcase_region (make_fixnum (search_regs.start[sub]),
 		    make_fixnum (newpoint),
@@ -2750,6 +2751,9 @@ DEFUN ("replace-match", Freplace_match, Sreplace_match, 1, 5, 0,
   /* Now move point "officially" to the end of the inserted replacement.  */
   move_if_not_intangible (newpoint);
 
+  signal_after_change (sub_start, sub_end - sub_start, SCHARS (newtext));
+  update_compositions (sub_start, newpoint, CHECK_BORDER);
+
   return Qnil;
 }
 
diff --git a/test/src/search-tests.el b/test/src/search-tests.el
new file mode 100644
index 0000000000..b7b4ab9a8f
--- /dev/null
+++ b/test/src/search-tests.el
@@ -0,0 +1,42 @@
+;;; search-tests.el --- tests for search.c functions -*- lexical-binding: t -*-
+
+;; Copyright (C) 2015-2016, 2018-2021 Free Software Foundation, Inc.
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'ert)
+
+(ert-deftest test-replace-match-modification-hooks ()
+  (let ((ov-set nil))
+    (with-temp-buffer
+      (insert "1 abc")
+      (setq ov-set (make-overlay 3 5))
+      (overlay-put
+       ov-set 'modification-hooks
+       (list (lambda (o after &rest _args)
+	       (when after
+		 (let ((inhibit-modification-hooks t))
+		   (save-excursion
+		     (goto-char 2)
+		     (insert "234")))))))
+      (goto-char 3)
+      (if (search-forward "bc")
+	  (replace-match "bcd"))
+      (should (= (point) 10)))))
+
+;;; search-tests.el ends here


-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




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

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


Received: (at 42424) by debbugs.gnu.org; 31 Jul 2021 14:29:06 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Jul 31 10:29:06 2021
Received: from localhost ([127.0.0.1]:34579 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1m9pz8-0001nY-7a
	for submit <at> debbugs.gnu.org; Sat, 31 Jul 2021 10:29:06 -0400
Received: from quimby.gnus.org ([95.216.78.240]:54178)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <larsi@HIDDEN>) id 1m9pz6-0001n5-Gd
 for 42424 <at> debbugs.gnu.org; Sat, 31 Jul 2021 10:29:05 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org;
 s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:
 References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:
 Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender:
 Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:
 List-Subscribe:List-Post:List-Owner:List-Archive;
 bh=wLvLSDiVXEtjkEj4N1GCwQl7tK/4cHTkz/dPgQaSC5o=; b=jROs+T5sClc/ja35LjoZymJXSe
 AY1IaCEYSOynXdMZ11xlxXvYrd/nWvIHryHK6+9MXkZ2vuBFhOfpcACKGjus/CjzeYCAuGTFucz0U
 OPUQzrFtQ+QKY6AmStXBaSXBLKDqVx022HGH5+6j6n3MuahQd49RzPcWL+yO0B8WKEXc=;
Received: from 2.149.45.105.tmi.telenormobil.no ([2.149.45.105] helo=elva)
 by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.92) (envelope-from <larsi@HIDDEN>)
 id 1m9pyx-0004U2-CX; Sat, 31 Jul 2021 16:28:58 +0200
From: Lars Ingebrigtsen <larsi@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#42424: 27.0.90; replace-match: point is NOT left at the end
 of replacement
References: <CAMks0JH0N=BAEjBnGrU-jfT=aryrC4jEZDOuJMxAd5N3UpSVbg@HIDDEN>
 <87zh4ltc5l.fsf@HIDDEN> <83tuussr1v.fsf@HIDDEN>
 <87tuusj618.fsf@HIDDEN> <87r1fefum7.fsf@HIDDEN>
 <835ywqpntr.fsf@HIDDEN>
Date: Sat, 31 Jul 2021 16:28:54 +0200
In-Reply-To: <835ywqpntr.fsf@HIDDEN> (Eli Zaretskii's message of "Sat, 31 Jul
 2021 17:20:16 +0300")
Message-ID: <871r7eftg9.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 @@CONTACT_ADDRESS@@ for details.
 Content preview:  Eli Zaretskii <eliz@HIDDEN> writes: > No,
 the hooks are called
 from signal_after_change, AFAICT. Hm, not able to get that working, either...
 Content analysis details:   (-2.9 points, 5.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
 0.0 TVD_RCVD_IP            Message was received from an IP address
 -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%
 [score: 0.0000]
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 42424
Cc: victorhge@HIDDEN, 42424 <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 (---)

Eli Zaretskii <eliz@HIDDEN> writes:

> No, the hooks are called from signal_after_change, AFAICT.

Hm, not able to get that working, either...

> And I'm probably missing something, because I don't understand how
> calling the hooks from replace-match would help: replace_range is
> called just once from replace-match, and the hooks are invoked at its
> very end.  What am I missing?

Because replace-match does this:

    replace_range (sub_start, sub_end, newtext, 1, 0, 1, true, true);

[...]

  /* Now move point "officially" to the end of the inserted replacement.  */
  move_if_not_intangible (newpoint);

And that leaves point somewhere odd if the hook has inserted more text
at the start of the buffer.

My idea was to try to see whether moving the hook stuff later would fix
the issue (and not regress anything).  Basically:

diff --git a/src/search.c b/src/search.c
index df384e1dcf..2c0d58c523 100644
--- a/src/search.c
+++ b/src/search.c
@@ -2725,15 +2726,21 @@ DEFUN ("replace-match", Freplace_match, Sreplace_match, 1, 5, 0,
   newpoint = sub_start + SCHARS (newtext);
 
   /* Replace the old text with the new in the cleanest possible way.  */
-  replace_range (sub_start, sub_end, newtext, 1, 0, 1, true);
-
-  if (case_action == all_caps)
-    Fupcase_region (make_fixnum (search_regs.start[sub]),
-		    make_fixnum (newpoint),
-		    Qnil);
-  else if (case_action == cap_initial)
-    Fupcase_initials_region (make_fixnum (search_regs.start[sub]),
-			     make_fixnum (newpoint), Qnil);
+  {
+    ptrdiff_t count = SPECPDL_INDEX ();
+    specbind (Qinhibit_modification_hooks, Qt);
+
+    replace_range (sub_start, sub_end, newtext, 1, 0, 1, true);
+
+    if (case_action == all_caps)
+      Fupcase_region (make_fixnum (search_regs.start[sub]),
+		      make_fixnum (newpoint),
+		      Qnil);
+    else if (case_action == cap_initial)
+      Fupcase_initials_region (make_fixnum (search_regs.start[sub]),
+			       make_fixnum (newpoint), Qnil);
+    unbind_to (count, Qnil);
+  }
 
   /* The replace_range etc. functions can trigger modification hooks
      (see signal_before_change and signal_after_change).  Try to error
@@ -2750,6 +2757,9 @@ DEFUN ("replace-match", Freplace_match, Sreplace_match, 1, 5, 0,
   /* Now move point "officially" to the end of the inserted replacement.  */
   move_if_not_intangible (newpoint);
 
+  signal_after_change (sub_start, sub_end - sub_start, SCHARS (newtext));
+  update_compositions (sub_start, newpoint, CHECK_BORDER);
+  
   return Qnil;
 }


But that does not seem to call the modification hook at all in the test
case.  Am I doing something obviously wrong here?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




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

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


Received: (at 42424) by debbugs.gnu.org; 31 Jul 2021 14:20:39 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Jul 31 10:20:39 2021
Received: from localhost ([127.0.0.1]:34565 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1m9pqw-0001am-QX
	for submit <at> debbugs.gnu.org; Sat, 31 Jul 2021 10:20:39 -0400
Received: from eggs.gnu.org ([209.51.188.92]:44550)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1m9pqu-0001aa-Li
 for 42424 <at> debbugs.gnu.org; Sat, 31 Jul 2021 10:20:37 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e]:49564)
 by eggs.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <eliz@HIDDEN>)
 id 1m9pqp-00035B-De; Sat, 31 Jul 2021 10:20:31 -0400
Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:2955
 helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1m9pqo-0008Ik-VB; Sat, 31 Jul 2021 10:20:31 -0400
Date: Sat, 31 Jul 2021 17:20:16 +0300
Message-Id: <835ywqpntr.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Lars Ingebrigtsen <larsi@HIDDEN>
In-Reply-To: <87r1fefum7.fsf@HIDDEN> (message from Lars Ingebrigtsen on Sat, 
 31 Jul 2021 16:03:44 +0200)
Subject: Re: bug#42424: 27.0.90; replace-match: point is NOT left at the end
 of replacement
References: <CAMks0JH0N=BAEjBnGrU-jfT=aryrC4jEZDOuJMxAd5N3UpSVbg@HIDDEN>
 <87zh4ltc5l.fsf@HIDDEN> <83tuussr1v.fsf@HIDDEN>
 <87tuusj618.fsf@HIDDEN> <87r1fefum7.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 42424
Cc: victorhge@HIDDEN, 42424 <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: Lars Ingebrigtsen <larsi@HIDDEN>
> Cc: 42424 <at> debbugs.gnu.org,  victorhge@HIDDEN
> Date: Sat, 31 Jul 2021 16:03:44 +0200
> 
> The hook is called from update_compositions, isn't it?  Are there any
> caveats to using that?

No, the hooks are called from signal_after_change, AFAICT.

And I'm probably missing something, because I don't understand how
calling the hooks from replace-match would help: replace_range is
called just once from replace-match, and the hooks are invoked at its
very end.  What am I missing?




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

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


Received: (at 42424) by debbugs.gnu.org; 31 Jul 2021 14:03:58 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Jul 31 10:03:58 2021
Received: from localhost ([127.0.0.1]:34523 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1m9pao-0007Sf-9W
	for submit <at> debbugs.gnu.org; Sat, 31 Jul 2021 10:03:58 -0400
Received: from quimby.gnus.org ([95.216.78.240]:53876)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <larsi@HIDDEN>) id 1m9pal-0007SQ-MA
 for 42424 <at> debbugs.gnu.org; Sat, 31 Jul 2021 10:03:56 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org;
 s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:
 References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:
 Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender:
 Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:
 List-Subscribe:List-Post:List-Owner:List-Archive;
 bh=XblT+Soe331M2p4afgX8F8VZ5pL16tESb/yBiu8Ayy8=; b=JcUEjmePV/ZQSX9JsXCFvHREOG
 m1HbG7638FSmL2bu7FVs+ikBM8QCx0Rz2oIYnt+saop3GUQbHqHeo5NvUzxuqD4ovwCNkHo1RQulS
 +ufSf71mo1GGvAdqG94MZIq7iBXKl0uWWaI4k4XfpAMnRugchbSJczx974S3I8MIdH+c=;
Received: from 2.149.45.105.tmi.telenormobil.no ([2.149.45.105] helo=elva)
 by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.92) (envelope-from <larsi@HIDDEN>)
 id 1m9pac-0004Je-99; Sat, 31 Jul 2021 16:03:49 +0200
From: Lars Ingebrigtsen <larsi@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#42424: 27.0.90; replace-match: point is NOT left at the end
 of replacement
References: <CAMks0JH0N=BAEjBnGrU-jfT=aryrC4jEZDOuJMxAd5N3UpSVbg@HIDDEN>
 <87zh4ltc5l.fsf@HIDDEN> <83tuussr1v.fsf@HIDDEN>
 <87tuusj618.fsf@HIDDEN>
Date: Sat, 31 Jul 2021 16:03:44 +0200
In-Reply-To: <87tuusj618.fsf@HIDDEN> (Lars Ingebrigtsen's message of "Sun,
 18 Oct 2020 10:24:19 +0200")
Message-ID: <87r1fefum7.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 @@CONTACT_ADDRESS@@ for details.
 Content preview:  Lars Ingebrigtsen <larsi@HIDDEN> writes: >> Other types
 of modification (insert or delete) do not have this issue. >> `point' is
 adjusted
 before running modification hooks. > > So I think the suggestion is to move
 point to the end of the rep [...] 
 Content analysis details:   (-2.9 points, 5.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
 0.0 TVD_RCVD_IP            Message was received from an IP address
 -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%
 [score: 0.0000]
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 42424
Cc: victorhge@HIDDEN, 42424 <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 (---)

Lars Ingebrigtsen <larsi@HIDDEN> writes:

>> Other types of modification (insert or delete) do not have this issue.
>> `point' is adjusted before running modification hooks.
>
> So I think the suggestion is to move point to the end of the replacement
> before running the modification hooks, i.e., move the point logic to
> replace_range.

No, that was wrong -- the suggestion was to not move point to the end of
the replacement text (numerically speaking).  But we can't do that --
the `replace-match' interface guarantees that it will do that, and
changing this will break stuff.

The modification hooks may do all kinda of oddball stuff that changes
the buffer before moving to that point, so to make that work more
reliably, we'd have to make a marker, I think?  But `replace-match' is
used so heavily that I'm not sure the performance impact won't be
noticeable.

One possible idea is to postpone the modification hooks until the end of
replace_match (instead of doing it in replace_range -- that should have
no performance impact, and not change behaviour in most cases.  But I'm
having problems making that work.

The hook is called from update_compositions, isn't it?  Are there any
caveats to using that?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




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

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


Received: (at 42424) by debbugs.gnu.org; 18 Oct 2020 08:24:32 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Oct 18 04:24:32 2020
Received: from localhost ([127.0.0.1]:36145 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1kU3zU-0006Ux-7z
	for submit <at> debbugs.gnu.org; Sun, 18 Oct 2020 04:24:32 -0400
Received: from quimby.gnus.org ([95.216.78.240]:48792)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <larsi@HIDDEN>) id 1kU3zS-0006Uk-7q
 for 42424 <at> debbugs.gnu.org; Sun, 18 Oct 2020 04:24:30 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org;
 s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:
 References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:
 Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender:
 Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:
 List-Subscribe:List-Post:List-Owner:List-Archive;
 bh=PK6CNu/Xy70A+DFTULuAJElasrx1T0ENXc9pwWN47GU=; b=iQ8tmsceItKafNHISSGLJjf4p6
 M2P6D92vn0npnzfXbFZnglAk59Sm6q5khjxnooGJMgx04BXmFJNKGN7avUfTmeYIKaKG7vCv0nSjc
 bYN7GX6T51L9Z2pla1/mi4YYW/yws8eB/FR89ljqVqqMLGKn8XZSeCfhr1kmtrnrtIcg=;
Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=xo)
 by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.92) (envelope-from <larsi@HIDDEN>)
 id 1kU3zJ-0006PN-75; Sun, 18 Oct 2020 10:24:23 +0200
From: Lars Ingebrigtsen <larsi@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#42424: 27.0.90; replace-match: point is NOT left at the end
 of replacement
References: <CAMks0JH0N=BAEjBnGrU-jfT=aryrC4jEZDOuJMxAd5N3UpSVbg@HIDDEN>
 <87zh4ltc5l.fsf@HIDDEN> <83tuussr1v.fsf@HIDDEN>
Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAABGdBTUEAALGPC/xhBQAAACBj
 SFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAFVBMVEVDNUhYT2KHdIYf
 GCT0zK+oXWX////KAn60AAAAAWJLR0QGYWa4fQAAAAd0SU1FB+QKEgciIGgyBOwAAAG7SURBVDjL
 XZRBcsMgDEWlquzBHvY2SfakTA/Qjr13Oub+V6mEwNAyWWT0pP9BCAMAoHV1TZQSB6z8Iv+BC9yS
 LECnoFVMISRdkg14FTgXbqmhCBYHsAzAdXMX1g6InTq4UwMp4VhxXzqA0eP+TQ1E7CCE+zZ386sk
 CLhdQCuwgu/5OmIBVk4Z2GNu5qjnsKI3jQcEBQQqlkYgyaCdWUZQmkjFy7awycXcWqBS0uJ+24oU
 WydJqDuKHFeA5V7AaTfAnwr6BZd05/N2ASpAlPBV8qsUJQHISv5lNN5AqWPXPNd4ATMUQNHl/Lnl
 LkUVPH0+TB6kSDdFbz4TXlLcQQUoIJpt8KCyW5yRwXsHFitIi8/QAceoaGGyJhszANSOTOTM8e4H
 DwbiFGg1x3mMB+Qbj8iPZkV77gOQKREaA1q//QM8IPNHsHB5XyC4eXossfV2yxVMqyOew96RrHfq
 pgViCKuFP8AKwGd4vJz1/yr4UcXw+Fmduu/b0QDPFLKWU5PcgeMR4We+Kjh3HajyDig9xV7BVywf
 DlAgYk7c9/OQgUYlc5m2qQJTkgWgTnpEnsM9v7wagzyoOtEK8i+W2o66dNtRxAAAACV0RVh0ZGF0
 ZTpjcmVhdGUAMjAyMC0xMC0xOFQwNzozNDozMiswMDowMGkk31EAAAAldEVYdGRhdGU6bW9kaWZ5
 ADIwMjAtMTAtMThUMDc6MzQ6MzIrMDA6MDAYeWftAAAAAElFTkSuQmCC
X-Now-Playing: Rocket To The Sky's _Cigars_: "Cigars"
Date: Sun, 18 Oct 2020 10:24:19 +0200
In-Reply-To: <83tuussr1v.fsf@HIDDEN> (Eli Zaretskii's message of "Sat, 17 Oct
 2020 20:25:32 +0300")
Message-ID: <87tuusj618.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 @@CONTACT_ADDRESS@@ for details.
 Content preview: Eli Zaretskii <eliz@HIDDEN> writes: >> Uhm... is that
 comment
 wrong? Aren't we moving point to the end of the >> inserted replacement?
 > > Yes, it should say "end", not "start". Fixed now. 
 Content analysis details:   (-2.9 points, 5.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
 -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%
 [score: 0.0000]
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 42424
Cc: 42424 <at> debbugs.gnu.org, victorhge@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:

>> Uhm...  is that comment wrong?  Aren't we moving point to the end of the
>> inserted replacement?
>
> Yes, it should say "end", not "start".

Fixed now.

> Personally, I wonder what was expected here.  If the modification
> hooks modify the replaced text behind our back, how can the Lisp
> program which does that expect to have point where it belongs?  Am I
> missing something?

No, the semantics are pretty unclear, and it's not obvious whether we
can guarantee anything here.  But the bug reporter notes:

> Other types of modification (insert or delete) do not have this issue.
> `point' is adjusted before running modification hooks.

So I think the suggestion is to move point to the end of the replacement
before running the modification hooks, i.e., move the point logic to
replace_range.  But I'm not actually sure where the modification hooks
are being run from...

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




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

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


Received: (at 42424) by debbugs.gnu.org; 17 Oct 2020 17:25:43 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Oct 17 13:25:43 2020
Received: from localhost ([127.0.0.1]:35459 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1kTpxf-0001XK-D5
	for submit <at> debbugs.gnu.org; Sat, 17 Oct 2020 13:25:43 -0400
Received: from eggs.gnu.org ([209.51.188.92]:58150)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1kTpxd-0001X5-2m
 for 42424 <at> debbugs.gnu.org; Sat, 17 Oct 2020 13:25:42 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e]:58803)
 by eggs.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <eliz@HIDDEN>)
 id 1kTpxX-0000Q1-9T; Sat, 17 Oct 2020 13:25:35 -0400
Received: from [176.228.60.248] (port=2103 helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <eliz@HIDDEN>)
 id 1kTpxV-00081f-54; Sat, 17 Oct 2020 13:25:34 -0400
Date: Sat, 17 Oct 2020 20:25:32 +0300
Message-Id: <83tuussr1v.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Lars Ingebrigtsen <larsi@HIDDEN>
In-Reply-To: <87zh4ltc5l.fsf@HIDDEN> (message from Lars Ingebrigtsen on Sat, 
 17 Oct 2020 11:49:42 +0200)
Subject: Re: bug#42424: 27.0.90;
 replace-match: point is NOT left at the end of replacement
References: <CAMks0JH0N=BAEjBnGrU-jfT=aryrC4jEZDOuJMxAd5N3UpSVbg@HIDDEN>
 <87zh4ltc5l.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 42424
Cc: 42424 <at> debbugs.gnu.org, victorhge@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: Lars Ingebrigtsen <larsi@HIDDEN>
> Date: Sat, 17 Oct 2020 11:49:42 +0200
> Cc: 42424 <at> debbugs.gnu.org
> 
>   /* Put point back where it was in the text, if possible.  */
>   TEMP_SET_PT (clip_to_bounds (BEGV, opoint + (opoint <= 0 ? ZV : 0), ZV));
>   /* Now move point "officially" to the start of the inserted replacement.  */
>   move_if_not_intangible (newpoint);
> 
> Uhm...  is that comment wrong?  Aren't we moving point to the end of the
> inserted replacement?

Yes, it should say "end", not "start".

>   /* The replace_range etc. functions can trigger modification hooks
>      (see signal_before_change and signal_after_change).  Try to error
>      out if these hooks clobber the match data since clobbering can
>      result in confusing bugs.  Although this sanity check does not
>      catch all possible clobberings, it should catch many of them.  */
>   if (! (search_regs.num_regs == num_regs
> 	 && search_regs.start[sub] == newstart
> 	 && search_regs.end[sub] == newpoint))
>     error ("Match data clobbered by buffer modification hooks");
> 
> So replace_match is already signalling some errors on buffer
> modification hooks, but not here.  So is this a bug or just something
> that should be documented better?

Personally, I wonder what was expected here.  If the modification
hooks modify the replaced text behind our back, how can the Lisp
program which does that expect to have point where it belongs?  Am I
missing something?




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

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


Received: (at 42424) by debbugs.gnu.org; 17 Oct 2020 09:49:55 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Oct 17 05:49:55 2020
Received: from localhost ([127.0.0.1]:33362 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1kTiqZ-0002Oc-9A
	for submit <at> debbugs.gnu.org; Sat, 17 Oct 2020 05:49:55 -0400
Received: from quimby.gnus.org ([95.216.78.240]:38346)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <larsi@HIDDEN>) id 1kTiqX-0002OO-Af
 for 42424 <at> debbugs.gnu.org; Sat, 17 Oct 2020 05:49:53 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org;
 s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:
 References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:
 Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender:
 Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:
 List-Subscribe:List-Post:List-Owner:List-Archive;
 bh=nhHZ1pGYzn9tEhB71/lvc+a5OlFoTw/u30iAzKFmceQ=; b=Z9Jr/h5OXqFWntt2sE1GEmOZlP
 7iYmjjrFR52s1I0Mtr+wLdQ1Bjcn8867KDDPzqCYJUpuVhMGXxTj5FzGraoLjMhL5MmT20s9thAAu
 BZ7ya7JBbprzA1mSnZTp0fTPHvKzdoa/Scak51MWL+gtNXtfiHRlVBCbFIIyHqbjaf24=;
Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=xo)
 by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.92) (envelope-from <larsi@HIDDEN>)
 id 1kTiqO-0002Bt-69; Sat, 17 Oct 2020 11:49:46 +0200
From: Lars Ingebrigtsen <larsi@HIDDEN>
To: Ren Victor <victorhge@HIDDEN>
Subject: Re: bug#42424: 27.0.90; replace-match: point is NOT left at the end
 of replacement
References: <CAMks0JH0N=BAEjBnGrU-jfT=aryrC4jEZDOuJMxAd5N3UpSVbg@HIDDEN>
X-Now-Playing: Machinedrum's _Vapor City Citizenship Programme_: "Vapor City
 - Vizion Centre Mix"
Date: Sat, 17 Oct 2020 11:49:42 +0200
In-Reply-To: <CAMks0JH0N=BAEjBnGrU-jfT=aryrC4jEZDOuJMxAd5N3UpSVbg@HIDDEN>
 (Ren Victor's message of "Sun, 19 Jul 2020 13:50:51 +0800")
Message-ID: <87zh4ltc5l.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 @@CONTACT_ADDRESS@@ for details.
 Content preview: Ren Victor <victorhge@HIDDEN> writes: > In `replace_range',
 the point is also relocated. I am not sure why it has > to be moved again
 just before returning from `replace-match'. I can reproduce this error on
 Emacs 28. 
 Content analysis details:   (-2.9 points, 5.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
 -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%
 [score: 0.0000]
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 42424
Cc: 42424 <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: -1.0 (-)

Ren Victor <victorhge@HIDDEN> writes:

> In `replace_range', the point is also relocated.  I am not sure why it has
> to be moved again just before returning from `replace-match'.

I can reproduce this error on Emacs 28.

The problem seems to be this in Freplace_match?  

  /* Put point back where it was in the text, if possible.  */
  TEMP_SET_PT (clip_to_bounds (BEGV, opoint + (opoint <= 0 ? ZV : 0), ZV));
  /* Now move point "officially" to the start of the inserted replacement.  */
  move_if_not_intangible (newpoint);

Uhm...  is that comment wrong?  Aren't we moving point to the end of the
inserted replacement?

Anyway, removing that move makes the suggested test not fail, but it
leads to a bunch of other tests failing, so it's doing something right,
at least.

However, just before that, there's this:

  /* The replace_range etc. functions can trigger modification hooks
     (see signal_before_change and signal_after_change).  Try to error
     out if these hooks clobber the match data since clobbering can
     result in confusing bugs.  Although this sanity check does not
     catch all possible clobberings, it should catch many of them.  */
  if (! (search_regs.num_regs == num_regs
	 && search_regs.start[sub] == newstart
	 && search_regs.end[sub] == newpoint))
    error ("Match data clobbered by buffer modification hooks");

So replace_match is already signalling some errors on buffer
modification hooks, but not here.  So is this a bug or just something
that should be documented better?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




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

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


Received: (at submit) by debbugs.gnu.org; 19 Jul 2020 05:52:11 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Jul 19 01:52:11 2020
Received: from localhost ([127.0.0.1]:59868 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1jx2F9-0001cO-Bh
	for submit <at> debbugs.gnu.org; Sun, 19 Jul 2020 01:52:11 -0400
Received: from lists.gnu.org ([209.51.188.17]:55122)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <victorhge@HIDDEN>) id 1jx2F7-0001cG-Sl
 for submit <at> debbugs.gnu.org; Sun, 19 Jul 2020 01:52:10 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:47414)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <victorhge@HIDDEN>)
 id 1jx2F7-0002w0-KD
 for bug-gnu-emacs@HIDDEN; Sun, 19 Jul 2020 01:52:09 -0400
Received: from mail-io1-xd32.google.com ([2607:f8b0:4864:20::d32]:34751)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <victorhge@HIDDEN>)
 id 1jx2F5-0000WC-Kq
 for bug-gnu-emacs@HIDDEN; Sun, 19 Jul 2020 01:52:09 -0400
Received: by mail-io1-xd32.google.com with SMTP id q74so14431921iod.1
 for <bug-gnu-emacs@HIDDEN>; Sat, 18 Jul 2020 22:52:06 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:from:date:message-id:subject:to;
 bh=hluyL3EFDNOIPxxJBZ9RlYB4uvv+Fm0elca/nTOA9CQ=;
 b=oaPEre84GoyiyYTc/Sa4L8wjUlX0v79xkdLV5tpZ0Hi4SZj0od3oz9uxpF6hQd6HHE
 dfnuGBX1MiuLiqoFtEfQTVVsKbPwwZlTQxlJ1eDasZ80Qa4ATxeclXS5TcBnEUJYp92h
 fWBJ8ztXOnLJF9L9fKqF7quwCR+Zq48gT5BAyoBvkTPgsdyrq9ZgkvuJjILhtHrKW0wM
 IQTiv4eA0aDZ57Jx2WtbhL1qE06vntg9QGqxv1PU1Eq5fj4PdwpvMD/7RbAft/MGFPz9
 PzEo2XxxeQ+rKteTKvWvDdzgnJ/iHmWzhxKKR/RpWnTInxULQ8CKsGzCIf5Zm/58rES7
 fL0Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:from:date:message-id:subject:to;
 bh=hluyL3EFDNOIPxxJBZ9RlYB4uvv+Fm0elca/nTOA9CQ=;
 b=gZPzNfSmoHl2gWrjgi0Agl2fLQg1wabM41P8WWS9QNEthUONmE+NqpKlW+6nOBpMkA
 jhSnXPIds2sZKpr9AtVIqgL0gy4ZUzTiyfh2h81WIGoiLlk0O6qNjRKDWKy/JeH+I0dG
 YCedYTUrXOvW5cVSxQrhpT6Pq3HJyXrtUgW7Nes1rI+dVRmGa+6SPb1YKJuBGdlaCNoO
 GCJWInAWj6YxiVnH28j5Dm2TgBLn+3j0D5J7lcRXw2W9lhuEuMBDgvwf7sJpBtdL/kNP
 wQN9+UsXXpVfA61uazizOPeBKzhvxvUcfnoy/KbX/21zywcFcexl7ZwUhRAh0ed/fyym
 c+oA==
X-Gm-Message-State: AOAM531iBNc7tRQlWR+cTlsObUiCeBKaT9Or+FdovBNAFqz2rfZyETPV
 JBFvDnA8H/egLYLfdvG12/Hccbkve7J/mW7UPsI4xNlY
X-Google-Smtp-Source: ABdhPJwSdhcIhlJB5sA2OksIUgDo9N0kIYvjdiKUAbaypt9iL/XQqSoPnQi2fPtBQqQ6P+fYc864bPt76Iwz7WlZs4w=
X-Received: by 2002:a05:6602:1491:: with SMTP id
 a17mr16981363iow.198.1595137925721; 
 Sat, 18 Jul 2020 22:52:05 -0700 (PDT)
MIME-Version: 1.0
From: Ren Victor <victorhge@HIDDEN>
Date: Sun, 19 Jul 2020 13:50:51 +0800
Message-ID: <CAMks0JH0N=BAEjBnGrU-jfT=aryrC4jEZDOuJMxAd5N3UpSVbg@HIDDEN>
Subject: 27.0.90; replace-match: point is NOT left at the end of replacement
To: bug-gnu-emacs@HIDDEN
Content-Type: multipart/mixed; boundary="0000000000006ed3d005aac4fd8c"
Received-SPF: pass client-ip=2607:f8b0:4864:20::d32;
 envelope-from=victorhge@HIDDEN; helo=mail-io1-xd32.google.com
X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache.
 That's all we know.
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001,
 RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 0.7 (/)
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: -2.3 (--)

--0000000000006ed3d005aac4fd8c
Content-Type: text/plain; charset="UTF-8"

I attach an ert case to show the recipe.

This issue happens when modification hooks modify the text before the
end of replacement text.

`replace-match' calls `replace_range' to do the actual replacement,
which can trigger modification hooks.  Before calling `replace_range',
the position of the end of replacement is saved. After `replace_range',
the point is moved to the saved position.

But the end of replacement might be changed inside of
`replace_range'.  So the final movement of point may end up to a wrong
place.

Other types of modification (insert or delete) do not have this issue.
`point' is adjusted before running modification hooks.

In `replace_range', the point is also relocated.  I am not sure why it has
to be moved again just before returning from `replace-match'.

This is not a new issue.  It is in Emacs24 at least.


In GNU Emacs 27.0.90 (build 1, x86_64-pc-cygwin)
 of 2020-03-04 built on moufang2
Repository revision: afff43a72e96fcccabe77ff63226cddd540e068d
Repository branch: master
Windowing system distributor 'Microsoft Corp.', version 10.0.19041
Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
Quit
ert
next-line: End of buffer [3 times]
test-replace-match
Ran 1 tests, 0 results were as expected, 1 unexpected
next-line: End of buffer
previous-line: Beginning of buffer [13 times]
previous-line: Beginning of buffer
Configured using:
 'configure
 --srcdir=/home/kbrown/src/cygpackages/emacs/emacs-27.0.90-1.x86_64/src/emacs-27.0.90
 --prefix=/usr --exec-prefix=/usr --localstatedir=/var --sysconfdir=/etc
 --docdir=/usr/share/doc/emacs --htmldir=/usr/share/doc/emacs/html -C
 --with-w32 'CFLAGS=-ggdb -O2 -pipe -Wall -Werror=format-security
 -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong
 --param=ssp-buffer-size=4
 -fdebug-prefix-map=/home/kbrown/src/cygpackages/emacs/emacs-27.0.90-1.x86_64/build=/usr/src/debug/emacs-27.0.90-1
 -fdebug-prefix-map=/home/kbrown/src/cygpackages/emacs/emacs-27.0.90-1.x86_64/src/emacs-27.0.90=/usr/src/debug/emacs-27.0.90-1'
 CPPFLAGS= LDFLAGS='

Configured features:
XPM JPEG TIFF GIF PNG SOUND DBUS GLIB NOTIFY GFILENOTIFY ACL GNUTLS
LIBXML2 HARFBUZZ ZLIB TOOLKIT_SCROLL_BARS XIM MODULES THREADS JSON
PDUMPER LCMS2 GMP

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Emacs-Lisp

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
format-spec rfc822 mml mml-sec password-cache epa derived epg epg-config
gnus-util rmail rmail-loaddefs text-property-search time-date subr-x
mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils
mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr
mail-utils cl-seq cl-extra seq byte-opt bytecomp byte-compile cconv
cl-macs gv ert pp ewoc debug backtrace help-mode find-func vc-git
diff-mode easymenu easy-mmode cl-loaddefs cl-lib tooltip eldoc electric
uniquify ediff-hook vc-hooks lisp-float-type mwheel disp-table
term/w32-win w32-win w32-vars term/common-win tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode elisp-mode
lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow isearch
timer select scroll-bar mouse jit-lock font-lock syntax facemenu
font-core term/tty-colors frame minibuffer cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote threads dbusbind
gfilenotify w32 lcms2 multi-tty make-network-process emacs)

Memory information:
((conses 16 62659 8699)
 (symbols 48 7750 1)
 (strings 32 21627 1406)
 (string-bytes 1 668356)
 (vectors 16 12971)
 (vector-slots 8 156156 9450)
 (floats 8 40 94)
 (intervals 56 307 1)
 (buffers 1000 14))

--0000000000006ed3d005aac4fd8c
Content-Type: application/octet-stream; name="test_replace_match.el"
Content-Disposition: attachment; filename="test_replace_match.el"
Content-Transfer-Encoding: base64
Content-ID: <f_kcsnspgk0>
X-Attachment-Id: f_kcsnspgk0

KHJlcXVpcmUgJ2VydCkKCihlcnQtZGVmdGVzdCB0ZXN0LXJlcGxhY2UtbWF0Y2ggKCkKICAiVGVz
dCBmb3IgYnVnLiIKICAobGV0ICgoY2hlY2stcG9pbnQgbmlsKQoJKG92LXNldCBuaWwpKQogICAg
KHdpdGgtdGVtcC1idWZmZXIKICAgICAgKGluc2VydCAiYSBhYmMiKQogICAgICAoc2V0cSBvdi1z
ZXQgKG1ha2Utb3ZlcmxheSAzIDUpKQogICAgICAob3ZlcmxheS1wdXQKCSAgIG92LXNldCAnbW9k
aWZpY2F0aW9uLWhvb2tzCgkgICAobGlzdCAobGFtYmRhIChvIGFmdGVyICZyZXN0IF9hcmdzKQoJ
CQkgICAod2hlbiBhZnRlcgoJCQkJIChsZXQgKChpbmhpYml0LW1vZGlmaWNhdGlvbi1ob29rcyB0
KSkKCQkJCSAgIChzYXZlLWV4Y3Vyc2lvbgoJCQkJCSAoZ290by1jaGFyIDIpCgkJCQkJIChpbnNl
cnQgImJjZCIpKSkpKSkpCiAgICAgIChnb3RvLWNoYXIgMykKCSAgKGlmIChzZWFyY2gtZm9yd2Fy
ZCAiYmMiKQoJCSAgKHJlcGxhY2UtbWF0Y2ggImJjZCIpKQogICAgICAoc2hvdWxkIChlcSAocG9p
bnQpIDEwKSkpKSkK
--0000000000006ed3d005aac4fd8c--




Acknowledgement sent to Ren Victor <victorhge@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#42424; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Tue, 9 Apr 2024 15:15:04 UTC

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