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#70077: An easier way to track buffer changes Date: Tue, 02 Apr 2024 14:22:29 +0000 Message-ID: <87wmpfsv2y.fsf@localhost> References: <86frw8ewk9.fsf@gnu.org> <86cyrcdy80.fsf@gnu.org> <877chh8fjk.fsf@localhost> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40560"; mail-complaints-to="usenet@ciao.gmane.io" Cc: casouri@gmail.com, 70077@debbugs.gnu.org, qhong@alum.mit.edu, frederic.bour@lakaban.net, joaotavora@gmail.com, mail@nicolasgoaziou.fr, acm@muc.de, Eli Zaretskii , stephen_leake@stephe-leake.org, alan.zimm@gmail.com, phillip.lord@russet.org.uk To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Apr 02 16:23:39 2024 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 1rrf35-000AF2-Oc for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 02 Apr 2024 16:23:39 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rrf2U-0008Kx-NI; Tue, 02 Apr 2024 10:23:02 -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 1rrf2R-0008Jt-4g for bug-gnu-emacs@gnu.org; Tue, 02 Apr 2024 10:22:59 -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 1rrf2Q-00068d-Ry for bug-gnu-emacs@gnu.org; Tue, 02 Apr 2024 10:22:58 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rrf2U-00086J-Jp for bug-gnu-emacs@gnu.org; Tue, 02 Apr 2024 10:23: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, 02 Apr 2024 14:23:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70077 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 70077-submit@debbugs.gnu.org id=B70077.171206776231023 (code B ref 70077); Tue, 02 Apr 2024 14:23:02 +0000 Original-Received: (at 70077) by debbugs.gnu.org; 2 Apr 2024 14:22:42 +0000 Original-Received: from localhost ([127.0.0.1]:54889 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rrf2A-00084J-1r for submit@debbugs.gnu.org; Tue, 02 Apr 2024 10:22:42 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:51447) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rrf27-00083M-NM for 70077@debbugs.gnu.org; Tue, 02 Apr 2024 10:22:40 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id EF7A9240103 for <70077@debbugs.gnu.org>; Tue, 2 Apr 2024 16:22:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1712067750; bh=KsuLsrFU8Ol8cigb1fjaOx9Agwj5H0AYLY41KtcG9oY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=jKD7uwYngrTL8OoGjlW7uL5luUl8Kc6/DlV4K7P3RkUV13cFBxInT4Alg86nKJq9H q6ejhxeSJAfhFUrsdcF3gJ1Po/+OIwCoumN+9owqfXuyPMRYWRn8fQ8eIRQXodK93Q ifp9yP8Hpb4tU3SCHTM+c2Ak6pT8OBde1UKu9UnG+0j83YFEUBQXgcotUiOaVKv4eW jwn1i+mJo21RPH+LhUIEp1wIX6irSI2rUGC5RAbeI5rXgnhg5uKp6Zx4bfPbqJPzoo AwviuIzpitms5ftMRFNg8npFGrC88nxeoJ3y03NSNTnLUDq3KoJW2zDBBAscBx0KIY GT1cPP+2tGGHg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4V897m05gFz9rxD; Tue, 2 Apr 2024 16:22:27 +0200 (CEST) In-Reply-To: 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:282514 Archived-At: Stefan Monnier writes: >>> Do I understand correctly that such bundling may result in a situation >>> when BEFORE is very long? In particular, I am thinking of a situation >>> when there are changes near the beginning and the end of buffer in quick >>> succession. >> Yes! > > I'm not sure how to combine the benefits of combining small changes into > larger ones with the benefits of keeping distant changes separate. I am not sure if combining small changes into larger ones is at all a good idea. The changes are stored in strings, which get allocated and re-allocated repeatedly. Repeated string allocations, especially when strings keep growing towards the buffer size, is likely going to increase consing and make GCs more frequent. > I don't want to expose in the API a "sequence of changes", because > that's difficult to use in general: the only thing a client can conveniently > do with it is to keep their own copy of the buffer (e.g. in the LSP > server) and apply the changes in the order given. But if for some > reason you need to do something else (e.g. convert the position from > charpos to line+col) you're in a world of hurt because (except for the > last element in the sequence) you don't have easy access to the state > the buffer was in when the change was made. Aside... How nice would it be if buffer state and buffer text were persistent. Like in https://code.visualstudio.com/blogs/2018/03/23/text-buffer-reimplementation > We could expose a list of simultaneous (and thus disjoint) changes, > which avoids the last problem. But it's a fair bit more work for us, it > makes the API more complex for the clients, and it's rarely what the > clients really want anyway. FYI, Org parser maintains such a list. We previously discussed a similar API in https://yhetil.org/emacs-bugs/87o7iq1emo.fsf@localhost/ > But it did occur to me that we could solve the "disjoint changes" > problem in the following way: signal the client (from > `before-change-functions`) when a change is about to be made "far" from > the currently pending changes. > > The API would still expose only (BEG END BEFORE) rather than > lists/sequences of changes, but the clients could then decide to record > disjoint changes as they occur and thus create&manage their own > list/sequence of changes. More specifically, someone could come > a create a new API on top which exposes a list/sequence of changes. > > The main downside is that this signal of "upcoming disjoint change" > would have to be called from `before-change-functions`, so the client > would need to be careful as usual (e.g. don't modify the buffer, don't > do any blocking operation, ...). This makes sense. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at