From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#70077: An easier way to track buffer changes Date: Sat, 30 Mar 2024 10:09:33 -0400 Message-ID: References: <87sf082gku.fsf@localhost> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23849"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Ihor Radchenko , 70077@debbugs.gnu.org, Yuan Fu , Qiantan Hong , =?UTF-8?Q?Fr=C3=A9d=C3=A9ric?= Bour , =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= , Nicolas Goaziou , Alan Mackenzie , Stephen Leake , Alan Zimmerman , Phillip Lord To: Ihor Radchenko Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Mar 30 15:10:20 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 1rqZPX-0005yL-TK for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 30 Mar 2024 15:10:20 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rqZPH-00027x-TF; Sat, 30 Mar 2024 10:10:03 -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 1rqZPE-00026n-Vs for bug-gnu-emacs@gnu.org; Sat, 30 Mar 2024 10:10:01 -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 1rqZPE-0000PA-Mg for bug-gnu-emacs@gnu.org; Sat, 30 Mar 2024 10:10:00 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rqZPG-0002Uk-Ap for bug-gnu-emacs@gnu.org; Sat, 30 Mar 2024 10:10:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 30 Mar 2024 14:10: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.17118077929556 (code B ref 70077); Sat, 30 Mar 2024 14:10:02 +0000 Original-Received: (at 70077) by debbugs.gnu.org; 30 Mar 2024 14:09:52 +0000 Original-Received: from localhost ([127.0.0.1]:45921 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rqZP3-0002U0-Qu for submit@debbugs.gnu.org; Sat, 30 Mar 2024 10:09:52 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:46519) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rqZOy-0002Tg-Bv for 70077@debbugs.gnu.org; Sat, 30 Mar 2024 10:09:48 -0400 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id D65084413F2; Sat, 30 Mar 2024 10:09:35 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1711807774; bh=I+8yjTTQyk5OdK+fv8vRlM3c6J99C5fgX5uowxede/k=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=CFCDpo+eUwsx5QKS41cGWB1xQg1L98mG5R9OJ+2ZY5A0QFCrUZDssdUfES08/BxFX vh6L8giqk6TFGklZid0HHKNM2hrkFQfwthcPB+NUTXN/jSvQZEfcPijs/Q+krZFIeP HZdacnPuOiivyoXGpXLKmJtEHN+TwOJd13Te28edAFArc7w2yWQmbio3eMabNpDCvW FHA7BtCL1yOUsS5OdOT5qqJBr9tJ1IEYhS+i64D2oayen6Cixqs3WVezjnVV7H8T1V wG646GlTRjsIzoAJmJxZcsHErkxyr62GDTQ8DBJ5XCRDfFX1Jwv8dCRrrpbYKljvST zRjLdpAT41Q7w== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 53C0B4413C2; Sat, 30 Mar 2024 10:09:34 -0400 (EDT) Original-Received: from pastel (unknown [45.72.201.215]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id EBE5712077F; Sat, 30 Mar 2024 10:09:33 -0400 (EDT) In-Reply-To: <87sf082gku.fsf@localhost> (Ihor Radchenko's message of "Sat, 30 Mar 2024 09:51:13 +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:282370 Archived-At: >> The driving design was: >> >> - Try to provide enough info such that it is possible and easy to >> maintain a copy of the buffer simply by applying the reported changes. >> E.g. for uses such as `eglot.el` or `crdt.el`. >> - Make the API less synchronous: take care of combining small changes >> into larger ones, and let the clients decide when they react to changes. > > Before we discuss the API, may you allow me to raise one critical > concern: bug#65451. Thanks, I wasn't aware of it. Note that bug#65451 would affect `track-changes.el` but not its clients nor its API. Well, I guess it couldn't really insulate its clients from such bugs, but it would be `track-changes.el`s responsibility to detect such problems and pass down to its clients something saying "oops we have a problem, you have to do a full-resync". > If my reading of the patch is correct, your code is relying upon the > buffer changes arriving in the same order the changes are being made. Indeed. > I am skeptical that you can achieve the desired patch goals purely > relying upon before/after-change-functions, without reaching down to C > internals. There's a FIXME for that: ;; FIXME: Try and do some sanity-checks (e.g. looking at `buffer-size'), ;; to detect if/when we somehow missed some changes. All the current non-trivial users of *-change-functions have such sanity checks. They're designed to handle those nasty cases where we have a bug in the C code. I don't claim my new API can magically paper over those bugs. The intention to deal with those bugs is: - When they're detected, call the clients with a special value for `before` which says that we lost track of some change, so the client knows that it may be necessary to do a full resync. Luckily for many/most clients a full-resync is only a performance problem (e.g. having to reparse the whole file), tho for some (like lentic) I suspect it can result in an actual loss of information. - Try and fix them, of course. Alan has done a great job in the past fixing many of them (tho apparently still not all). [ And also a great job of convincing me that we *can* and thus *should* fix them. ] IOW, no magic bullet: the clients would still have to somehow handle such a "full-resync"s. The main advantage would be that the job of sanity-checking would be taken care of by `track-changes.el` and the clients would have to check only `before` for a special value to indicate a problem. Stefan