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#73404: 30.0.50; [forward/kill/etc]-sexp commands do not behave as expected in tree-sitter modes Date: Wed, 18 Dec 2024 20:04:11 -0800 Message-ID: References: <87plox4mtp.fsf@masteringemacs.org> <87bk0a1u0o.fsf@masteringemacs.org> <86tte2a5o3.fsf@gnu.org> <877cay1lqt.fsf@masteringemacs.org> <86frpma06f.fsf@gnu.org> <86ikueiekp.fsf@mail.linkov.net> <86ed4zg1cc.fsf@mail.linkov.net> <87zflac68t.fsf@mail.linkov.net> <87jzcdlxdp.fsf@mail.linkov.net> <87o71jocgs.fsf@mail.linkov.net> <5192B278-66C0-48AE-B881-E57CCBB6B501@gmail.com> <87frmtbc9z.fsf@mail.linkov.net> <86bjxh1h86.fsf@gnu.org> <87y10l8h6k.fsf@mail.linkov.net> <87ldwl8g60.fsf@mail.linkov.net> <87wmg53rdj.fsf@mail.linkov.net> <87a5d0n651.fsf@mail.linkov.net> <87zfktphks.fsf@mail.linkov.net> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51\)) 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="22832"; mail-complaints-to="usenet@ciao.gmane.io" Cc: theo@thornhill.no, Mickey Petersen , monnier@iro.umontreal.ca, 73404@debbugs.gnu.org To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 19 05:06:34 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 1tO7o1-0005kv-Hl for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 19 Dec 2024 05:06:33 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tO7na-0005GO-L2; Wed, 18 Dec 2024 23:06:06 -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 1tO7nY-0005GB-8a for bug-gnu-emacs@gnu.org; Wed, 18 Dec 2024 23:06:04 -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 1tO7nY-0000No-0L for bug-gnu-emacs@gnu.org; Wed, 18 Dec 2024 23:06:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=References:Date:In-Reply-To:From:Mime-Version:To:Subject; bh=z2TIDlaz7NNbHJehin0C2XwrYBL/bg3tGB5mCt7W1gA=; b=W33IQBEVpZ22bJxxz3kvr36D10KOET36S6A43VZz4JtWdAtn3lgFbIYRuCyr/gz5k2YGX9EDB1lJ66LiutOHM3dV1RTH0m4A9bHg+zV34pf/oWGKSqVDvpupAwETcsAdGDjQzj8BJeMm5IG5w8brsIGSSMKnjmuHmLKzgCeXub0RjQkt+tiysUR5+joxxzR8S/3VD/k4psa648fXboShLb1HQBS/SbdcjONM0dY3XP8uhjBs1NVqhE5zJxrZxNsbTPNn/YHGj0yIyxAEcohMsXKPEweLEFjTxe/m6PdpIHNVi9Tz1ysduULPZvIHZP9rJEhmAhnjk4nAsJK5tkNiwA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tO7nW-0005DR-0d for bug-gnu-emacs@gnu.org; Wed, 18 Dec 2024 23:06: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: Thu, 19 Dec 2024 04:06:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 73404 X-GNU-PR-Package: emacs Original-Received: via spool by 73404-submit@debbugs.gnu.org id=B73404.173458113319993 (code B ref 73404); Thu, 19 Dec 2024 04:06:01 +0000 Original-Received: (at 73404) by debbugs.gnu.org; 19 Dec 2024 04:05:33 +0000 Original-Received: from localhost ([127.0.0.1]:36902 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tO7n2-0005CO-W3 for submit@debbugs.gnu.org; Wed, 18 Dec 2024 23:05:33 -0500 Original-Received: from mail-pf1-f172.google.com ([209.85.210.172]:43067) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tO7n0-0005C8-4Y for 73404@debbugs.gnu.org; Wed, 18 Dec 2024 23:05:31 -0500 Original-Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-725dc290c00so1215682b3a.0 for <73404@debbugs.gnu.org>; Wed, 18 Dec 2024 20:05:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734581064; x=1735185864; 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=z2TIDlaz7NNbHJehin0C2XwrYBL/bg3tGB5mCt7W1gA=; b=GGE2L/GAq4MK6V2xWAAfs0SygybqPQ5ZKyX7fGvcUKlKn+SA9cVrLQGMIkPYtAEWkF PK8/3HbDKRKiTkmwK8c+e2hqN06ifbx33rKMiHpUd4wPdqJ0CSfWIc6VdPLwluMa7zf6 PLbkyqINFppOVI4NFOyLwYSqO3UzccNWHDJLUJ/2zd/8OkFTNuTcJmGX3ti31CHkuCPW dwGGmr9YZf++oQLg+ATpUkulnuwKjlu2NLeimppzFHw57SitVFziD5Pwg0rY3Rir05pq DiTdIBSvMHhUUG++D8+SrHU9yq0HZCEwYZ0R5n6pL+f1OEjJALEOMdemCKWCBToT0rO3 r80A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734581064; x=1735185864; 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=z2TIDlaz7NNbHJehin0C2XwrYBL/bg3tGB5mCt7W1gA=; b=dcCyB4tYvLTk4xdVoSYhzJZt90UReVJu9XLxSMNc3fwta5cEaKjV90lCkA9eQ3uy3H Su5SMHfWfpyzZYu9esjNFjFpHDcKcWVk1cY0To521+xtK8gHK+4xc63jmh+8YcSIPu3O Nduvat5W+8Du/84i8wwn7CBgo3XDvwYHumwrfHckvUE6bHCPGa8kE1bUaSaUiZ9NFkDx iXNNbX33qGSbEAOKnO5OVmjqfWt7bETTVE4MtLQqOPfg2j0+eERywVsdesd14MODA0yM Vj6eAS9/u+7zWJFAABGJ3/XF1LQxJI5ob8M9yIjLEMQZcY2ik+85+5dC//1IK5X5Az70 UC1g== X-Forwarded-Encrypted: i=1; AJvYcCWBf6rdhJgUxzXy48bKduhjUjFdidXegIEnsi1B7oI9OkpPAieeEONJdehnI5PWzht2AIzlbQ==@debbugs.gnu.org X-Gm-Message-State: AOJu0Yw4OiSIJW2sErI0D9W+VXsO+9a3AOdMPor+4/5TyDMJRqsr9JYO 5CBc8wDN6rlj7xyJBp3UIYVG9Kzh+H4YVK4nSuzexOjn2zYFY9Xp X-Gm-Gg: ASbGncv8dHATnkB5Tx54YpxwYHrTeg7+Ja8llaeE7DgfpMa16Y+pYgPp/1SxeynU6cz mZSNQyMkgH5zR7sdLiqixIATIFQ03rUDss8e4UaedH0WyFGTZ2yzTlCszViuy+AL+ApLQklbnR4 bP970+QVW26wHWnYZU6hWsnZRAWaZELHTgKIcZgpywaqmtG4yxkvLgpZbVgEMRB/JQJVQ8PER3Q XzuJ/eJJmIobP0eeZd6CugW99NJ5/Kid5bNuFJQFKUJfAKNd7La8K9jGYhvmztGSa1INbutt9MP QQvS X-Google-Smtp-Source: AGHT+IEPAunrXxUN4hH1ZhwnPsTi7w7y1GBZcCUsdd7fJbI2+bVbifz03zct6ymu5213Zu2p5wCmXg== X-Received: by 2002:a17:902:f687:b0:215:a808:61cf with SMTP id d9443c01a7336-219da7f007bmr24064355ad.25.1734581064109; Wed, 18 Dec 2024 20:04:24 -0800 (PST) Original-Received: from smtpclient.apple ([2601:646:8f81:6120:d586:f3b3:85da:8dc9]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc96294bsm3145675ad.36.2024.12.18.20.04.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Dec 2024 20:04:23 -0800 (PST) In-Reply-To: <87zfktphks.fsf@mail.linkov.net> X-Mailer: Apple Mail (2.3776.700.51) 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:297357 Archived-At: > On Dec 17, 2024, at 11:37=E2=80=AFPM, Juri Linkov = wrote: >=20 > While testing treesit-forward-sexp-list, I discovered that > thing-navigation functions are not restricted to named nodes. >=20 > I wonder if there a reason to find anonymous nodes as things? We should rather ask is there any reason to not find anonymous nodes as = things? Even ruby-ts-mode defines a bunch of anonymous nodes as sexp, = no? In any case, excluding anonymous nodes from things doesn=E2=80=99t = sound right. >=20 > The problem was found with the node "unless" in Ruby: >=20 > unless cond > a +=3D 1 > else > b -=3D 1 > end >=20 > Here the named node 'unless' has exactly the same name > as the anonymous node with the text "unless": >=20 > (unless "unless" condition: (identifier) I feel like Ruby=E2=80=99s grammar should call the named node something = else, like unless_statement. >=20 > Finding anonymous nodes breaks forward-sexp when point is on "unless": >=20 > un-!-less cond > a +=3D 1 > else > b -=3D 1 > end >=20 > because (treesit-thing-at (point) 'sexp t) finds >=20 > # >=20 > instead of >=20 > # >=20 > Also this breaks backward-sexp and backward-up-list > because treesit--thing-sibling finds > the anonymous node "unless" as a previous sibling > instead of the named node 'unless' as a parent. >=20 > Would the right solution be to check if the found thing > is a named node? With something like: >=20 > diff --git a/lisp/treesit.el b/lisp/treesit.el > index 18200acf53f..9ad879ee40c 100644 > --- a/lisp/treesit.el > +++ b/lisp/treesit.el > @@ -2711,6 +2774,7 @@ treesit--thing-sibling > (lambda (n) (>=3D (treesit-node-start n) pos)))) > (iter-pred (lambda (node) > (and (treesit-node-match-p node thing t) > + (treesit-node-check node 'named) > (funcall pos-pred node)))) > (sibling nil)) > (when cursor > @@ -2760,6 +2824,7 @@ treesit-thing-at > (let* ((cursor (treesit-node-at pos)) > (iter-pred (lambda (node) > (and (treesit-node-match-p node thing t) > + (treesit-node-check node 'named) > (if strict > (< (treesit-node-start node) pos) > (<=3D (treesit-node-start node) pos)) A better solution IMO is to add some way to distinguish between named = and anonymous nodes. I can think of two ways, either add =E2=80=9Cand=E2=80= =9D and =E2=80=9Cnamed/anonymous=E2=80=9D predicate, so (and named = =E2=80=9Cunless=E2=80=9D) only matches the named =E2=80=9Cunless=E2=80=9D = node; or we add a special syntax such that =E2=80=9C(unless)=E2=80=9D = only matches named nodes, and =E2=80=9C\=E2=80=9Dunless\=E2=80=9D=E2=80=9D= only matches anonymous nodes. Yuan=