From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#68824: treesitter support for outline-minor-mode Date: Thu, 01 Feb 2024 19:12:17 +0200 Organization: LINKOV.NET Message-ID: <868r44ryzb.fsf@mail.linkov.net> References: <86le8667u7.fsf@mail.linkov.net> <865xza39vp.fsf@gnu.org> <86y1c6q7oh.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4762"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) Cc: 68824@debbugs.gnu.org To: Yuan Fu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Feb 01 18:17:16 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 1rVage-00012x-A6 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 01 Feb 2024 18:17:16 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVagO-0008St-Ou; Thu, 01 Feb 2024 12:17:00 -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 1rVagG-0008QB-8u for bug-gnu-emacs@gnu.org; Thu, 01 Feb 2024 12:16:54 -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 1rVagG-0003bn-0d for bug-gnu-emacs@gnu.org; Thu, 01 Feb 2024 12:16:52 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rVagP-0002IZ-RA for bug-gnu-emacs@gnu.org; Thu, 01 Feb 2024 12:17:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 01 Feb 2024 17:17:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68824 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 68824-submit@debbugs.gnu.org id=B68824.17068077678721 (code B ref 68824); Thu, 01 Feb 2024 17:17:01 +0000 Original-Received: (at 68824) by debbugs.gnu.org; 1 Feb 2024 17:16:07 +0000 Original-Received: from localhost ([127.0.0.1]:43104 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rVafW-0002GZ-Ns for submit@debbugs.gnu.org; Thu, 01 Feb 2024 12:16:07 -0500 Original-Received: from relay9-d.mail.gandi.net ([217.70.183.199]:37597) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rVafU-0002Fx-0d for 68824@debbugs.gnu.org; Thu, 01 Feb 2024 12:16:05 -0500 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id A1703FF806; Thu, 1 Feb 2024 17:15:46 +0000 (UTC) In-Reply-To: <86y1c6q7oh.fsf@mail.linkov.net> (Juri Linkov's message of "Wed, 31 Jan 2024 09:32:46 +0200") X-GND-Sasl: juri@linkov.net 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:279300 Archived-At: Yuan, do you think it makes sense to add a new optional arg to 'treesit-search-forward' that will define the traversal order? The problem is that to search the next outline heading in outline-minor-mode, there is a need to visit headings in the same order as they appear in the buffer where a parent is located before its children: * Parent ** Child 1 ** Child 2 Currently 'treesit-search-forward' returns "Child 1" before "Parent". This means that 'treesit-search-forward' should return the topmost matched parent instead of starting to traverse children from the deepest leaf. IOW, it's necessary to traverse nodes in this order: o | Ï---------------------11 | | o--------S----------3 12 | | | o--o-+--o 1--+--2 4--+-----7 | | | | o o +-+-+ +--+--+ | | | | | 5 6 8 9 10 Please note there is no 11 or 12 at the parent of S node because it should traverse only the remaining siblings of the parent. This is because remaining parent siblings have treesit-node-start positions greater than treesit-node-start of S node. > +(defun treesit-outline-search (&optional bound move backward looking-at) > + (let* ((current (treesit-node-at (pos-bol))) > + (current (or (treesit-parent-until current treesit-outline-predicate) > + current)) > + (node (treesit-search-forward > + current treesit-outline-predicate backward))