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#66732: tree-sitter fontification doesn't update multi-line syntax reliably Date: Sat, 16 Dec 2023 12:11:07 -0500 Message-ID: References: <878r7s5cdf.fsf@honnef.co> <83fs1tbou1.fsf@gnu.org> <835y1zo3rw.fsf@gnu.org> <2ce274aa-6d01-4d0a-b10c-07f821343fed@gmail.com> <50920549-006c-0153-2471-02e41a3dada7@gutov.dev> <8c7cd429-bdc3-4fac-ad1c-fbad793bf1a0@gmail.com> <231ebcd1-ec30-0432-82e7-d63e11cd65f7@gutov.dev> <765D713E-9923-4F66-9044-9D69C104C9B0@gmail.com> <33fe5d61-5022-67c5-6a65-babde4fb7f91@gutov.dev> <92CACD38-9534-4A07-8DE3-CE8408272FB6@gmail.com> <59CC46F7-867E-4C74-83EC-49B41DF0FAB8@gmail.com> 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="27333"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Dmitry Gutov , Eli Zaretskii , 66732@debbugs.gnu.org, dominik@honnef.co To: Yuan Fu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 16 18:12:24 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 1rEYD9-0006sN-2b for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 16 Dec 2023 18:12:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rEYCp-0008No-9G; Sat, 16 Dec 2023 12:12:03 -0500 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 1rEYCn-0008Ng-Tl for bug-gnu-emacs@gnu.org; Sat, 16 Dec 2023 12:12:02 -0500 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 1rEYCn-0006o3-EV for bug-gnu-emacs@gnu.org; Sat, 16 Dec 2023 12:12:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rEYCn-0008Vu-Hp for bug-gnu-emacs@gnu.org; Sat, 16 Dec 2023 12:12:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 16 Dec 2023 17:12:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66732 X-GNU-PR-Package: emacs Original-Received: via spool by 66732-submit@debbugs.gnu.org id=B66732.170274668032661 (code B ref 66732); Sat, 16 Dec 2023 17:12:01 +0000 Original-Received: (at 66732) by debbugs.gnu.org; 16 Dec 2023 17:11:20 +0000 Original-Received: from localhost ([127.0.0.1]:55876 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rEYC7-0008Ui-W0 for submit@debbugs.gnu.org; Sat, 16 Dec 2023 12:11:20 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:56841) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rEYC4-0008US-1M for 66732@debbugs.gnu.org; Sat, 16 Dec 2023 12:11:19 -0500 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id ED5E480B9B; Sat, 16 Dec 2023 12:11:09 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1702746668; bh=uSlBzV6qBbjN8LPgxXS52k42RUkM2SuxYCaxvMsPP4g=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=iDoR16sBOR9W9Sr84wudzCdRIV1SYxfwTjlMypdhP3lM7/ziY7LaEZwki1+AvLYbd PMa0IE5omGpB79F4Ni5YoJL1fPfxaEW08UQZA6WJwlN2/1VDUJmJHf2bdMftsJBMEZ D5ujqn4V/eYECp80BxBo4bL3L125EvchusU0b4TuPk/MzkSHpKbQNpZcC3qLOYVrSP evxN+vuyj3/OwfroTWANOm41VJxko3H0CC/1JQ1Na7pYNYkF9hHcD0ATL/J+D60YJ6 psPH0/GtdhYeqCvttEIFGLvizIZ5rpJ9xm2NocfMagAkgPGwCxq3S8BulJSvFCexTf gOMr4Mn0/TH5w== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id D79D4808C0; Sat, 16 Dec 2023 12:11:08 -0500 (EST) Original-Received: from pastel (65-110-221-238.cpe.pppoe.ca [65.110.221.238]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id A0D66120E2C; Sat, 16 Dec 2023 12:11:08 -0500 (EST) In-Reply-To: (Stefan Monnier's message of "Sat, 16 Dec 2023 10:22:41 -0500") 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:276364 Archived-At: > Hmm... This `put-text-property` can't be right. > Can you trace `font-lock-fontify-region` and > `font-lock-default-fontify-region` to check that they correctly return > the proper (extended) bounds of the region they (re)fontified? BTW, using the extend-region-function isn't ideal: this is meant for things which can't be refontified separately, so if a change in the buffer causes notification to make changes over a large portion of the buffer we'll end up (re)fontified *right away* that whole large portion even if only a small part (or even no part at all) is displayed. IOW, it'd be better to mark the changed chunks with this `put-text-property`, but to do it before jit&font-lock get triggered. Basically, we'd like to call it from `after-change-functions`, but this can be called *many* times within a single command, so we want to delay it. So we can probably just set a flag that says "there are unprocessed changes" and then sprinkle calls to a "lazy update" function which checks this flag before calling `treesit--font-lock-notifier` (or something similar). One of the places where we'd need the sprinkle would be `pre-redisplay-functions`. Another one might be `syntax-ppss`? Stefan