From unknown Fri Jun 20 07:23:31 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#78402 <78402@debbugs.gnu.org> To: bug#78402 <78402@debbugs.gnu.org> Subject: Status: treesit after-change-functions Reply-To: bug#78402 <78402@debbugs.gnu.org> Date: Fri, 20 Jun 2025 14:23:31 +0000 retitle 78402 treesit after-change-functions reassign 78402 emacs submitter 78402 Juri Linkov severity 78402 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Tue May 13 02:33:48 2025 Received: (at submit) by debbugs.gnu.org; 13 May 2025 06:33:48 +0000 Received: from localhost ([127.0.0.1]:57345 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uEjD2-0006VE-81 for submit@debbugs.gnu.org; Tue, 13 May 2025 02:33:48 -0400 Received: from lists.gnu.org ([2001:470:142::17]:47966) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uEjCz-0006UB-2h for submit@debbugs.gnu.org; Tue, 13 May 2025 02:33:45 -0400 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 1uEjCV-0006kH-5R for bug-gnu-emacs@gnu.org; Tue, 13 May 2025 02:33:15 -0400 Received: from relay1-d.mail.gandi.net ([217.70.183.193]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uEjCR-0002Gd-GS for bug-gnu-emacs@gnu.org; Tue, 13 May 2025 02:33:13 -0400 Received: by mail.gandi.net (Postfix) with ESMTPSA id 216F143A71 for ; Tue, 13 May 2025 06:33:06 +0000 (UTC) From: Juri Linkov To: bug-gnu-emacs@gnu.org Subject: treesit after-change-functions Organization: LINKOV.NET X-Debbugs-Cc: Stefan Monnier , Yuan Fu Date: Tue, 13 May 2025 09:27:45 +0300 Message-ID: <87msbh58ke.fsf@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain X-GND-State: clean X-GND-Score: 0 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdeftdefgeefucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecunecujfgurhephffvufhofffkfgggtgesthdtredttdertdenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucggtffrrghtthgvrhhnpefhleejffeivdffjeffhfevudegudfhueeluddvudeigefffedtvdfgleelfeefleenucffohhmrghinhepghhnuhdrohhrghenucfkphepledurdduvdelrddutdehrdduudejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepledurdduvdelrddutdehrdduudejpdhhvghlohepmhgrihhlrdhgrghnughirdhnvghtpdhmrghilhhfrhhomhepjhhurhhisehlihhnkhhovhdrnhgvthdpnhgspghrtghpthhtohepuddprhgtphhtthhopegsuhhgqdhgnhhuqdgvmhgrtghssehgnhhurdhorhhg X-GND-Sasl: juri@linkov.net Received-SPF: pass client-ip=217.70.183.193; envelope-from=juri@linkov.net; helo=relay1-d.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.7 (/) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.3 (/) This new request is the continuation from bug#77256 and https://lists.gnu.org/archive/html/emacs-devel/2025-05/msg00300.html about updating treesit ranges for after-change-functions, particularly for outline--fix-buttons-after-change that uses ranges. Hopefully Yuan could verify how implementable is this: > BTW the fix should be fairly simple, AFAICT: the `treesit.c` code is > told about the buffer change before `after-change-functions` runs, so it > can record "ranges need to be updated" somewhere, and then lazily update > the ranges next time some code uses treesit functions that depend on the > ranges (e.g. outline's after-change function). If the fully automatic > lazy update is too eager, we can delay it to an explicit call to > `treesit-ensure-ranges-are-uptodate` which outline's after-change > function would have to call manually (same as all other current calls > to `treesit-update-ranges`) From debbugs-submit-bounces@debbugs.gnu.org Thu May 15 03:11:23 2025 Received: (at 78402) by debbugs.gnu.org; 15 May 2025 07:11:23 +0000 Received: from localhost ([127.0.0.1]:50458 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uFSkU-0001Ye-BF for submit@debbugs.gnu.org; Thu, 15 May 2025 03:11:23 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]:47152) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1uFSkO-0001YK-53 for 78402@debbugs.gnu.org; Thu, 15 May 2025 03:11:16 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-74248a3359fso615673b3a.2 for <78402@debbugs.gnu.org>; Thu, 15 May 2025 00:11:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747293070; x=1747897870; darn=debbugs.gnu.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=wAI0kIWx1yKeJg9f9Hy2HhB63xsdQqJ6YTVik3o0Ads=; b=ON1t+xW6BeSAJewYO4CRkNyWzTNnkb0J0+keJhOTAO5aIfeS7QUmLbPfG/t+3C3TcH Co6phgG8rTfaNhkA1RrtB3pAqOfENAJF8yYYuwAuV7NodgjZ2QCqFqDINPPIcW3oMKqp j1ZPX2X4A7HFDcEiCBRbRzt2mhuOk61UUBM6+rxi7UIuZSKYCkArdgekaX2iq/pFWvd4 Dey0wUaR0MLK64JLd+R0hgF/hg6oVQyvc97t6nO0OIq4/uavU16+0hhByLrCMIikRom/ lDpPw5ATVUFhLyeobf2NurD4hy9UvUcayNYlI7X4LrkhPoC25onGPZgJIWKXA6SpJcCL CbeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747293070; x=1747897870; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wAI0kIWx1yKeJg9f9Hy2HhB63xsdQqJ6YTVik3o0Ads=; b=eiKdDMHpUO1YD3sZUMsiR3clzC3jMA6dbRRRRMokXD8AiFdM8WAgvPKUX6PtRThhxN nXWc3n3B1QsDed0MrEujwvMBvMg1yO7nM70ft0jPl+hldZGQ/fDrkJ0bI1HbuysFdSPJ ccdNGrFMGp1SMcnfYlLAieeny7LIoLjVGXkFQnFj+Lm/lvAfZC39XpFH5666wW3N26E6 MYBJo7YCQBIIpNxDZKx15C0Ks9LednYXHpJV0Qp2w7bYmscLQsEO7zHKuyc0dVzlmIan /HcdQiZskeNYHVyXeiJ45GCfijO0U8A0s/9ZQp9sHtxrOClfkek31a1hNdzyQxiUD0qI IPHw== X-Gm-Message-State: AOJu0YxQrYVU1SUGuzsZP3chxzL29li55hVjLH/MyYG33XalBy21TSxa RTzI8UcSYyfxRVc+Lowb8mxuPNeVw8vAzM3zj40h38tFO+YkwOigZYZliw== X-Gm-Gg: ASbGncsdr4LiOC1FBOGAUJNQwqZToRv57skwRX6oxXPexBb6p6ENxgY4gG7ciCytjWT QRWKrGxBVr3QQ97vY60h3tAq1cfNlnlkCFNyfp3E3UPTxk8F1+cjfs9FnUH8nUcFMlGsYOV90xv l3KwnwP2Hx5bAeP+012qd5A3JZP27d7OP1EcbNtoqGvYUNWCNTLTAhr6UR+iLGzgadlmiCX6Tn2 hDcfmjwC4xsNMBe22ghZ1gzQtD5MfZqA/52p2lMTOV757gztjGJHzBih7FeHnnio77gvbSAMEXx ehxBjtrVGXOw5tDxhwPP0fxTJPle6Y/tSKsvvdmipfJwXwKpmPDg6amPINTMzEX3x4DfZkYBEE0 = X-Google-Smtp-Source: AGHT+IF1S7PLN4Jt+zvGQvU5pg89/lRquNeaWc4b3qaqYTOV4lOmgLjbJCipyPzqlVTQ1CKQnr8C0w== X-Received: by 2002:a05:6a21:3418:b0:215:e818:9fdf with SMTP id adf61e73a8af0-215ff113049mr9674842637.23.1747293069731; Thu, 15 May 2025 00:11:09 -0700 (PDT) Received: from smtpclient.apple ([2601:646:8f81:6120:fc6f:318d:bb8d:99b2]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b26e30c5dedsm46775a12.65.2025.05.15.00.11.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 May 2025 00:11:09 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.500.181.1.5\)) Subject: Re: bug#78402: treesit after-change-functions From: Yuan Fu In-Reply-To: <87msbh58ke.fsf@mail.linkov.net> Date: Thu, 15 May 2025 00:10:57 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: References: <87msbh58ke.fsf@mail.linkov.net> To: Juri Linkov X-Mailer: Apple Mail (2.3826.500.181.1.5) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 78402 Cc: Stefan Monnier , 78402@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) > On May 12, 2025, at 11:27=E2=80=AFPM, Juri Linkov = wrote: >=20 > This new request is the continuation from bug#77256 and > https://lists.gnu.org/archive/html/emacs-devel/2025-05/msg00300.html > about updating treesit ranges for after-change-functions, > particularly for outline--fix-buttons-after-change that uses ranges. >=20 > Hopefully Yuan could verify how implementable is this: >=20 >> BTW the fix should be fairly simple, AFAICT: the `treesit.c` code is >> told about the buffer change before `after-change-functions` runs, so = it >> can record "ranges need to be updated" somewhere, and then lazily = update >> the ranges next time some code uses treesit functions that depend on = the >> ranges (e.g. outline's after-change function). If the fully = automatic >> lazy update is too eager, we can delay it to an explicit call to >> `treesit-ensure-ranges-are-uptodate` which outline's after-change >> function would have to call manually (same as all other current calls >> to `treesit-update-ranges`) First of all, the affected range could be larger than the changed range = (think inserting =E2=80=9C/*=E2=80=9D into a C buffer, everything behind = the /* is affected). And you don=E2=80=99t really need to remember the = changed range, we already does that in the form of updating the existing = tree-sitter parse-tree with buffer edit information. When we finally = re-parse the buffer, the parser knows the affected range. And we already = rely on that information to selectively update ranges. Specifically, we = get the affected regions of the primary parser (which should be the = superset of all the affected ranges of all the embedded parsers), and = update embedded parser ranges in those regions. It seems that we only need to invoke treesit--pre-redisplay whenever the = root node is accessed (you have to get the root node to accessing any = node in the parse tree). treesit--pre-redisplay, if haven=E2=80=99t = called since last buffer-chars-modified-tick, will force a re-parse on = the primary parser, get the affected region, and update ranges for = embedded parsers on the region. Let me ponder on this a bit more to make sure it=E2=80=99s actually a = good idea. Btw, what=E2=80=99s the issue we=E2=80=99re trying to fix here? If some = lisp want to have up-to-date ranges, it can just call = treesit--pre-redisplay or treesit-update-ranges. Why do we get the = node-outdated error? Yuan= From debbugs-submit-bounces@debbugs.gnu.org Thu May 15 13:08:34 2025 Received: (at 78402) by debbugs.gnu.org; 15 May 2025 17:08:35 +0000 Received: from localhost ([127.0.0.1]:55627 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uFc4P-0004Qh-6j for submit@debbugs.gnu.org; Thu, 15 May 2025 13:08:34 -0400 Received: from relay2-d.mail.gandi.net ([2001:4b98:dc4:8::222]:48465) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uFc4M-0004Pz-7N for 78402@debbugs.gnu.org; Thu, 15 May 2025 13:08:31 -0400 Received: by mail.gandi.net (Postfix) with ESMTPSA id 5215A43873; Thu, 15 May 2025 17:08:21 +0000 (UTC) From: Juri Linkov To: Yuan Fu Subject: Re: bug#78402: treesit after-change-functions In-Reply-To: Organization: LINKOV.NET References: <87msbh58ke.fsf@mail.linkov.net> Date: Thu, 15 May 2025 20:06:14 +0300 Message-ID: <87msbdiz21.fsf@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdefuddtgeefucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufgjohhffffkfgggtgfgsehtkeertddtreejnecuhfhrohhmpefluhhrihcunfhinhhkohhvuceojhhurhhisehlihhnkhhovhdrnhgvtheqnecuggftrfgrthhtvghrnhepieffteejgeehffejuedtiefhudekgeejteekiefgveeuheetvdefgeekkeevkedunecukfhppeeluddruddvledruddthedruddujeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeeluddruddvledruddthedruddujedphhgvlhhopehmrghilhdrghgrnhguihdrnhgvthdpmhgrihhlfhhrohhmpehjuhhriheslhhinhhkohhvrdhnvghtpdhnsggprhgtphhtthhopeefpdhrtghpthhtohepmhhonhhnihgvrhesihhrohdruhhmohhnthhrvggrlhdrtggrpdhrtghpthhtohepjeekgedtvdesuggvsggsuhhgshdrghhnuhdrohhrghdprhgtphhtthhopegtrghsohhurhhisehgmhgrihhlrdgtohhm X-GND-Sasl: juri@linkov.net X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 78402 Cc: Stefan Monnier , 78402@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) > Btw, what’s the issue we’re trying to fix here? If some lisp want to > have up-to-date ranges, it can just call treesit--pre-redisplay or > treesit-update-ranges. Why do we get the node-outdated error? One example where this is needed is updating the outline buttons based on the changed text in a ts-mode buffer. Either after-change-functions or jit-lock-function calls outline--fix-up-all-buttons that uses treesit-outline-search that requires the updated ranges. I see that treesit-indent and treesit-indent-region explicitly calls treesit-update-ranges at the beginning. Is it how treesit command are intended to update ranges for themselves? It would be inefficient to call treesit-update-ranges in treesit-outline-search. From debbugs-submit-bounces@debbugs.gnu.org Sat May 17 17:12:35 2025 Received: (at 78402) by debbugs.gnu.org; 17 May 2025 21:12:35 +0000 Received: from localhost ([127.0.0.1]:51573 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uGOpf-000192-AT for submit@debbugs.gnu.org; Sat, 17 May 2025 17:12:35 -0400 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:38994) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uGOpd-00018j-Fw for 78402@debbugs.gnu.org; Sat, 17 May 2025 17:12:34 -0400 Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 0577F1002EC; Sat, 17 May 2025 17:12:27 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1747516346; bh=R7gObVT4VBL7C2gCjgXAfbmJ0LZH3RusRYBRGmhnzdw=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=omBKgOcH01aYzGeze0Uj5/w+r3ZXz5AlH9U81STCIV3xhr+Cm2Ip5jG5ZJQebUAD0 60i6RDNr/waidLDdHtiu8czeVSaXGhM/i4X/xtB9wZUDSQQ6XwVe7AnZLXl8/e7zS2 hCcuV5YV0j5yTko00qS9vH7g7N/0UPMoIeMaDZJyXNNk7aVzc5RDIBHaQFG3KJfyJK DBNLJOqdQZBMnMDILv0JVlTNshnu++fgMzJMfmXsEJ1+EuBTdfzK52KmUvEp3cU21z EawwHRBWyBy6mnfFmFeWbiLaFE6PKXnvCohvcJR2BPWhuPb+ww6lrP/RUQ1+gGQHtu GNIrYuerOKKXQ== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id F246E100034; Sat, 17 May 2025 17:12:25 -0400 (EDT) Received: from alfajor (104-195-232-56.cpe.teksavvy.com [104.195.232.56]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id BA5541203B5; Sat, 17 May 2025 17:12:25 -0400 (EDT) From: Stefan Monnier To: Yuan Fu Subject: Re: bug#78402: treesit after-change-functions In-Reply-To: Message-ID: References: <87msbh58ke.fsf@mail.linkov.net> Date: Sat, 17 May 2025 17:12:25 -0400 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL -0.214 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 78402 Cc: 78402@debbugs.gnu.org, Juri Linkov X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Btw, what=E2=80=99s the issue we=E2=80=99re trying to fix here? If some l= isp want to have > up-to-date ranges, it can just call treesit--pre-redisplay or > treesit-update-ranges. Why do we get the node-outdated error? Hmm... so what you're saying is that we should do something like the patch below? Stefan diff --git a/lisp/treesit.el b/lisp/treesit.el index a353bc942d3..0c368de6a03 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -4050,6 +4050,9 @@ treesit-outline-search "Search for the next outline heading in the syntax tree. For BOUND, MOVE, BACKWARD, LOOKING-AT, see the descriptions in `outline-search-function'." + (if backward + (treesit-update-ranges bound (point)) + (treesit-update-ranges (point) bound)) (if looking-at (when (treesit-outline--at-point) (pos-bol)) =20 @@ -4136,11 +4139,6 @@ treesit-outline-level =20 level)) =20 -(defun treesit--after-change (beg end _len) - "Force updating the ranges in BEG...END. -Expected to be called after each text change." - (treesit-update-ranges beg end)) - ;;; Hideshow mode =20 (defun treesit-hs-block-end () @@ -4438,8 +4436,7 @@ treesit-major-mode-setup (setq treesit-outline-predicate #'treesit-outline-predicate--from-imenu)) (setq-local outline-search-function #'treesit-outline-search - outline-level #'treesit-outline-level) - (add-hook 'outline-after-change-functions #'treesit--after-change nil = t)) + outline-level #'treesit-outline-level)) =20 ;; Remove existing local parsers. (dolist (ov (overlays-in (point-min) (point-max))) From debbugs-submit-bounces@debbugs.gnu.org Mon May 19 02:49:15 2025 Received: (at 78402) by debbugs.gnu.org; 19 May 2025 06:49:15 +0000 Received: from localhost ([127.0.0.1]:36394 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uGuJH-00089S-Bl for submit@debbugs.gnu.org; Mon, 19 May 2025 02:49:15 -0400 Received: from relay7-d.mail.gandi.net ([217.70.183.200]:52617) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uGuJ4-00088D-OL for 78402@debbugs.gnu.org; Mon, 19 May 2025 02:49:03 -0400 Received: by mail.gandi.net (Postfix) with ESMTPSA id 81EA143950; Mon, 19 May 2025 06:48:55 +0000 (UTC) From: Juri Linkov To: Stefan Monnier Subject: Re: bug#78402: treesit after-change-functions In-Reply-To: Organization: LINKOV.NET References: <87msbh58ke.fsf@mail.linkov.net> Date: Mon, 19 May 2025 09:38:40 +0300 Message-ID: <87ecwl2jgv.fsf@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdefvddtieelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufgjohhffffkfgggtgfgsehtkeertddtreejnecuhfhrohhmpefluhhrihcunfhinhhkohhvuceojhhurhhisehlihhnkhhovhdrnhgvtheqnecuggftrfgrthhtvghrnhepieffteejgeehffejuedtiefhudekgeejteekiefgveeuheetvdefgeekkeevkedunecukfhppeeluddruddvledruddthedruddujeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeeluddruddvledruddthedruddujedphhgvlhhopehmrghilhdrghgrnhguihdrnhgvthdpmhgrihhlfhhrohhmpehjuhhriheslhhinhhkohhvrdhnvghtpdhnsggprhgtphhtthhopeefpdhrtghpthhtohepjeekgedtvdesuggvsggsuhhgshdrghhnuhdrohhrghdprhgtphhtthhopegtrghsohhurhhisehgmhgrihhlrdgtohhmpdhrtghpthhtohepmhhonhhnihgvrhesihhrohdruhhmohhnthhrvggrlhdrtggr X-GND-Sasl: juri@linkov.net X-Spam-Score: -1.7 (-) X-Debbugs-Envelope-To: 78402 Cc: Yuan Fu , 78402@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.7 (--) >> Btw, what’s the issue we’re trying to fix here? If some lisp want to have >> up-to-date ranges, it can just call treesit--pre-redisplay or >> treesit-update-ranges. Why do we get the node-outdated error? > > Hmm... so what you're saying is that we should do something like the > patch below? Maybe Yuan could confirm if `treesit-update-ranges` is already optimized for frequent calls on overlapping ranges that don't need updating and where 'beg' and 'end' fall back to (point-min) and (point-max). > + (if backward > + (treesit-update-ranges bound (point)) > + (treesit-update-ranges (point) bound)) This also requires turning markers into integers before: (when (markerp bound) (setq bound (marker-position bound))) From debbugs-submit-bounces@debbugs.gnu.org Wed May 21 02:38:44 2025 Received: (at 78402) by debbugs.gnu.org; 21 May 2025 06:38:45 +0000 Received: from localhost ([127.0.0.1]:43308 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uHd6C-0004b6-0a for submit@debbugs.gnu.org; Wed, 21 May 2025 02:38:44 -0400 Received: from relay1-d.mail.gandi.net ([2001:4b98:dc4:8::221]:44749) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uHd67-0004a6-Ob for 78402@debbugs.gnu.org; Wed, 21 May 2025 02:38:40 -0400 Received: by mail.gandi.net (Postfix) with ESMTPSA id 272E843A5C; Wed, 21 May 2025 06:38:30 +0000 (UTC) From: Juri Linkov To: Stefan Monnier Subject: Re: bug#78402: treesit after-change-functions In-Reply-To: <87ecwl2jgv.fsf@mail.linkov.net> Organization: LINKOV.NET References: <87msbh58ke.fsf@mail.linkov.net> <87ecwl2jgv.fsf@mail.linkov.net> Date: Wed, 21 May 2025 09:35:18 +0300 Message-ID: <87y0uqa2u1.fsf@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddtgddvfeekucdltddurdegfedvrddttddmucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufgjohhffffkfgggtgfgsehtkeertddtreejnecuhfhrohhmpefluhhrihcunfhinhhkohhvuceojhhurhhisehlihhnkhhovhdrnhgvtheqnecuggftrfgrthhtvghrnhepieffteejgeehffejuedtiefhudekgeejteekiefgveeuheetvdefgeekkeevkedunecukfhppeeluddruddvledruddthedruddujeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeeluddruddvledruddthedruddujedphhgvlhhopehmrghilhdrghgrnhguihdrnhgvthdpmhgrihhlfhhrohhmpehjuhhriheslhhinhhkohhvrdhnvghtpdhnsggprhgtphhtthhopeefpdhrtghpthhtohepjeekgedtvdesuggvsggsuhhgshdrghhnuhdrohhrghdprhgtphhtthhopegtrghsohhurhhisehgmhgrihhlrdgtohhmpdhrtghpthhtohepmhhonhhnihgvrhesihhrohdruhhmohhnthhrvggrlhdrtggr X-GND-Sasl: juri@linkov.net X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 78402 Cc: Yuan Fu , 78402@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) >>> Btw, what’s the issue we’re trying to fix here? If some lisp want to have >>> up-to-date ranges, it can just call treesit--pre-redisplay or >>> treesit-update-ranges. Why do we get the node-outdated error? >> >> Hmm... so what you're saying is that we should do something like the >> patch below? > > Maybe Yuan could confirm if `treesit-update-ranges` > is already optimized for frequent calls on overlapping ranges > that don't need updating and where 'beg' and 'end' fall back > to (point-min) and (point-max). It seems not optimized since in my tests outline-minor-mode is much slower with this change. From debbugs-submit-bounces@debbugs.gnu.org Wed May 21 03:22:06 2025 Received: (at 78402) by debbugs.gnu.org; 21 May 2025 07:22:06 +0000 Received: from localhost ([127.0.0.1]:43776 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uHdm6-0000I6-3t for submit@debbugs.gnu.org; Wed, 21 May 2025 03:22:05 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]:47110) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1uHdm1-0000H5-F3 for 78402@debbugs.gnu.org; Wed, 21 May 2025 03:21:58 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-742c035f2afso2496722b3a.2 for <78402@debbugs.gnu.org>; Wed, 21 May 2025 00:21:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747812111; x=1748416911; darn=debbugs.gnu.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=EkDWq5G0G0Am1JBptsANw2zbW5nLJO9V+cecrfthoPg=; b=LbyHEpcsyXfAmpgRysN2CCeRS5d2OnrUtZ2QTJyixsRr/yhjbSGT3QMSqN/NUwESfi BIDlqyj+RoFXo4An8gTswBjqILXwFmTb4uHMOgtHgxxm/XtngdeKbqr/IAO90T8LHWzl FtrRl5rKbNewAYIhuCdqjXanbyoonxNt8xTQhO5acXz3g64BTSANV1Epb9LKN+m+468t Ykw1GQjDQuK7xOFxPfVaNtvWAaJ2o4AAlW7GOQDtluMSeXul2HorRy85vWk1foXfAkCv ym6v8GL/duWyuGIhqGna9uMRKQMtt4LSkx424jgom3/8OBIvEsFKLVfTOY1wdPxsiSlX H3uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747812111; x=1748416911; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EkDWq5G0G0Am1JBptsANw2zbW5nLJO9V+cecrfthoPg=; b=Y9m44VZeEAkC/vNLDKvIMKt4QVsYBXflj0xiJ/dsRz1pmmN4hmsDXCspfIvqhjgdaA SSDjLH3uTgPmRKnAm7yTaSkmxEoAU6ZTtEcVN2VttfuPHw8gYuVXv5yydLh92yt0ixSt s4YNghX7DPR7anuTOzWABJGODAvt8QAvd8fmF6cLjsk3LsTc2bMr7HUdN2GsM9/n7Tpr yOMkSbGqSDSWyJBAcZaJkwJ68EXgH7SYYGQSHGMa9TwEmDG8w+4s53nu24Fd9zK3nT/1 MnAfVKzPNlpCuoLyeSfrk3md9xNNCuBQeiFsreXSLIvknS+eBOB2LuMVYc5fD8t/yYLY hhew== X-Forwarded-Encrypted: i=1; AJvYcCVP9VsbQ73MfbNmGdD1IKy0VV8RZuvoqywuTYnRyJ8Frx00qnWjSDU+QMrfVpsdzIttFCfu9g==@debbugs.gnu.org X-Gm-Message-State: AOJu0YxFwsKhk+0seZTEKX40dBm+Z05S1F3Dtx/cfpKV+4z1wCgErbId OXI9YAxNB4739+PVNBB1M/XoQfnMMY8qvmi88bQF6/yXz/oNnhEfC9ss X-Gm-Gg: ASbGncs2cUKh3to1EJwdc5IXRMnEcwEHOTj7FSefZqvDHyXtCrMtr+J5XbKtAieHG+n rvU97n983IDE7AGZKscQ+ZqwM4PdqU+Vo3W5dfbrXmAPOpGQEW/BUaNXVSs38cMVa0JUtoxaiA+ q8HrFMVl096qK0n4vItHoHflF5BrAsrWnez5EeTFwRT+EMo4IRrIqTyQEN5sAlfGRe/cgbFXhh5 CjIfRaSucx2aoFRE3eJT+AsSb4iZ160bdlunnE98oDirmUbYFEdKLVfAZvM/oHwI8YGH56BdJrO Xwrv9khpgHxrYb9d5FTaMc2bWDlnblskiH/up2n0VD9BGEhjWsNnUoYAjo/w9pbSdXv9nps6IfG +qUUcfwK2drmMYOO+VlvHWxP6 X-Google-Smtp-Source: AGHT+IG47kAdjM3wV0mUb8UuRWMlHyltnnnOksmnSJNTVhS/JvdLky1DHssssCvb8w3i9/T4bHuX7g== X-Received: by 2002:a17:90b:3b48:b0:2ee:d433:7c50 with SMTP id 98e67ed59e1d1-30e7d5ac7ecmr25195644a91.23.1747812110933; Wed, 21 May 2025 00:21:50 -0700 (PDT) Received: from smtpclient.apple (c-24-4-247-194.hsd1.ca.comcast.net. [24.4.247.194]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-310a67c5703sm335069a91.2.2025.05.21.00.21.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 May 2025 00:21:50 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.500.181.1.5\)) Subject: Re: bug#78402: treesit after-change-functions From: Yuan Fu In-Reply-To: <87y0uqa2u1.fsf@mail.linkov.net> Date: Wed, 21 May 2025 00:21:39 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: <8B27B23F-FF4B-48FF-A3E5-0B93E246D5E6@gmail.com> References: <87msbh58ke.fsf@mail.linkov.net> <87ecwl2jgv.fsf@mail.linkov.net> <87y0uqa2u1.fsf@mail.linkov.net> To: Juri Linkov X-Mailer: Apple Mail (2.3826.500.181.1.5) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 78402 Cc: Stefan Monnier , 78402@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) > On May 20, 2025, at 11:35=E2=80=AFPM, Juri Linkov = wrote: >=20 >>>> Btw, what=E2=80=99s the issue we=E2=80=99re trying to fix here? If = some lisp want to have >>>> up-to-date ranges, it can just call treesit--pre-redisplay or >>>> treesit-update-ranges. Why do we get the node-outdated error? >>>=20 >>> Hmm... so what you're saying is that we should do something like the >>> patch below? >>=20 >> Maybe Yuan could confirm if `treesit-update-ranges` >> is already optimized for frequent calls on overlapping ranges >> that don't need updating and where 'beg' and 'end' fall back >> to (point-min) and (point-max). >=20 > It seems not optimized since in my tests outline-minor-mode > is much slower with this change. Hey, sorry for the delay. I've been busy with real life. As you said, = `treesit-update-ranges` doesn=E2=80=99t have any optimization for = repeated calls. OTOH, `treesit--pre-redisplay` has optimization for = repeated calls while buffer content doesn=E2=80=99t change. Maybe the = patch can use that instead? Yuan= From debbugs-submit-bounces@debbugs.gnu.org Wed May 21 13:47:25 2025 Received: (at 78402) by debbugs.gnu.org; 21 May 2025 17:47:25 +0000 Received: from localhost ([127.0.0.1]:51902 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uHnXI-0003nf-Bg for submit@debbugs.gnu.org; Wed, 21 May 2025 13:47:25 -0400 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:33706) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uHnXB-0003m0-I6 for 78402@debbugs.gnu.org; Wed, 21 May 2025 13:47:19 -0400 Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 7B20310006B; Wed, 21 May 2025 13:47:11 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1747849630; bh=TLUgy5syFq5yjjMzMqZwehHrK1rT6MPeuGLbYUobIeQ=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=MTHmgpHOY83ROeEG5wcXPsBAn/dQ9ZO0ojvMpBzaH0jWOab2YFiM4OD3P2SZtaiYN 5LPKfXre53x9E25kGuq1v9Ot6/XacvbjxumnT6k+9285J9RlhsnzJwiYZ/DI7yZOie VYp9IXbhs17Ta4W9IAFmgO6o+hZJEKEfONKqVL1eKYICCNZHI4h6D6teOvY5pEW7X3 TtepaXENYP7oUu7zCfRqAuE4NzelUHrRcWDkYJVLGZSTUYmh/yuFfFdI3pwnVEtGqT 9cFXvEOchC8F52JUNSaeH5iMhDzRozP3P7Eo6/IbaTjQFgL3QEyqdjDJO3eSL2MG5E Z2zTmxBeM5/zw== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 6A0B6100029; Wed, 21 May 2025 13:47:10 -0400 (EDT) Received: from lechazo (lechon.iro.umontreal.ca [132.204.27.242]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 5B3311203B3; Wed, 21 May 2025 13:47:10 -0400 (EDT) From: Stefan Monnier To: Yuan Fu Subject: Re: bug#78402: treesit after-change-functions In-Reply-To: <8B27B23F-FF4B-48FF-A3E5-0B93E246D5E6@gmail.com> Message-ID: References: <87msbh58ke.fsf@mail.linkov.net> <87ecwl2jgv.fsf@mail.linkov.net> <87y0uqa2u1.fsf@mail.linkov.net> <8B27B23F-FF4B-48FF-A3E5-0B93E246D5E6@gmail.com> Date: Wed, 21 May 2025 13:47:09 -0400 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL 0.089 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 78402 Cc: 78402@debbugs.gnu.org, Juri Linkov X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Yuan Fu [2025-05-21 00:21:39] wrote: >> On May 20, 2025, at 11:35=E2=80=AFPM, Juri Linkov wrot= e: >>>>> Btw, what=E2=80=99s the issue we=E2=80=99re trying to fix here? If so= me lisp want to have >>>>> up-to-date ranges, it can just call treesit--pre-redisplay or >>>>> treesit-update-ranges. Why do we get the node-outdated error? >>>>=20 >>>> Hmm... so what you're saying is that we should do something like the >>>> patch below? >>>=20 >>> Maybe Yuan could confirm if `treesit-update-ranges` >>> is already optimized for frequent calls on overlapping ranges >>> that don't need updating and where 'beg' and 'end' fall back >>> to (point-min) and (point-max). >>=20 >> It seems not optimized since in my tests outline-minor-mode >> is much slower with this change. > > Hey, sorry for the delay. I've been busy with real life. As you said, > `treesit-update-ranges` doesn=E2=80=99t have any optimization for repeated > calls. That seems like a potential problem for existing uses of that function (we're just "lucky" that they're expected to be used once-per-command). > OTOH, `treesit--pre-redisplay` has optimization for repeated calls > while buffer content doesn=E2=80=99t change. Maybe the patch can use that= instead? Like in the patch below? That sounds OK, but then `treesit--pre-redisplay` needs to be renamed to something like `treesit--update` or `treesit--sync`, and maybe `treesit-font-lock-fontify-region`, `treesit-indent`, and `treesit-indent-region` should use that function instead of `treesit-update-ranges`? Stefan diff --git a/lisp/treesit.el b/lisp/treesit.el index 5df8eb70cbf..89edc700f75 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -2615,6 +2615,7 @@ treesit--indent-1 =20 (defun treesit-indent () "Indent according to the result of `treesit-indent-function'." + ;; FIXME: Use `prog-indent-line'? (treesit-update-ranges (line-beginning-position) (line-end-position)) ;; We don't return 'noindent even if no rules match, because @@ -4064,6 +4065,7 @@ treesit-outline-search "Search for the next outline heading in the syntax tree. For BOUND, MOVE, BACKWARD, LOOKING-AT, see the descriptions in `outline-search-function'." + (treesit--pre-redisplay) (if looking-at (when (treesit-outline--at-point) (pos-bol)) =20 @@ -4150,11 +4152,6 @@ treesit-outline-level =20 level)) =20 -(defun treesit--after-change (beg end _len) - "Force updating the ranges in BEG...END. -Expected to be called after each text change." - (treesit-update-ranges beg end)) - ;;; Hideshow mode =20 (defun treesit-hs-block-end () @@ -4452,8 +4449,7 @@ treesit-major-mode-setup (setq treesit-outline-predicate #'treesit-outline-predicate--from-imenu)) (setq-local outline-search-function #'treesit-outline-search - outline-level #'treesit-outline-level) - (add-hook 'outline-after-change-functions #'treesit--after-change nil = t)) + outline-level #'treesit-outline-level)) =20 ;; Remove existing local parsers. (dolist (ov (overlays-in (point-min) (point-max))) From debbugs-submit-bounces@debbugs.gnu.org Thu May 22 01:36:28 2025 Received: (at 78402) by debbugs.gnu.org; 22 May 2025 05:36:29 +0000 Received: from localhost ([127.0.0.1]:58315 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uHybU-0007x0-Cg for submit@debbugs.gnu.org; Thu, 22 May 2025 01:36:28 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]:42476) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1uHybR-0007wT-1O for 78402@debbugs.gnu.org; Thu, 22 May 2025 01:36:26 -0400 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-231fd67a9aeso43147445ad.1 for <78402@debbugs.gnu.org>; Wed, 21 May 2025 22:36:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747892178; x=1748496978; darn=debbugs.gnu.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=2ytUj5FEJ7eWjQCak37Z2PxFc8qb7PEcfSLQfM4WzIQ=; b=OfYnrL/emVBgtSiR+kye2d2cINJccefsAohIRfI8K4odpelRtwIrQv8v9l6OkHGDvU EI4bzbroTIQH3hEEZJPepKsBs6fc0xlU3JmfTXoJnFxCG6UGc3uftAYZZ2Dqvy06jSpL TovCaoe19Ayz8bK37B3TucSRNFzQ5/jFA83vxLBJ4MLv0GN7p27rmb2jSyzrySTSPl/g nraQHNTN9cvYsSZQe2snNljBH8At0JEiI4nDI7JMMERvl9eyLdw+GQPLSOgOgd6okmkk +3iukxxTNmHDItO/A0ymYK3qzoAWOauZciNF7ns32P2hmrjeJt4PG0HR3G6v1nxsnpen U/Tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747892178; x=1748496978; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2ytUj5FEJ7eWjQCak37Z2PxFc8qb7PEcfSLQfM4WzIQ=; b=kfG7myJYmM3Vis03Sh0vGD2cN6yNtBkWEBRwmGeYhuPUiHBtu+97LyDiJj4PkzP3/j fmmz+ras+4KqJ7rVjCWks4gtGr0FOwb6gGVwRaUq8X0ZTHSPiOX4xB6Ro7UZyeokp7Xd iJfX9UnZTh0uGqXiCeJ2OgyZPze6anlm70RAoDW4+2EMn4tpYV5ka+N4cWgKINCw5FXV /S0wBC9cOmrEMrTk3IMESV2CKggikDOxDUVVym3LpKpH2azuq3/FAKUUyajnOru+pm7l 0XW890MT6f8p3b3ErDA5kS609GN8THlKCMHqQPZjEV7/2YTopTM0GKveQHLXDMKy0C+q G+yA== X-Forwarded-Encrypted: i=1; AJvYcCUv8LwZRCMh8yfUq+FuKlXyzTELoSVXLmmsHBJwoNsvufyl1O8cClQUQYeqmKyiyTBD1q8lvw==@debbugs.gnu.org X-Gm-Message-State: AOJu0Yxvifn0acURxe1WwCYOvQxRFhpw+4YrARpbXlv6GAvKDSaEaZbu fRH3V31iqz0PiqU1gx8QCjcENWb47YBtkAxX1zk2xKq4YoLD3R2vy/WQ X-Gm-Gg: ASbGncuGpIYUoMVB/IiktL4BZcuMUNxU5YSWzE7beuZZFezCPoWqefNwYHHm2i+9387 y2evGSS/eproGMTXIjM3LAb2NSyxIF3kWxHR9V7TXg4XbcQLSu4+lp2pCGA0RDtAGhZVEkm9Doi oPrMnku8fGExWMopspMH/wXsvaG29q07k99YGcMyFwFKOulFpLFtkQigXAm+MB1YB8I+H22ylZS BloOQ0kYD/9eqVevUeBrQDOTqRvOYQWjoW107W/fb9XOalNoDfoFT8i5h+lXt2ydO3URnoR2HF4 M8d+dLz6gcRSiS3civ+7An+EDWwMnb+MGBWf3WY+miRgjWu73lwd6wi7N1MGkTgWRV8kMPZcpDR 2rPWx1IHW/5ONp1Pt8ghIy1msw8i2i0Yq/dY= X-Google-Smtp-Source: AGHT+IHtVQAW2SuWqESFmbsWnpkp+d0g3ZfCH69SH474OCxIMTUbsxq3iQYqWD8Zk6cZp8FTq9y4lw== X-Received: by 2002:a17:902:e548:b0:231:ed38:8a92 with SMTP id d9443c01a7336-231ed388babmr325775405ad.25.1747892178515; Wed, 21 May 2025 22:36:18 -0700 (PDT) Received: from smtpclient.apple (c-24-4-247-194.hsd1.ca.comcast.net. [24.4.247.194]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-231d4af1525sm101355055ad.84.2025.05.21.22.36.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 May 2025 22:36:17 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.500.181.1.5\)) Subject: Re: bug#78402: treesit after-change-functions From: Yuan Fu In-Reply-To: Date: Wed, 21 May 2025 22:36:06 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: References: <87msbh58ke.fsf@mail.linkov.net> <87ecwl2jgv.fsf@mail.linkov.net> <87y0uqa2u1.fsf@mail.linkov.net> <8B27B23F-FF4B-48FF-A3E5-0B93E246D5E6@gmail.com> To: Stefan Monnier X-Mailer: Apple Mail (2.3826.500.181.1.5) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 78402 Cc: 78402@debbugs.gnu.org, Juri Linkov X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) > On May 21, 2025, at 10:47=E2=80=AFAM, Stefan Monnier = wrote: >=20 > Yuan Fu [2025-05-21 00:21:39] wrote: >>> On May 20, 2025, at 11:35=E2=80=AFPM, Juri Linkov = wrote: >>>>>> Btw, what=E2=80=99s the issue we=E2=80=99re trying to fix here? = If some lisp want to have >>>>>> up-to-date ranges, it can just call treesit--pre-redisplay or >>>>>> treesit-update-ranges. Why do we get the node-outdated error? >>>>>=20 >>>>> Hmm... so what you're saying is that we should do something like = the >>>>> patch below? >>>>=20 >>>> Maybe Yuan could confirm if `treesit-update-ranges` >>>> is already optimized for frequent calls on overlapping ranges >>>> that don't need updating and where 'beg' and 'end' fall back >>>> to (point-min) and (point-max). >>>=20 >>> It seems not optimized since in my tests outline-minor-mode >>> is much slower with this change. >>=20 >> Hey, sorry for the delay. I've been busy with real life. As you said, >> `treesit-update-ranges` doesn=E2=80=99t have any optimization for = repeated >> calls. >=20 > That seems like a potential problem for existing uses of that function > (we're just "lucky" that they're expected to be used = once-per-command). Kind of, yeah. Most of the time fontification updates the ranges early = enough that other lisp commands/functions never see the state when the = ranges are not up to date. >=20 >> OTOH, `treesit--pre-redisplay` has optimization for repeated calls >> while buffer content doesn=E2=80=99t change. Maybe the patch can use = that instead? >=20 > Like in the patch below? >=20 > That sounds OK, but then `treesit--pre-redisplay` needs to be renamed = to > something like `treesit--update` or `treesit--sync`, and maybe > `treesit-font-lock-fontify-region`, `treesit-indent`, and > `treesit-indent-region` should use that function instead of > `treesit-update-ranges`? >=20 Yeah. On top of that, we can try calling `treesit--pre-redisplay` in = `treesit-node-at`, which should ensure range is always up-to-date. The = downside is the potential cost of updating range for the whole buffer, = especially when an edit changes actually does affect the whole buffer = (like inserting /* in C) and we have to add/remove hundred of local = parsers (eg, for doxygen). Yuan= From debbugs-submit-bounces@debbugs.gnu.org Thu May 22 13:17:48 2025 Received: (at 78402) by debbugs.gnu.org; 22 May 2025 17:17:48 +0000 Received: from localhost ([127.0.0.1]:36987 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uI9YC-0003m6-Ak for submit@debbugs.gnu.org; Thu, 22 May 2025 13:17:48 -0400 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:47619) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uI9Y0-0003jd-Qi for 78402@debbugs.gnu.org; Thu, 22 May 2025 13:17:37 -0400 Received: by mail.gandi.net (Postfix) with ESMTPSA id 2496443B77; Thu, 22 May 2025 17:17:27 +0000 (UTC) From: Juri Linkov To: Stefan Monnier Subject: Re: bug#78402: treesit after-change-functions In-Reply-To: Organization: LINKOV.NET References: <87msbh58ke.fsf@mail.linkov.net> <87ecwl2jgv.fsf@mail.linkov.net> <87y0uqa2u1.fsf@mail.linkov.net> <8B27B23F-FF4B-48FF-A3E5-0B93E246D5E6@gmail.com> Date: Thu, 22 May 2025 20:06:07 +0300 Message-ID: <875xhs8thg.fsf@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddtgdeiheegucdltddurdegfedvrddttddmucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufgjohhffffkfgggtgesthdtredttdertdenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucggtffrrghtthgvrhhnpeffgeetfeevlefhleejfeeuheeiudeitdffhfdutdekfeffgffhveehteegueekheenucfkphepledurdduvdelrddutdefrddvjeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeeluddruddvledruddtfedrvdejpdhhvghlohepmhgrihhlrdhgrghnughirdhnvghtpdhmrghilhhfrhhomhepjhhurhhisehlihhnkhhovhdrnhgvthdpnhgspghrtghpthhtohepfedprhgtphhtthhopeejkeegtddvseguvggssghughhsrdhgnhhurdhorhhgpdhrtghpthhtoheptggrshhouhhrihesghhmrghilhdrtghomhdprhgtphhtthhopehmohhnnhhivghrsehirhhordhumhhonhhtrhgvrghlrdgtrg X-GND-Sasl: juri@linkov.net X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 78402 Cc: Yuan Fu , 78402@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) > @@ -4064,6 +4065,7 @@ treesit-outline-search > "Search for the next outline heading in the syntax tree. > For BOUND, MOVE, BACKWARD, LOOKING-AT, see the descriptions in > `outline-search-function'." > + (treesit--pre-redisplay) > (if looking-at > (when (treesit-outline--at-point) (pos-bol)) Alas, the same error: Error: treesit-node-outdated (#) treesit-node-start(#) treesit-node-enclosed-p(# #) treesit-navigate-thing(252 1 beg html-ts-mode--outline-predicate) treesit-outline-search(#) outline-map-region(# 253 274) outline--fix-up-all-buttons(253 274) outline--fix-buttons(253 257) #f(compiled-function (fun) #)(outline--fix-buttons) run-hook-wrapped(#f(compiled-function (fun) #) outline--fix-buttons) jit-lock--run-functions(253 257) jit-lock-fontify-now(253 401) jit-lock-function(253) redisplay_internal\ \(C\ function\)() From debbugs-submit-bounces@debbugs.gnu.org Sun May 25 23:55:26 2025 Received: (at 78402) by debbugs.gnu.org; 26 May 2025 03:55:26 +0000 Received: from localhost ([127.0.0.1]:51990 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uJOvu-00032B-Ae for submit@debbugs.gnu.org; Sun, 25 May 2025 23:55:26 -0400 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]:57831) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1uJOvr-00031X-GE for 78402@debbugs.gnu.org; Sun, 25 May 2025 23:55:24 -0400 Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-b27015122c4so940193a12.3 for <78402@debbugs.gnu.org>; Sun, 25 May 2025 20:55:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748231717; x=1748836517; darn=debbugs.gnu.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=JksLLpULxBPQrhG0LNA9QvJYk2dutdYs2CCBmpJm96Q=; b=OmeBBW8fRI75OA7ayQB5K1sZsKChN035MofQHiRLV8E/mAA2475mdv9WdSq2IkwvuU bIPOYx07ySlDT11hm06JoGXELSEPEZ08n3NAmvY3P3vHriHyGvh51E3inrLY3UAVkREi b3crvv98h8jb88W4f0ombzcknaWWwkQrwpIjQNO0TCpoYfJ5C7sGcgv/4L9fPUp+sZSH 74OYEtEbjxDHf3gj4OGXnuUfRmeCsG6KyQkSKlN1VzlWM+In+LvA/iNHbmGeekNFjwP1 M/3x5pNqd15+k0B1Mm4BxP09P4wMrjMxtQwDFdgwq8mLaHXHzX6wp1bIypcDkZg/Iy96 RTCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748231717; x=1748836517; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JksLLpULxBPQrhG0LNA9QvJYk2dutdYs2CCBmpJm96Q=; b=D4NpA8CHrq2mkDp3Y9mi13O9j9fzy+/9bGJ59/PEkHEwwwUYyBTPrL0aRgP3ckMvZa GcXOH7Dhm3jitV0ytJbg/JpX1IQG9ixi6fZyBMGJMvmN/C+o78YwznIeXlO37IVLqX9B 2Q78QjVazz0qIqCTeW+BucwXupvLeWyP87NouSqqIYEMPNVvojjgZYFgoNa+fYIbqYBv ZRp+0TvRip8QVAHNj9o1z+Ng1mI0XrqGI/s75y7utsbX2vXsbWkeWxxB+IyBcnG5N4Cd 1H2efkqRicIOL7MyE5chnIbp1+EUUZMlehoB7psFbWZZom5bio+WW6CmJHECDhbh0D70 RKAA== X-Forwarded-Encrypted: i=1; AJvYcCX2puWjYvIpibyiH06gT+EpPtA9ebcIisHEPnYq/K+ZjupkCrubS6sHGerIp3Esln4G5k9gqw==@debbugs.gnu.org X-Gm-Message-State: AOJu0YyVk5L2GbCa3oQJUiIZEWmQTrh/e7JC2QMzRXovJLLUC6UI5vuE sHY+ddJJzN5PG2va73LJM6Lwje4cMT9mWpFmBnbWES+HnofAw3NGNUJ/A3EozQ== X-Gm-Gg: ASbGnctN3yHcOcxTMeGEX9tQNIRqxo58rqmFxnzNIig6mOVuCivjy2cBnw0DY42fJhm tioRZSDToI0O0GGfDhAbsKxfXfCUmAmW6+kBdUFMhuzqCwcGULzpyss1lbqxVdt2sOwzTw0SZGg 0MLig3i2qSoVN536JSpFe6eAxMnpJ1+WbnIWseha9tnOI5sNLbbFZSdkWWHSl6R6r/DbOS8VGii +bAQwW6G4D2gzXYHl3oXeF5EGzy/Ur8NtwYbj49LnpU7DTx5kfMyDiy1BSsSILyXNV4w6tHtDNO 2YJoBXfuVo2+ByHF9SpWvtHhuG3AG+Bgv6xxtn+gHdB+NVTFTOhGga9iKu9Hj++XLyiA4Ihd0zw WJG6wfvIHU/6kWZRz1WtaNyfJ X-Google-Smtp-Source: AGHT+IEd6opITl0SOiS0au47/QjoV8LhfWedxxOz8ykx3H6T2r9Qgn1fwcIhfteU3rfKe3KuVx61Lw== X-Received: by 2002:a17:90a:d44d:b0:2ee:741c:e9f4 with SMTP id 98e67ed59e1d1-3110f20c1efmr12120499a91.11.1748231717257; Sun, 25 May 2025 20:55:17 -0700 (PDT) Received: from smtpclient.apple (c-24-4-247-194.hsd1.ca.comcast.net. [24.4.247.194]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-311251d6563sm3108073a91.37.2025.05.25.20.55.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 May 2025 20:55:16 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.500.181.1.5\)) Subject: Re: bug#78402: treesit after-change-functions From: Yuan Fu In-Reply-To: <875xhs8thg.fsf@mail.linkov.net> Date: Sun, 25 May 2025 20:55:05 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: <2B8134CF-3AAC-4782-9847-2F9F9EA4A27C@gmail.com> References: <87msbh58ke.fsf@mail.linkov.net> <87ecwl2jgv.fsf@mail.linkov.net> <87y0uqa2u1.fsf@mail.linkov.net> <8B27B23F-FF4B-48FF-A3E5-0B93E246D5E6@gmail.com> <875xhs8thg.fsf@mail.linkov.net> To: Juri Linkov X-Mailer: Apple Mail (2.3826.500.181.1.5) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 78402 Cc: Stefan Monnier , 78402@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) > On May 22, 2025, at 10:06=E2=80=AFAM, Juri Linkov = wrote: >=20 >> @@ -4064,6 +4065,7 @@ treesit-outline-search >> "Search for the next outline heading in the syntax tree. >> For BOUND, MOVE, BACKWARD, LOOKING-AT, see the descriptions in >> `outline-search-function'." >> + (treesit--pre-redisplay) >> (if looking-at >> (when (treesit-outline--at-point) (pos-bol)) >=20 > Alas, the same error: Gah! Sorry, I don=E2=80=99t have time to properly look into this right = now. But I=E2=80=99ll try to find some time as soon as possible (pinky = promise). Yuan= From debbugs-submit-bounces@debbugs.gnu.org Sun Jun 01 18:31:22 2025 Received: (at 78402) by debbugs.gnu.org; 1 Jun 2025 22:31:22 +0000 Received: from localhost ([127.0.0.1]:42941 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uLrD7-00069c-TK for submit@debbugs.gnu.org; Sun, 01 Jun 2025 18:31:22 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]:55405) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1uLrD5-00069M-Ku for 78402@debbugs.gnu.org; Sun, 01 Jun 2025 18:31:20 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-7399a2dc13fso4747312b3a.2 for <78402@debbugs.gnu.org>; Sun, 01 Jun 2025 15:31:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748817073; x=1749421873; darn=debbugs.gnu.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=SD/cCpSbwp81hIgJCJYNzw5t9aPQMLI5/3aXHms96Qs=; b=If3TT/hQV9z76PX1BWmJGkRnLjyQsB+5UlW68RUC3sCOhQGOys2YYdioLQ2XjzV/Tq 8wZMzlurCArs7+470ALVK0jFeNWTFnpUruTQQgRXDLx1fanorDie5f6in/P3PhgxJxGq ENoFaAZkD3+7T5QmeA5MxZG1l+V+dZtmI9Cep/s52PiLygl+w9n2BqJMdhOa+C6B5+PB e4UWv1FDVJlda70E1mw8pfUPkui4hqUcMtwHrDfUARhV/xDfFA8nJ6MIsDcMHOfjPUc6 ARPgIBuIT2w0E9JncUwrkn7xYVds8hyx4hG9zQAyhXxsaP5ZXuNOoefOOlfo73FXs1MB fVww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748817073; x=1749421873; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SD/cCpSbwp81hIgJCJYNzw5t9aPQMLI5/3aXHms96Qs=; b=MJKjHW28wfiNNOWAIcaMUG3LW+T1jrvvpwfFNergoSpHqFO2HSXvqF236W7WE7a1Ou Bta8sLtS6S9I05+tniRmqhTHYc6HBlshpfI88JrLx3FqisEJKPm075lB/bKoeULGHflb TTuz+ERYkMKe+oiL9abNkTzfoT3e2XPhz52GGGlwLEBMva4m0R1fWfBfaX+VGSG4f/ZO zpJSXMx1nnOMf5zpVpV6lpaCuhZ3SF3NDsv/IUILVTS5VL/HJCd2wRxFi3lA6PH42ckA FUdthe3YbTl3bqExKfeSasuFowH2u93szT3wpsu5SnBOSpvfkZDwKPhUKhIjGZrqNXRL RmVA== X-Forwarded-Encrypted: i=1; AJvYcCVdwIU+4Vs7oznRzjzQprzEvNTaEeK1SbUkK8U/9wcsfeaE/5EcDFKQxU33PPsorjRc5CWaHg==@debbugs.gnu.org X-Gm-Message-State: AOJu0YxyPCV9TYy7USCGJnI/NICh/4/T7g28d/WLkwm7CjzFzEKan7Ca xUGoJ/LiYEq35TBozaCjlILeTa7ilKwdiP4rA5jrb8wynSd+GtxwktTx X-Gm-Gg: ASbGncvdMUm2BytmLrZklD7AfPw/Rz1uBoAGUawOOQslaKnW7bbXOa7HUep3QGzYCa4 RzQpvEC/YOQDNLAUJhPGWoZM0GQx3WdmVadm5CHm2WiOg+Mfxm/W0zeKHjGFbwMktVPxVsNAheC dnKrOjYq9DVCLy3xUHqY7je9DfCCOHZs3uWmVxdlUqzjpV6oa7Qt49mTtwyath45wVoAa1ksi+C C0LB9YeH9cxiotLgCO7gu+wvpf3OE67p0DOzDCImJbq4kV9NloGmDwuwHKJqY8mAJAME83Tekei mIxb4zOXIiJsJo7L2AnG85LCliMLZfKksohBAvWvWTy0AL1vg1P9ESKiC7WoDarv0Q40VgfEXM7 tuWTctn/u3X7VCMxafIXt+j4Yrd63d2S1uaQ= X-Google-Smtp-Source: AGHT+IHn/j83yKh1p9rfTaz0zdvh1EImXAgE+vBhEnH2UiCCako5QS2tAo3QZ0Bw51biBBc0ilyTUA== X-Received: by 2002:a05:6a21:6d97:b0:1f5:7280:1cdb with SMTP id adf61e73a8af0-21adff88d3amr14344380637.16.1748817073347; Sun, 01 Jun 2025 15:31:13 -0700 (PDT) Received: from smtpclient.apple (c-24-4-247-194.hsd1.ca.comcast.net. [24.4.247.194]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b2eceb29cafsm3854800a12.28.2025.06.01.15.31.12 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Jun 2025 15:31:12 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.500.181.1.5\)) Subject: Re: bug#78402: treesit after-change-functions From: Yuan Fu In-Reply-To: <2B8134CF-3AAC-4782-9847-2F9F9EA4A27C@gmail.com> Date: Sun, 1 Jun 2025 15:31:01 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: <81511474-A79A-4D4A-8C7A-A313B421E138@gmail.com> References: <87msbh58ke.fsf@mail.linkov.net> <87ecwl2jgv.fsf@mail.linkov.net> <87y0uqa2u1.fsf@mail.linkov.net> <8B27B23F-FF4B-48FF-A3E5-0B93E246D5E6@gmail.com> <875xhs8thg.fsf@mail.linkov.net> <2B8134CF-3AAC-4782-9847-2F9F9EA4A27C@gmail.com> To: Juri Linkov X-Mailer: Apple Mail (2.3826.500.181.1.5) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 78402 Cc: Stefan Monnier , 78402@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) > On May 25, 2025, at 8:55=E2=80=AFPM, Yuan Fu = wrote: >=20 >=20 >=20 >> On May 22, 2025, at 10:06=E2=80=AFAM, Juri Linkov = wrote: >>=20 >>> @@ -4064,6 +4065,7 @@ treesit-outline-search >>> "Search for the next outline heading in the syntax tree. >>> For BOUND, MOVE, BACKWARD, LOOKING-AT, see the descriptions in >>> `outline-search-function'." >>> + (treesit--pre-redisplay) >>> (if looking-at >>> (when (treesit-outline--at-point) (pos-bol)) >>=20 >> Alas, the same error: >=20 > Gah! Sorry, I don=E2=80=99t have time to properly look into this right = now. But I=E2=80=99ll try to find some time as soon as possible (pinky = promise). Hi Juri, how did you produce this error? I tried to use the = liquid-generic-ts-mode example in bug#77256 but that didn=E2=80=99t = trigger the error. BTW, I noticed that when tree-sitter-provided outline is in effect, = pressing tab on the lines determined as outline titles=E2=80=94like = first line of a defun=E2=80=94toggles folding instead of indenting the = code. That feels intrusive IMHO. It=E2=80=99s not a problem for = =E2=80=9Ctraditional=E2=80=9D kind of outline headers in comments, but = code is another story. Take this code as example: function MyBigFunc(param1 param2) { const abc =3D 'def'; function embed() { return true; } } Right now I can=E2=80=99t indent the embed function, because pressing = TAB folds it. Another common practice is to select the whole MyBigFunc = function and press TAB to indent everything in the region, that = wouldn=E2=80=99t work if point happens to be on the first line, which is = common. Maybe I should create a separate bug report to discuss/address this? Yuan= From debbugs-submit-bounces@debbugs.gnu.org Tue Jun 03 12:42:45 2025 Received: (at 78402) by debbugs.gnu.org; 3 Jun 2025 16:42:45 +0000 Received: from localhost ([127.0.0.1]:40770 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uMUir-0000XN-9Y for submit@debbugs.gnu.org; Tue, 03 Jun 2025 12:42:45 -0400 Received: from mslow3.mail.gandi.net ([217.70.178.249]:47653) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uMUin-0000X4-LU for 78402@debbugs.gnu.org; Tue, 03 Jun 2025 12:42:42 -0400 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::228]) by mslow3.mail.gandi.net (Postfix) with ESMTP id A8A12582162 for <78402@debbugs.gnu.org>; Tue, 3 Jun 2025 15:39:01 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id EF53843B2B; Tue, 3 Jun 2025 15:38:59 +0000 (UTC) From: Juri Linkov To: Yuan Fu Subject: Re: bug#78402: treesit after-change-functions In-Reply-To: <81511474-A79A-4D4A-8C7A-A313B421E138@gmail.com> Organization: LINKOV.NET References: <87msbh58ke.fsf@mail.linkov.net> <87ecwl2jgv.fsf@mail.linkov.net> <87y0uqa2u1.fsf@mail.linkov.net> <8B27B23F-FF4B-48FF-A3E5-0B93E246D5E6@gmail.com> <875xhs8thg.fsf@mail.linkov.net> <2B8134CF-3AAC-4782-9847-2F9F9EA4A27C@gmail.com> <81511474-A79A-4D4A-8C7A-A313B421E138@gmail.com> Date: Tue, 03 Jun 2025 18:29:45 +0300 Message-ID: <87r0007w7q.fsf@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddugdeiudcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefujghofhffkfgfgggtgfesthekredttderjeenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucggtffrrghtthgvrhhnpeeiffetjeegheffjeeutdeihfdukeegjeetkeeigfevueehtedvfeegkeekveekudenucfkphepledurdduvdelrddutdefrddvjeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeeluddruddvledruddtfedrvdejpdhhvghlohepmhgrihhlrdhgrghnughirdhnvghtpdhmrghilhhfrhhomhepjhhurhhisehlihhnkhhovhdrnhgvthdpnhgspghrtghpthhtohepfedprhgtphhtthhopeejkeegtddvseguvggssghughhsrdhgnhhurdhorhhgpdhrtghpthhtohepmhhonhhnihgvrhesihhrohdruhhmohhnthhrvggrlhdrtggrpdhrtghpthhtoheptggrshhouhhrihesghhmrghilhdrtghomh X-GND-Sasl: juri@linkov.net X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 78402 Cc: Stefan Monnier , 78402@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) >>>> @@ -4064,6 +4065,7 @@ treesit-outline-search >>>> "Search for the next outline heading in the syntax tree. >>>> For BOUND, MOVE, BACKWARD, LOOKING-AT, see the descriptions in >>>> `outline-search-function'." >>>> + (treesit--pre-redisplay) >>>> (if looking-at >>>> (when (treesit-outline--at-point) (pos-bol)) >>> >>> Alas, the same error: >> >> Gah! Sorry, I don’t have time to properly look into this right now. But I’ll try to find some time as soon as possible (pinky promise). > > Hi Juri, how did you produce this error? I tried to use the > liquid-generic-ts-mode example in bug#77256 but that didn’t trigger > the error. You can produce this error by visiting test/manual/indent/html-multi.html with enabled liquid-generic-ts-mode, then delete the word "script" (outside of comments). > BTW, I noticed that when tree-sitter-provided outline is in effect, > pressing tab on the lines determined as outline titles—like first line > of a defun—toggles folding instead of indenting the code. That feels > intrusive IMHO. It’s not a problem for “traditional” kind of outline > headers in comments, but code is another story. > > Take this code as example: > > function MyBigFunc(param1 > param2) { > const abc = 'def'; > function embed() { > return true; > } > } > > Right now I can’t indent the embed function, because pressing TAB > folds it. Another common practice is to select the whole MyBigFunc > function and press TAB to indent everything in the region, that > wouldn’t work if point happens to be on the first line, which is > common. Indeed, there is a clash between TAB keybindings. So to address this ambiguity we created a special option 'outline-minor-mode-cycle-filter' that defines in what context TAB should fold outlines. For example, you can customize: (setopt outline-minor-mode-cycle-filter (lambda () (bolp))) Then TAB will fold only when pressed at the beginning of the line. Anywhere else TAB will indent the line. From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 04 03:31:20 2025 Received: (at 78402) by debbugs.gnu.org; 4 Jun 2025 07:31:20 +0000 Received: from localhost ([127.0.0.1]:46446 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uMial-0008VE-TK for submit@debbugs.gnu.org; Wed, 04 Jun 2025 03:31:20 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]:57553) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1uMiaj-0008Ut-F7 for 78402@debbugs.gnu.org; Wed, 04 Jun 2025 03:31:18 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-2351227b098so45385665ad.2 for <78402@debbugs.gnu.org>; Wed, 04 Jun 2025 00:31:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749022271; x=1749627071; darn=debbugs.gnu.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=AzqSq60/GXF8Qj0qaelovoYDqLzIxlwkp/zRLORdcMY=; b=GP1B/alAXsNH5wJmo5qbThwGU2mz44m3fSga3BQwwFwKtr7nLzoKCYZK86Ma+eFCcR j/Z0UO+5zlO+48yW0w5FLC+hQwc160spBNwFpuCegSRiA1KEErL2/uWGVfh2sBqRzan5 uvApPa04wueG3AT1G3lg7SIPQhoZBMUOINDT4/5n+xMJULnsB5KrMsc3zQQgKMjAt/d/ PrKbpSD/hGwOoXyToH9/CWx67JPbAg9WadOzbxRXHyxF7bi3BYWbvK0c/S2pVcpLGSFX D6X4fPBD42nMrI88qCqffqjW5qRuJitvdRaEIrihnpsRshpd6nWkgYS0BZI4zhskp72W xAWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749022271; x=1749627071; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AzqSq60/GXF8Qj0qaelovoYDqLzIxlwkp/zRLORdcMY=; b=q8EW5FulJziuBQfrViRwFJ/lH9SM1cpW+YrPAs8SRsXoPOz7sdaFFqj4kAefc7sETK +87CsIh/KhNJ+CcjgylMOWBCp3EEANojm5q4bWqy3vjSCuEFEjWRZxgtEWr2Nu/YvE1i 1JbHvwYAiUceZHdQJRQjL67Pz2us9h7sYja1xsyzeUwBazia2N5/FJjkyJhbTz1vZlkK uvOaun3MoLRrWWwlxatlLwME7g/dbT/rexouZ9f6/VPGK1gubkv61EvPGfUaP+FrQnym +rCF/Xs/8Hzj+NU2mw7ZYq/WYKnHYiaFsnFoxoy1fHi7wRuY6U4DfyIr2LOKrBKSRBJd qikw== X-Forwarded-Encrypted: i=1; AJvYcCWCiGCQGjk0JdIKy2mUtrcm4/ObG9UR6ljegCzsZJuQgNbwPMdDAqFP3KGCjuikOjtYNcch2Q==@debbugs.gnu.org X-Gm-Message-State: AOJu0YxOv49qAQk8gdwS11SjMvm2Sd9+OIJIrsCfMk7UXUu69CrW3Pev vfiJu2EZLr/N6qCIHBNw7Tj6w0fqPfbbPs6Irp4BWWJwjhVKz0eA8lKm1tq36w== X-Gm-Gg: ASbGncuqsxsFD2b3eatOQtv+H+B1Q6H2HHlcbi1fnigFi8wh9ye2wU2Zt8wwSm2Us0C nTTewKYvySMNxBObmOgjD1C4ZFS//njYfnq5FXfUsfvqy26elKc3PglSgdpMF3uKKPN84KNqyv9 B9LwnGYGn38s90lcpLBtuese7d9o2FS1YJSsNSJwB9mrQoGmh18mqgyxIprGPsC1Ab3jHPy/QYZ 5ctz09qIw7eV+COBYN1gGLabj3a0DqS4QlOz1o72LyfyuPtLbqbjqdSH61SahhywKKjnObSh7u5 IkzML0W/Se4Bp7pbuXKgHocWKgtby1lihPfeK5JzBBI+SsVLURjeuQBq+j3NznVr4EVhqDV0Q/k M4kPc7UplqNSOK5/4BiVRnmqdYkwMRzpObas= X-Google-Smtp-Source: AGHT+IFlwbt74EtFc6SCNhZF94NUpd8yK0T3k5wzpbJ0cND1h3moa1SBtIyFNLNu+gDa9WwV3+vfew== X-Received: by 2002:a17:903:1a03:b0:235:7c6:ebc2 with SMTP id d9443c01a7336-235e101366dmr26157055ad.4.1749022270919; Wed, 04 Jun 2025 00:31:10 -0700 (PDT) Received: from smtpclient.apple (c-24-4-247-194.hsd1.ca.comcast.net. [24.4.247.194]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-23506bc85acsm98047355ad.12.2025.06.04.00.31.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Jun 2025 00:31:10 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.500.181.1.5\)) Subject: Re: bug#78402: treesit after-change-functions From: Yuan Fu In-Reply-To: <87r0007w7q.fsf@mail.linkov.net> Date: Wed, 4 Jun 2025 00:30:59 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: References: <87msbh58ke.fsf@mail.linkov.net> <87ecwl2jgv.fsf@mail.linkov.net> <87y0uqa2u1.fsf@mail.linkov.net> <8B27B23F-FF4B-48FF-A3E5-0B93E246D5E6@gmail.com> <875xhs8thg.fsf@mail.linkov.net> <2B8134CF-3AAC-4782-9847-2F9F9EA4A27C@gmail.com> <81511474-A79A-4D4A-8C7A-A313B421E138@gmail.com> <87r0007w7q.fsf@mail.linkov.net> To: Juri Linkov X-Mailer: Apple Mail (2.3826.500.181.1.5) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 78402 Cc: Stefan Monnier , 78402@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) > On Jun 3, 2025, at 8:29=E2=80=AFAM, Juri Linkov = wrote: >=20 >>>>> @@ -4064,6 +4065,7 @@ treesit-outline-search >>>>> "Search for the next outline heading in the syntax tree. >>>>> For BOUND, MOVE, BACKWARD, LOOKING-AT, see the descriptions in >>>>> `outline-search-function'." >>>>> + (treesit--pre-redisplay) >>>>> (if looking-at >>>>> (when (treesit-outline--at-point) (pos-bol)) >>>>=20 >>>> Alas, the same error: >>>=20 >>> Gah! Sorry, I don=E2=80=99t have time to properly look into this = right now. But I=E2=80=99ll try to find some time as soon as possible = (pinky promise). >>=20 >> Hi Juri, how did you produce this error? I tried to use the >> liquid-generic-ts-mode example in bug#77256 but that didn=E2=80=99t = trigger >> the error. >=20 > You can produce this error by visiting = test/manual/indent/html-multi.html > with enabled liquid-generic-ts-mode, then delete the word "script" > (outside of comments). Hmm, not sure what I=E2=80=99m doing wrong but I still can=E2=80=99t = trigger the error. I=E2=80=99m using emacs -q, with Stefan=E2=80=99s = patch, enabled liquid mode and outline-minor-mode, and deleted the =