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#73404: 30.0.50; [forward/kill/etc]-sexp commands do not behave as expected in tree-sitter modes Date: Wed, 18 Dec 2024 09:37:39 +0200 Organization: LINKOV.NET Message-ID: <87zfktphks.fsf@mail.linkov.net> 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> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25117"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) Cc: theo@thornhill.no, mickey@masteringemacs.org, monnier@iro.umontreal.ca, 73404@debbugs.gnu.org To: Yuan Fu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 18 08:44:29 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 1tNojM-0006P3-Vf for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 18 Dec 2024 08:44:29 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tNoj0-00013j-LP; Wed, 18 Dec 2024 02:44: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 1tNoiy-0000w7-3W for bug-gnu-emacs@gnu.org; Wed, 18 Dec 2024 02:44: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 1tNoix-0006sl-RO for bug-gnu-emacs@gnu.org; Wed, 18 Dec 2024 02:44:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=XW2YeZxG2fIt1FyOJa3WfB4fvJTGb1VwcoijMoc0Law=; b=P1IwdjGc0I3GwUqTrIauywLAi1GQiSkEd4Wp2DyAliLbJiQ++6XjPNUHUdT2QDlAOM4Ja80U7RXhehRGLywnPXq2ohk8JpDisEgcZBhd1ut8mD/12f3wyOHCRQ66LBdpteBi9QOTu4ts61kdeY5P7K2Q2O37DQYmsHL0Lmbk1NY1eaVh1O0wSdVB/ardLBZRDLvUml6vA8ZJb1++8e5/unRgDULMmLXN9wUOG0lFfJ+5ZRXtslXD5eYvuOxw/fNW0aK9VhRmCWROTeJu4dGfj0UpnAkjyYKsYxzTIysk+PY8No28RbCl5SAp7rwxjSd5tdgKRTg6mJxhKauBP3xTIw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tNoiw-00035K-C4 for bug-gnu-emacs@gnu.org; Wed, 18 Dec 2024 02:44:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 18 Dec 2024 07:44:02 +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.173450781411800 (code B ref 73404); Wed, 18 Dec 2024 07:44:02 +0000 Original-Received: (at 73404) by debbugs.gnu.org; 18 Dec 2024 07:43:34 +0000 Original-Received: from localhost ([127.0.0.1]:33227 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tNoiU-00034E-7x for submit@debbugs.gnu.org; Wed, 18 Dec 2024 02:43:34 -0500 Original-Received: from relay5-d.mail.gandi.net ([217.70.183.197]:42477) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tNoiR-00033t-JB for 73404@debbugs.gnu.org; Wed, 18 Dec 2024 02:43:32 -0500 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id 583BC1C0003; Wed, 18 Dec 2024 07:43:00 +0000 (UTC) In-Reply-To: <87a5d0n651.fsf@mail.linkov.net> (Juri Linkov's message of "Thu, 12 Dec 2024 19:49:30 +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:297328 Archived-At: While testing treesit-forward-sexp-list, I discovered that thing-navigation functions are not restricted to named nodes. I wonder if there a reason to find anonymous nodes as things? The problem was found with the node "unless" in Ruby: unless cond a += 1 else b -= 1 end Here the named node 'unless' has exactly the same name as the anonymous node with the text "unless": (unless "unless" condition: (identifier) Finding anonymous nodes breaks forward-sexp when point is on "unless": un-!-less cond a += 1 else b -= 1 end because (treesit-thing-at (point) 'sexp t) finds # instead of # 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. Would the right solution be to check if the found thing is a named node? With something like: 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) (>= (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) (<= (treesit-node-start node) pos))