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: Tue, 1 Oct 2024 23:14:15 -0700 Message-ID: <08933A47-CCCD-4317-9EEA-DCB0C1D9E544@gmail.com> References: <87plox4mtp.fsf@masteringemacs.org> <87frpm20t7.fsf@masteringemacs.org> <8634lmbs8t.fsf@gnu.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> 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="7631"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , Mickey Petersen , 73404@debbugs.gnu.org To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Oct 02 08:16:21 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 1svseq-0001mh-Nt for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 02 Oct 2024 08:16:20 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1svsed-0005Pk-O0; Wed, 02 Oct 2024 02:16:07 -0400 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 1svseY-0005O3-Op for bug-gnu-emacs@gnu.org; Wed, 02 Oct 2024 02:16:04 -0400 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 1svseY-00085J-8T for bug-gnu-emacs@gnu.org; Wed, 02 Oct 2024 02:16:02 -0400 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=HQI5CKJhw8HN4YBu4hfpxTlfh7VeWb6JscWOg0y7VTk=; b=kF2HSxtwZ7nF4bK1ru5vkSBasnmc7XrbK7hu5uD+34db6V/N5kkUYSugCHgJ2Tgphel+j6mMeLEGkfZBSEu7wpuc/sUe/gqbCWuo/ihnUxZmsuv9y73XLLHKV4ZO/k7IQrX1/SgP2ZzygdgTmEVzHXQAHp6xSHForHsULry5OP5VGVwipyJHIl88gWLQEh5ybDz/q7YMFtj1zObj+Pv4sD4wuRGZ05mL0UnC74O50UWEtHOngKGFg44cL371excS0U6NpfgK47KlWXgqkHKYQUoxtnzKK0N8MdHRs2PKaAxX+s/d5vnhuspxY0kcBJzP6+rgstAe2cCZ8G0RCx/Row==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1svseY-0002CH-6H for bug-gnu-emacs@gnu.org; Wed, 02 Oct 2024 02:16:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 02 Oct 2024 06:16: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.17278497358412 (code B ref 73404); Wed, 02 Oct 2024 06:16:02 +0000 Original-Received: (at 73404) by debbugs.gnu.org; 2 Oct 2024 06:15:35 +0000 Original-Received: from localhost ([127.0.0.1]:56321 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1svse6-0002Bc-LE for submit@debbugs.gnu.org; Wed, 02 Oct 2024 02:15:35 -0400 Original-Received: from mail-pl1-f172.google.com ([209.85.214.172]:61914) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1svse5-0002BQ-Da for 73404@debbugs.gnu.org; Wed, 02 Oct 2024 02:15:34 -0400 Original-Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-20bc2970df5so7692805ad.3 for <73404@debbugs.gnu.org>; Tue, 01 Oct 2024 23:15:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727849667; x=1728454467; 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=HQI5CKJhw8HN4YBu4hfpxTlfh7VeWb6JscWOg0y7VTk=; b=HaeZT9RX9J55DIYrRx70djifEowggqeeAT5zTfLlJLD81oqMbyQfxxDCaWrxGuQgYH Ahak3d89BBShO4Om7JpoNTV9An7xZpZL40aKunxczKSvhZQq3z49Re6xlIpNg4hkq85H fJs10UY2z6iWfCusAPJv8nppWcX8t9oF2NBu41SeqmmCzbYiLtQl0++S6hxcOuj1ianR fs4wMXYqNd3zBcA7rixoXGbFWwEKdtH3l+DzzLjdTjnxXKWNf6y06JnuapbFGqbBKWaE X2Zhidf/SBkFoq1vsKGUk5d2oSJUgxW+Zpq6HKr/AgUfy3omeFehod0m3OsLqVj81UTQ P9Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727849667; x=1728454467; 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=HQI5CKJhw8HN4YBu4hfpxTlfh7VeWb6JscWOg0y7VTk=; b=Uj+7y9LybjT1Arj68/whYwDnte9c7wRgTMr5z7zZSnaF4GMQV1eZC5SQTDdf4fcTw3 88rVWYx3QSLYgVJGVZAxjzT04OZ0Rw8guDRgYTm/JFQ/ZpK+8IXlhoBRLHfYiHdFzlGB gM/n0AJgQhub+t6odzxhWQzuVMAWZDBZ7mSXSfCWxBKSgpB9lM6Xnujmwy/Rjvbwo1Gy BqDtUy3XZ1dAYrStlRXG4FQje0oV1K2GITQR6ynZMzFA4U31tFW2QxhacNha0XyJmfn6 ZHUz2HxDZeFpBAO7RKWBOeMecVc/BVS1OPPwJ/uuUoAM1zhLukeP5OspzC9Nsp+BnPrH OxQQ== X-Forwarded-Encrypted: i=1; AJvYcCXSoQnicfOneQ+b6ozxUdolHQA9psftTvAnacYQClQ2aVq9XAvsTs/pP4sqgMUBQftx+5o7jg==@debbugs.gnu.org X-Gm-Message-State: AOJu0YxUoPVEoa885vo0h/BM9aB3IMsT750OAR3+lA8whjWcR7FJmwna XTyGKIow+Bsh1rtTzzlO74RtrMb35MSnPWYNosEfVEPnMfce2J1c X-Google-Smtp-Source: AGHT+IHmNSgFXj3FDx15Ll7rHPXqVxN3GCG+gqBhkH6Fvv2xsF5s2jsIaWfmUbUTGpLWoMwVTo6iMA== X-Received: by 2002:a17:90a:c287:b0:2e0:b02e:d1e0 with SMTP id 98e67ed59e1d1-2e18456f0dfmr2691815a91.16.1727849667166; Tue, 01 Oct 2024 23:14:27 -0700 (PDT) Original-Received: from smtpclient.apple ([2601:646:8f81:6120:6dd0:d187:4760:9860]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e18f747292sm745286a91.7.2024.10.01.23.14.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Oct 2024 23:14:26 -0700 (PDT) In-Reply-To: <86ed4zg1cc.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:292816 Archived-At: > On Oct 1, 2024, at 10:49=E2=80=AFAM, Juri Linkov = wrote: >=20 >> The user can modify treesit-thing-settings to alter the behavior of >> sexp navigation, they don=E2=80=99t necessarily need to use >> js--treesit-sexp-nodes. Maybe we should add a test for >> (treesit-thing-defined-p 'sexp nil) in treesit-forward-sexp? >=20 > I tried to do something like this, and everything works nicely with: >=20 > @@ -2289,11 +2289,10 @@ treesit-forward-sexp > (node-at-point > (treesit-node-at (point) (treesit-language-at (point))))) > (or (when (and node-at-point > - ;; Make sure point is strictly inside node. > - (< (treesit-node-start node-at-point) > - (point) > - (treesit-node-end node-at-point)) > - (treesit-node-match-p node-at-point 'text t)) > + (or (treesit-node-match-p node-at-point 'text t) > + (not (treesit-thing-at > + (if (> arg 0) (point) (1- (point))) > + (treesit-thing-definition 'sexp = nil))))) > (forward-sexp-default-function arg) > t) > (if (> arg 0) >=20 > The new logic is the following: if there is no sexp thing defined at = point, > then fall back to 'forward-sexp-default-function'. >=20 > Then after (setq js--treesit-sexp-nodes '("binary_expression")) > 'C-M-f' in e.g. >=20 > export const add =3D (a, b) =3D> -!-a + b; >=20 > moves point to >=20 > export const add =3D (a, b) =3D> a + b-!-; >=20 > The condition (if (> arg 0) (point) (1- (point))) above > is necessary to allow 'C-M-b' to move back to: >=20 > export const add =3D (a, b) =3D> -!-a + b; >=20 > Also the condition to make sure point is strictly inside node > was removed to handle the case when point was at the beginning > of the buffer: >=20 > -!- > export const add =3D (a, b) =3D> a + b; >=20 > to move after >=20 > export-!- const add =3D (a, b) =3D> a + b; >=20 > by 'forward-sexp-default-function'. Sounds good. Feel free to install on master if you think it works well = :-) >=20 >> Your second example sounds useful, but right now the premise of = tree-sitter >> sexp movement is to use the parse tree primarily, and only use the = default >> sexp movement for comments and strings. What you envisioned seems to = be the >> other way around: use default sexp movement by default, and only use >> tree-sitter movement under certain conditions. Is that few lines of = change >> able to make such big difference in the logic? >=20 > I think we need to support both ways: >=20 > 1. opt-out - where sexp-thing definition is used by default, > and only text-thing allows users to override it; >=20 > 2. opt-in - where 'forward-sexp-default-function' is used by default, > and user can explicitly define what sexp-things are preferable > for navigation by treesit. >=20 > Then in the latter case the users could prefer to use > treesit sexp navigation only for constructions with > "invisible parens". For example, in Ruby there are > two interchangeable syntaxes for code blocks: >=20 > 1. curly braces {...} that are already handled > by 'forward-sexp-default-function'; >=20 > 2. do...end that can't be handled by 'forward-sexp-default-function', > so treesit is coming to the rescue for the case of such > implicit braces. Sounds good to me, I wonder if there are clever way to implement this. = If there isn=E2=80=99t, we=E2=80=99d need to define two sets = treesit-sexp functions and add a custom option to control which one to = use. Seems a bit clunky to me. Yuan=