From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#74963: Ambiguous treesit named and anonymous nodes in ruby-ts-mode Date: Wed, 25 Dec 2024 05:25:24 +0200 Message-ID: <8abcb53c-1636-450d-ac0c-fdf44566ab95@gutov.dev> References: <87plox4mtp.fsf@masteringemacs.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> <87ttb0rwni.fsf_-_@mail.linkov.net> <4DFCFBC8-A353-48F2-8257-D6CFB155A030@gmail.com> <87ttatpnii.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5451"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: 74963@debbugs.gnu.org To: Juri Linkov , Yuan Fu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 25 04:26:14 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 1tQI2H-0001FA-FM for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 25 Dec 2024 04:26:14 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tQI2A-0002bP-KH; Tue, 24 Dec 2024 22:26: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 1tQI27-0002bF-EI for bug-gnu-emacs@gnu.org; Tue, 24 Dec 2024 22:26:03 -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 1tQI27-0000MV-5U for bug-gnu-emacs@gnu.org; Tue, 24 Dec 2024 22:26:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=In-Reply-To:From:References:MIME-Version:Date:To:Subject; bh=RDMedM13SKUcehccntHhdm3JzKzNwyaWLSZZeWPYGTk=; b=rKcDd7mHyTbBECql16PfbqGRS5VQyH9ytqhIY7FaNsPsN4K4n4BCb+Kgil+++0D5brPfvEaJpxnukDgT+80HWgPZmN43NPj5p50pW2TcLtTxxj2539SnCjb0aQ3lqMCltYvDLvY/268Bw15y5RWfDevmkL+E9/Lopzj5+VmDSnNA89mSdFfcdKs9Omfl78DEi+uB/HFBe3dwqdxpatuYjfjLkdC7AFH120Oy/o5TCWAcvV3IfGSh5+3NimLOHXDc5939+dhZ8xjeyArGXpS8XgXahdCGi0btFtI8Ff4918tsJcL53/c1OWYecfVobHq60C5/pOnece3DVXsyQmnkdA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tQI26-0000EX-0E for bug-gnu-emacs@gnu.org; Tue, 24 Dec 2024 22:26:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 25 Dec 2024 03:26:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74963 X-GNU-PR-Package: emacs Original-Received: via spool by 74963-submit@debbugs.gnu.org id=B74963.1735097139859 (code B ref 74963); Wed, 25 Dec 2024 03:26:01 +0000 Original-Received: (at 74963) by debbugs.gnu.org; 25 Dec 2024 03:25:39 +0000 Original-Received: from localhost ([127.0.0.1]:35671 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tQI1j-0000Dm-7Q for submit@debbugs.gnu.org; Tue, 24 Dec 2024 22:25:39 -0500 Original-Received: from fhigh-a3-smtp.messagingengine.com ([103.168.172.154]:36433) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tQI1e-0000DU-O0 for 74963@debbugs.gnu.org; Tue, 24 Dec 2024 22:25:38 -0500 Original-Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfhigh.phl.internal (Postfix) with ESMTP id C5596114016F; Tue, 24 Dec 2024 22:25:28 -0500 (EST) Original-Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Tue, 24 Dec 2024 22:25:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1735097128; x=1735183528; bh=RDMedM13SKUcehccntHhdm3JzKzNwyaWLSZZeWPYGTk=; b= K0w/9sTZnoItgN2O4sNnX4ReC8iX8xQ4PnxQgsuY7aOUW7utri81zlmDSJiRCHPo EusuzlPI+V1TLaFycpTrL4dg2DtdxVNL6XAd6YgiR2bJ1SM57qPFOPFdeQX8jH1q +JiZwl3WZ7hzIrJncrzk9sxG8op2LRXdFp4RLyfzOPI4EXFXYrrZYce3x6W1lcAA NWwGR8NbB+NuLnIlEqDrHV5aYTuTjkjUGryO3B+wBcNaNCmPtXwokQHbXYXLbhew tzJWSr8o0YFikIipf8xVk9XKxuv29RznUCYC+UsR7z4kboqvm5QnVfBmlvl9BVC5 R8e1UULlXvaDjh3jR4a/eg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1735097128; x= 1735183528; bh=RDMedM13SKUcehccntHhdm3JzKzNwyaWLSZZeWPYGTk=; b=m C3Xui5WYgmkQ02Bn4e6V3zO130CjFfbwDZbCCNahtrGDS8ZAiiI3Hu1sGyQRiKxZ Ar23OEFjZcKhzSiIg3Mw5MfMOzHhs+IApeC70HVv1wcwSOCiWNNUdlhAJQv2qd6f RJ6fHwBBBG1PBcm1NZ10X0bDefmUaUiEIGCFHB7rlU8vNo3MIrHDVLTd5yNhcIfW TghH3RQm1CjkAISl2a1/HdOZktPktSN/sPIzEGwvgadHXSCSzJbNkNsuMriNJng8 3Nu3HGeXV+yLflCjomseqQrPth7zVjH2pNlvlzN7NHLwkrF7tT4gTrY4LsCCwlKo 5G+PgjQU0zY1VVWHnfPnw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudduhedgheejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtvdej necuhfhrohhmpeffmhhithhrhicuifhuthhovhcuoegumhhithhrhiesghhuthhovhdrug gvvheqnecuggftrfgrthhtvghrnhepteduleejgeehtefgheegjeekueehvdevieekueef tddvtdevfefhvdevgedujeehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepughmihhtrhihsehguhhtohhvrdguvghvpdhnsggprhgtphhtthho peefpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehjuhhriheslhhinhhkohhvrd hnvghtpdhrtghpthhtoheptggrshhouhhrihesghhmrghilhdrtghomhdprhgtphhtthho peejgeelieefseguvggssghughhsrdhgnhhurdhorhhg X-ME-Proxy: Feedback-ID: i07de48aa:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 24 Dec 2024 22:25:27 -0500 (EST) Content-Language: en-US In-Reply-To: <87ttatpnii.fsf@mail.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:297710 Archived-At: Hi Juri, On 24/12/2024 09:17, Juri Linkov wrote: > While addition of '(and named "unless")' would be appreciated, > I see that currently it's possible to do this by proving a predicate > like there is 'ruby-ts--sexp-p' in > > (setq-local treesit-thing-settings > `((ruby > (sexp ,(cons (rx > bol > (or > "class" > ... > ) > eol) > #'ruby-ts--sexp-p)) > > Then 'ruby-ts--sexp-p' could check for the named node "unless" as well. > > But it seems such solution is less efficient than adding '(and named "unless")'. Given that we're already calling a predicate every time (in ruby-ts-mode), we might as well add one more check. See the patch at the end. Speaking of tricky examples though, here's a definition: module Bar class Foo def baz end end end If you move point inside the keyword "module" or "class", C-M-f wouldn't move forward either as of the latest master. No such problem with "def". Adding the check for "named" fixes the first two cases, but then C-M-f inside "def" jumps to after "baaz". Could be worked around with a special case, but I wonder what this difference comes from (haven't properly debugged yet). diff --git a/lisp/progmodes/ruby-ts-mode.el b/lisp/progmodes/ruby-ts-mode.el index 4ef0cb18eae..4b15c6cbf27 100644 --- a/lisp/progmodes/ruby-ts-mode.el +++ b/lisp/progmodes/ruby-ts-mode.el @@ -1120,6 +1120,10 @@ ruby-ts--sexp-p (equal (treesit-node-type (treesit-node-child node 0)) "("))) +(defun ruby-ts--sexp-list-p (node) + (when (treesit-node-check node 'named) + (ruby-ts--sexp-p node))) + (defvar-keymap ruby-ts-mode-map :doc "Keymap used in Ruby mode" :parent prog-mode-map @@ -1235,7 +1239,7 @@ ruby-ts-mode "array" "hash") eol) - #'ruby-ts--sexp-p)) + #'ruby-ts--sexp-list-p)) (text ,(lambda (node) (or (member (treesit-node-type node) '("comment" "string_content" "heredoc_content"))