From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.bugs Subject: bug#68824: treesitter support for outline-minor-mode Date: Thu, 1 Feb 2024 16:34:47 -0800 Message-ID: <3D859057-3DE9-470A-80A4-E0F734A0A622@gmail.com> References: <86le8667u7.fsf@mail.linkov.net> <865xza39vp.fsf@gnu.org> <86y1c6q7oh.fsf@mail.linkov.net> <868r44ryzb.fsf@mail.linkov.net> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) 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="3944"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 68824@debbugs.gnu.org To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Feb 02 01:36: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 1rVhXX-0000qn-Od for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 02 Feb 2024 01:36:19 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVhX8-0008QJ-7n; Thu, 01 Feb 2024 19:35:54 -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 1rVhX6-0008QB-J7 for bug-gnu-emacs@gnu.org; Thu, 01 Feb 2024 19:35:52 -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 1rVhX6-0001bm-Az for bug-gnu-emacs@gnu.org; Thu, 01 Feb 2024 19:35:52 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rVhXG-0003w1-Eo for bug-gnu-emacs@gnu.org; Thu, 01 Feb 2024 19:36:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 02 Feb 2024 00:36:02 +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.170683412215065 (code B ref 68824); Fri, 02 Feb 2024 00:36:02 +0000 Original-Received: (at 68824) by debbugs.gnu.org; 2 Feb 2024 00:35:22 +0000 Original-Received: from localhost ([127.0.0.1]:43355 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rVhWb-0003uv-Ks for submit@debbugs.gnu.org; Thu, 01 Feb 2024 19:35:21 -0500 Original-Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]:46184) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rVhWW-0003ua-1C for 68824@debbugs.gnu.org; Thu, 01 Feb 2024 19:35:20 -0500 Original-Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1d944e8f367so13714185ad.0 for <68824@debbugs.gnu.org>; Thu, 01 Feb 2024 16:35:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706834100; x=1707438900; 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=vQoH2kw262Sdg0C6cEucuPfYCUjG/+nLhmUypXjBQ2s=; b=LJonFVBegL1XwxUUGYlCmKK50/2Z0mE/45YFToiaEoQMHBtwsR+ob04NulWp0NZI5Q 7CGmNaZzXQhmCU46ZTHBWFpyzdeYt27NBlNuBz9P5NSoP02jPRGR1J9OMzf6WSVlKG/b q7eJMHui/gJiR32nuOc19Sn26e2PquKlvSA0RJ7+wYqL2Bu1sHsDsl8Znxy2UhTWsK2H ZvfKn6UQ5rSu9Tn3CdF+sfouPs2KU64AeTOBKR2NutMjKT6HoGmzyTITnHzZw3W0aFh5 /kkR6vOTcMnGXMAZm/P6swXzBv4UEYTqK76vrATurD0LE/UB80xWHI9sbboDMdnZ9xT7 75Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706834100; x=1707438900; 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=vQoH2kw262Sdg0C6cEucuPfYCUjG/+nLhmUypXjBQ2s=; b=GLxnnehLpMUNY0Fp4kee/3hUFscQUhuBczU5zt52StA69VuW97CPJp5dOE/MH9AUwU C2ZOpCGLU0lPwvdod9Ihe/jQMZ6N59GNozjeot0ouMevMC7bo4UnpLiOEqhAIxVy9KY4 cax70FHiAGRxqy4D8JcWdGws2Jr6GsDfAUAF4gIybQM0gDcNhwOql7eja0kw8p8QZ3RV BHIm3raTjYW2xwPX8PRmTpDnnW/UBUwn9lo6ygO2hfb3HhmF/9lTI+/tRZ6Bjj1G1CPr IaCq6iEOJYE02tmmPH1ncp4bZNkqnEuvej3jXAG6LLG0Ju1wyA1Z7kasIE15Jgtqz4vb hJ0w== X-Gm-Message-State: AOJu0YydvNF2BrwBBND0BWG9wnW81X+qgqi91fr1U8Rxu8zTS+GW3b2Q e94tV9pO5hVrsZlW5CEOFH5zC6C8s4VW0UTLzQXafX4HC+IQCpmo X-Google-Smtp-Source: AGHT+IGFQc7H3+Oiy38g5zUdkvuCdETG3uTfgi2H23I+8iCXtcjh00mJ+fWf6JDYLM9PRipP8VLIdw== X-Received: by 2002:a05:6a20:d90e:b0:19e:4813:7b06 with SMTP id jd14-20020a056a20d90e00b0019e48137b06mr2883065pzb.30.1706834099550; Thu, 01 Feb 2024 16:34:59 -0800 (PST) Original-Received: from smtpclient.apple (172-117-161-177.res.spectrum.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id lw10-20020a056a00750a00b006de11c980e5sm345982pfb.80.2024.02.01.16.34.58 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Feb 2024 16:34:59 -0800 (PST) In-Reply-To: <868r44ryzb.fsf@mail.linkov.net> X-Mailer: Apple Mail (2.3731.700.6) 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:279311 Archived-At: > On Feb 1, 2024, at 9:12 AM, Juri Linkov wrote: >=20 > Yuan, do you think it makes sense to add a new optional arg to > 'treesit-search-forward' that will define the traversal order? >=20 > 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: >=20 > * Parent > ** Child 1 > ** Child 2 >=20 > Currently 'treesit-search-forward' returns "Child 1" before "Parent". >=20 > This means that 'treesit-search-forward' should return the > topmost matched parent instead of starting to traverse children > from the deepest leaf. >=20 > IOW, it's necessary to traverse nodes in this order: >=20 > o > | > =D0=BE---------------------11 > | | > o--------S----------3 12 > | | | > o--o-+--o 1--+--2 4--+-----7 > | | | | > o o +-+-+ +--+--+ > | | | | | > 5 6 8 9 10 >=20 > 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. >=20 >> +(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)) Instead of using treesit-search-forward, can you use = treesit-beginning-of-thing or treesit--navigate-thing to do what you = want? They handle the =E2=80=9Cchild before parent=E2=80=9D problem for = you, and handles some other edge cases. Yuan=