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, 22 Aug 2023 12:42:18 +0000 Message-ID: <87jztn1c5x.fsf@localhost> References: <871qfv2zlk.fsf@localhost> <83a5ujtgfo.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1614"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 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 22 14:43:19 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 1qYQj9-0000FM-Hz for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 22 Aug 2023 14:43:19 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYQiu-0001pi-O2; Tue, 22 Aug 2023 08:43:06 -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 1qYQiq-0001jA-76 for bug-gnu-emacs@gnu.org; Tue, 22 Aug 2023 08:43: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 1qYQio-0005wX-TF for bug-gnu-emacs@gnu.org; Tue, 22 Aug 2023 08:42:59 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qYQir-00063P-Le for bug-gnu-emacs@gnu.org; Tue, 22 Aug 2023 08:43:01 -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, 22 Aug 2023 12:43:01 +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.169270812523182 (code B ref 65451); Tue, 22 Aug 2023 12:43:01 +0000 Original-Received: (at 65451) by debbugs.gnu.org; 22 Aug 2023 12:42:05 +0000 Original-Received: from localhost ([127.0.0.1]:58691 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qYQhw-00061p-DW for submit@debbugs.gnu.org; Tue, 22 Aug 2023 08:42:04 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:34675) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qYQhr-00061B-Ev for 65451@debbugs.gnu.org; Tue, 22 Aug 2023 08:42:02 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 2E67D240027 for <65451@debbugs.gnu.org>; Tue, 22 Aug 2023 14:41:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1692708110; bh=Nc1erb2eNyMo8/JHNqiWJmHqKqddDM8TxFGvxkcAVAI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version: Content-Transfer-Encoding:From; b=AnE7qM5OWWGxn3pcAj4P+szehA5u9zZicbotXUj8Cs19GErefkaD3kEjO5GbGUkEZ iZRbeN2JoHbIg2LFzbFdM4jsiEdwwSbFtttzLyP1D8tFx3sAYDPU7DMVo8eA7DYCHp ZdFqQcuJIUH8iOGsyrfs4FulBV2csxLSQfrAMpP336CSRBfkqhn65eLyddGBPDRgQ+ R+PrBjs8sFIEpkbZ7J2vqtWD4kibj1Xny5GhUiXEnSIoSaRP8VPPVMaSG7xsbgBIcG Qs7UbahjTft/EO1HX3vhnZaBH+Lg8ChKy8YblsQOlVpw2xzkK76pnwc9+R5jby4q6I DVDMN6rnxuUeg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4RVTW05TFPz9rxD; Tue, 22 Aug 2023 14:41:48 +0200 (CEST) In-Reply-To: <83a5ujtgfo.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:268166 Archived-At: Eli Zaretskii writes: >> 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. Then, I'd like to point back to the previous discussion where I asked to expose to Elisp information about buffer changes available to tree-sitter. https://yhetil.org/emacs-devel/83tu8jq2vl.fsf@gnu.org/ If there is no guarantee that buffer modifications are not signaled in order, on-the-fly updates of the parsed AST will become impossible for Org, even if using markers (as you suggested in the linked thread). In fact, I am not sure if tree-sitter will behave correctly if it is signaled changes in incorrect order. https://tree-sitter.github.io/tree-sitter/using-parsers#advanced-parsing says In applications like text editors, you often need to re-parse a file after its source code has changed. Tree-sitter is designed to support this use case efficiently. There are two steps required. First, you must edit the syntax tree, which adjusts the ranges of its nodes so that they stay in sync with the code. =20=20=20=20 typedef struct { uint32_t start_byte; uint32_t old_end_byte; uint32_t new_end_byte; TSPoint start_point; TSPoint old_end_point; TSPoint new_end_point; } TSInputEdit; =20=20=20=20 void ts_tree_edit(TSTree *, const TSInputEdit *); Note how the API is similar to `after-change-functions' - it expects edited region boundaries before/after the edit. If Emacs feeds the following to tree-sitter =E2=9B=94 Warning (emacs): After: 1278 1288 delta: 0 =E2=9B=94 Warning (emacs): After: 1278 1288 delta: 7 , the first "edit" query will apply to wrong range in the cached AST. --=20 Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at