From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#65451: 30.0.50; `after-change-functions' are not triggered in the same order the changes are made Date: Tue, 22 Aug 2023 15:22:35 +0300 Message-ID: <83a5ujtgfo.fsf@gnu.org> References: <871qfv2zlk.fsf@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18086"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 65451@debbugs.gnu.org To: Ihor Radchenko Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Aug 22 14:23:18 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qYQPj-0004PR-OE for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 22 Aug 2023 14:23:15 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYQPV-0000g7-VI; Tue, 22 Aug 2023 08:23:01 -0400 Original-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 ) id 1qYQPU-0000fe-E3 for bug-gnu-emacs@gnu.org; Tue, 22 Aug 2023 08:23:00 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYQPU-0001hG-35 for bug-gnu-emacs@gnu.org; Tue, 22 Aug 2023 08:23:00 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qYQPW-0005Y1-I0 for bug-gnu-emacs@gnu.org; Tue, 22 Aug 2023 08:23:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 22 Aug 2023 12:23:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65451 X-GNU-PR-Package: emacs Original-Received: via spool by 65451-submit@debbugs.gnu.org id=B65451.169270695021286 (code B ref 65451); Tue, 22 Aug 2023 12:23:02 +0000 Original-Received: (at 65451) by debbugs.gnu.org; 22 Aug 2023 12:22:30 +0000 Original-Received: from localhost ([127.0.0.1]:58684 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qYQP0-0005XG-Bl for submit@debbugs.gnu.org; Tue, 22 Aug 2023 08:22:30 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59382) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qYQOy-0005X1-DX for 65451@debbugs.gnu.org; Tue, 22 Aug 2023 08:22:29 -0400 Original-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 ) id 1qYQOq-0001Ue-0R; Tue, 22 Aug 2023 08:22:20 -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=B/zX5hQzTxDPiXft1nUmQCxejOPyfMfN5vKUCXqDFbQ=; b=Bec3XbNDTm9cZdedZras fdjT04rXHzPJbSZgfkvlWALk1da09cfOdPfrgpIpyhBL82eWUns7Rim3VWkAzFktpT6LSIHlScigk ZyD516yE2y6s/QOq5pz/6Kmx0Kp3e2q6pCkJEzMrZ430A8OFK5hjrlu8bY+xOP9Fmy8htm05+AUX3 ApS7ORRK1S+iHK/3/Mmnomxzl4rwY8MQYng65JRuZ6qCkuagEfXSJpa9ZXp1WcQ50kSmYqX+e4wzQ rAOO0+ZBOOMsW3fB1OHiPUT6AlDfSOLotQlUpZzdRFkhNjUk7sGXTj/OyyB+L6z0smNZejUWqFJoo EEws1gw92cldFQ==; In-Reply-To: <871qfv2zlk.fsf@localhost> (message from Ihor Radchenko on Tue, 22 Aug 2023 09:30:47 +0000) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:268165 Archived-At: > From: Ihor Radchenko > Date: Tue, 22 Aug 2023 09:30:47 +0000 > > The last bit of the messages corresponds to dabbrev expansion of "UTF" > to "utf-8-unix": > > ⛔ Warning (emacs): Before: 1278 1281 > ⛔ Warning (emacs): Before: 1278 1288 > ⛔ Warning (emacs): After: 1278 1288 delta: 0 > ⛔ Warning (emacs): After: 1278 1288 delta: 7 > > Note how "After: 1278 1288 delta: 0" reports a change of "utf-8-unix" > that did not alter the buffer text size. It is trigerred _before_ > "After: 1278 1288 delta: 7" that corresponds to replacing "UTF" with > "utf-8-unix". The inner Before+After is because replace-match also changes the letter-case of the replaced text (to match the letter-case of the original). > The order of after-change notifications thus do not correspond to the > order of buffer changes. Org mode is relying upon the correct change > order to update parser cache with buffer modifications. I think Org mode is relying on something it should not. This particular use case aside, Emacs is allowed to call a function that changes the buffer from a function that itself changes the buffer, and it is allowed to call that inner function _before_ it did all the changes it intended to do. In such cases you will see Before+After pairs embedded inside an outer Before+After pair, because most functions which end up calling these hooks try not to call them too often, so they generally call the before-hook once at the beginning and the after-hook once near the end. IOW, we try to report all of the changes in one go, instead of reporting them one small chunk (perhaps even one character) at a time. And that inevitably leads to situations like this one. Which is perfectly normal, from my POV, and not a bug at all. I'd hate to make our code more complex, let alone slower, just to satisfy the reliance on the perfect pairing like you do. (We've been through this in other discussions: Org uses these hooks for purposes they were not designed for. The ELisp manual even warns about such assumptions.) > The same recipe using Emacs 27 yields the correct order AFAIR, Emacs 27 had quite a few bugs in this area, which were fixed in development since then. See bug#42424, for example.