From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ihor Radchenko 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, 29 Aug 2023 07:39:27 +0000 Message-ID: <87o7iq1emo.fsf@localhost> References: <871qfv2zlk.fsf@localhost> <83a5ujtgfo.fsf@gnu.org> <87jztn1c5x.fsf@localhost> <834jkrters.fsf@gnu.org> <87v8d7i48y.fsf@localhost> <83ttsrrroo.fsf@gnu.org> <874jkq87jl.fsf@localhost> <83y1i1r689.fsf@gnu.org> <87fs487uip.fsf@localhost> <83zg2gq2vj.fsf@gnu.org> <871qfsel8q.fsf@localhost> <83r0nsprrk.fsf@gnu.org> <87cyzck1uh.fsf@localhost> <83il94pk49.fsf@gnu.org> <83pm3bocea.fsf@gnu.org> <87o7ivh4js.fsf@localhost> <83cyzamg8l.fsf@gnu.org> <87pm38gax9.fsf@localhost> <83v8d0khvr.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14333"; mail-complaints-to="usenet@ciao.gmane.io" Cc: casouri@gmail.com, 65451@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Aug 29 09:40:31 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 1qatKw-0003Vj-W3 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 29 Aug 2023 09:40:31 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qatKa-0004rH-Dt; Tue, 29 Aug 2023 03:40:08 -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 1qatKO-0004qU-9U for bug-gnu-emacs@gnu.org; Tue, 29 Aug 2023 03:39:56 -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 1qatKN-0001yn-Vx for bug-gnu-emacs@gnu.org; Tue, 29 Aug 2023 03:39:56 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qatKU-0003kO-8y for bug-gnu-emacs@gnu.org; Tue, 29 Aug 2023 03:40:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ihor Radchenko Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 29 Aug 2023 07:40: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.169329475814343 (code B ref 65451); Tue, 29 Aug 2023 07:40:02 +0000 Original-Received: (at 65451) by debbugs.gnu.org; 29 Aug 2023 07:39:18 +0000 Original-Received: from localhost ([127.0.0.1]:49462 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qatJl-0003jH-IU for submit@debbugs.gnu.org; Tue, 29 Aug 2023 03:39:17 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:48301) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qatJi-0003j0-Mc for 65451@debbugs.gnu.org; Tue, 29 Aug 2023 03:39:16 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 2AB49240106 for <65451@debbugs.gnu.org>; Tue, 29 Aug 2023 09:39:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1693294741; bh=54lU5jsNW8jbncxRPta+drUbfQJaGUUxrxjc+AWB2wg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:From; b=DcYA1WSqDWzoYQB8xkiBWWdZesepfWUaESx9YpLifNoPjcI6Q4E087aOqaOsk33M0 0QD0cgnNiz77fT6eXAKybuKO3/HcWvVED/9wS07gbmHUwfVU9YIfW4wVgVP30v4ak/ OSAl01IYyEm67NQ9epdt4kk/deRD5+DZg3nU4jlFBeE38Nvm9laygKBGdAZO737YRQ q8xFKcNyYncAC0xTaU8gvHxrQjqCeNmu/S+fAC2WpL2vhu7wr8XJrU40MwoOzshBy7 l0J54vLDmF7ft+25+yeLp7fC+TmCODjocmW1ZrC3brAgJ2UU0M6Mo3D839CgOg9lNj BbIW3GYyrm02g== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4RZfSN33bfz6txC; Tue, 29 Aug 2023 09:39:00 +0200 (CEST) In-Reply-To: <83v8d0khvr.fsf@gnu.org> 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:268656 Archived-At: Eli Zaretskii writes: >> Then, what about compacting the "edit list" more frequently, so that we >> do not need to worry about its size? But I am not sure what frequency >> will be safe. > > Something like that, yes. But we need to invent a protocol which > would allow several clients to consume the list safely and without the > risk of missing edits. I can think of two approaches: 1. There will be a new buffer-local variable - `buffer-edit-history' that will hold recent `buffer-edit-history-limit' edits. This way, Elisp functions will be able to examine it any time they need to. In addition, there will be `after-edit-functions' hook that will be called after `buffer-edit-history-limit' is exceeded. Before the hook is called, `buffer-edit-history' is truncated. The hook functions will be called with a single argument - list of edits that have been removed from the `buffer-undo-history'. That way, Elisp will be able to process edits that will disappear from the `buffer-edit-history'. Each entry in `buffer-edit-history' will be a list of (beg end_before end_after counter), describing region boundaries before and after the edit + a counter that can be used to keep track of processed positions. The counter will be useful for the code that processes `buffer-edit-history' independently, outside `after-edit-functions', and may need to skip already processed elements. (I initially though that we can simply hold `buffer-chars-modified-tick' here, but it is not necessary to hold `buffer-chars-modified-tick' specifically - just something to indicate "epoch" in the edit history). The downside of exposing `buffer-edit-history' is that some bad-written Elisp may be tempted to hold a pointer to a cons cell in `buffer-edit-history', thus preventing GC. 2. We can have `after-edit-functions' being called once for each edit event with (beg end_before end_after) arguments. To avoid skipping edits, in addition to Emacs sometimes calling the hook, we should allow Elisp to trigger the hook early, by calling `process-buffer-edits'. This way, synchronization can be ensured. The downside here is when multiple consumers are using `after-edit-functions' - synchronization (`process-buffer-edits') requested by one consumer will also trigger all other consumers, potentially creating extra overheads. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at