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: Mon, 30 Sep 2024 20:57:36 -0700 Message-ID: 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> 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="11461"; 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 Tue Oct 01 16:48:15 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 1sveAg-0002oH-RH for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 01 Oct 2024 16:48:15 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sveAB-00032I-7p; Tue, 01 Oct 2024 10:47:43 -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 1sve9X-0002fi-EQ for bug-gnu-emacs@gnu.org; Tue, 01 Oct 2024 10:47: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 1sve9X-0004OU-5H for bug-gnu-emacs@gnu.org; Tue, 01 Oct 2024 10:47:03 -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=lKu6RK5D5CPROq7ZBpITKnqSjn1wOF98HEslkScTRj4=; b=mHoULO1z+oxVgDkFmgRdW4fBXrkB1bVluNX+zzVfpKGxgBDxWpEbbK8NhNf6Kn4Y3hhXtoae0iYPoBuRuXf0PUs2MxQIELy1UZ+PRBC/1rAqznu9VioJNLA8rMD57H7tOsVe2T81nv5SiHCvN597dvvKFhQBrON6OKz6BL93AVJboAn4aYqsA+IDjNuPYTrkS5EvRSbqCpBCbKTdb4al0OoYxZ1OYZO6AuR8PqDJyg4603x+Mgdkw3W5ezlM8xbNl4LaCygJGoEB4TLYeMvcPbmDjuwb/rw/ueCw2AKLK1e7xo3Wu4vausB2jtOOnXpAougN8bjZTCcYT8ihuIe67g==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1svdvy-0002Vz-Mt for bug-gnu-emacs@gnu.org; Tue, 01 Oct 2024 10:33: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: Tue, 01 Oct 2024 14:33: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.17277931249639 (code B ref 73404); Tue, 01 Oct 2024 14:33:02 +0000 Original-Received: (at 73404) by debbugs.gnu.org; 1 Oct 2024 14:32:04 +0000 Original-Received: from localhost ([127.0.0.1]:51681 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1svdv1-0002VP-Up for submit@debbugs.gnu.org; Tue, 01 Oct 2024 10:32:04 -0400 Original-Received: from mail-ot1-f44.google.com ([209.85.210.44]:44460) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1svduz-0002Ux-Uy for 73404@debbugs.gnu.org; Tue, 01 Oct 2024 10:32:02 -0400 Original-Received: by mail-ot1-f44.google.com with SMTP id 46e09a7af769-710e489860bso2895499a34.1 for <73404@debbugs.gnu.org>; Tue, 01 Oct 2024 07:32:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727793057; x=1728397857; 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=lKu6RK5D5CPROq7ZBpITKnqSjn1wOF98HEslkScTRj4=; b=EIDsFCO56F2u4bIMhMO5dpdYZZ7yJEF8SWPxMq9QmSHTddv/cfSxUoKKahUij+PuXk KGhOCXb2X9dbnIP8V4pFwSVaec+4jpVt3c8mP7sEuVgY8qgMsFU6wonnhj5f4cefia0t nBIFhpKGrouq3QLajb5eIrjSzhGBxaFk/91bpOrZtf25Jf6rSdfWrOOr3A7MvAIKhrG+ jxdvot/Ggrzz9xR/0t9FoqWECFEz3s5sslF8S6RxUxXkMA7YVzzU7sXvUAuG85Tymo5h tu1qcTiJLrmEFi/zD55JN6A0F1LQoUo6wJNbHtBRT9tAx+0uWRsxUn+9Mz59CB4c8RTG 3N/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727793057; x=1728397857; 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=lKu6RK5D5CPROq7ZBpITKnqSjn1wOF98HEslkScTRj4=; b=RJ15e6chHsU+/MHH+qC22iuSTYu3MArAqNV7Wx6dGfeZyj1ad1JrqLjTDfi0O5FQHy fikKo0Wugb5IuPP9UPreNv8OX258xgj3bilBZOlnJnHeYbI9pPEX+5tGBob1RNg+dqkK CWSgSJG0dkO2c3JZdVyhNxj3GII58WtUYvL26Pa73T+wjmRp7Yjj4TDAuQ7AMU0eVKBP nXGBc/BzNlt52nct3Vo8+feJx44sXCz+3oiPd4XLGhzefE04DMkbCyJh8N1tO5MvQFfM TIcVDvnI/JzE/ismhSQ/ediP24bCUKpm/LENR92U/bOTt7/BgZFheAnRlY4s6GpMOkbC v5Gw== X-Forwarded-Encrypted: i=1; AJvYcCXo7Bg7xpeROLpzZgxIQ+cpFlN0tt4b2R1gthgK/6/FWp4zT7h305AIqbXKzcKWfaKIxP+VgA==@debbugs.gnu.org X-Gm-Message-State: AOJu0YxYFADUml1fDjpagcb0vkKJF/zVlpTqL1gdX65CtrTCZLvBEFRR 8wu7rdVwnekpyjkOa31oj0uBCTpDNA7eefeudRzM3ggrfPrmJh+oAZsroQ== X-Google-Smtp-Source: AGHT+IH07RBr6uDpe5Ts/fnIwqP9ZmG5aUo8DKFts72GgY6X/6Zax9kS+7uW5qFdOp3XXvRnCM1f0Q== X-Received: by 2002:a17:902:e551:b0:20b:65d6:d268 with SMTP id d9443c01a7336-20b65d6d4bcmr145334865ad.53.1727755068549; Mon, 30 Sep 2024 20:57:48 -0700 (PDT) Original-Received: from smtpclient.apple ([2601:646:8f81:6120:6dd0:d187:4760:9860]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20b37e0d7f2sm60861935ad.180.2024.09.30.20.57.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Sep 2024 20:57:47 -0700 (PDT) In-Reply-To: <86ikueiekp.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:292759 Archived-At: > On Sep 29, 2024, at 9:56=E2=80=AFAM, Juri Linkov = wrote: >=20 >> Note that you can affect the behavior of tree-sitter sexp movement by >> defining the sexp =E2=80=9Cthing=E2=80=9D in treesit-thing-settings. = Js-ts-mode defines one >> (js--treesit-sexp-nodes) and it only consider some nodes as sexp. You = might >> be able to tweak the sexp movement to your liking by changing it, or >> directly modifying the definition for `sexp=E2=80=99 in = treesit-thing-settings. >>=20 >>>> Do you think the examples I listed in the original bug report match >>>> your expectations? If so, then it is probably OK to close the bug = report. >>>=20 >>> Yes, I do, but let's wait for others to chime in if they have = opinions >>> on this. >=20 > Here are some ideas how to cover more use cases. >=20 > Suppose that a user wants to disable tree-sitter sexp movement > completely to use the default forward-sexp-default-function. > The natural way to do this would be set the list of nodes to nil: >=20 > (setq js--treesit-sexp-nodes nil) >=20 > However, this currently doesn't work, and requires a change like this: >=20 > @@ -2290,10 +2290,12 @@ treesit-forward-sexp > (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)) > + (<=3D (treesit-node-start node-at-point) > + (point) > + (treesit-node-end node-at-point)) > + (or (treesit-node-match-p node-at-point 'text t) > + (not (treesit-node-match-p node-at-point = 'sexp t)) > + )) > (forward-sexp-default-function arg) > t) > (if (> arg 0) >=20 > Now, the next case: what if the user wants to use the default > forward-sexp-default-function except for the 'binary_expression' > like "a + b" where `C-M-f' should move from "a" to the end of "b": >=20 > export const add =3D (a, b) =3D> -!-a + b; >=20 > should move to >=20 > export const add =3D (a, b) =3D> a + b; >=20 > ^1 >=20 > The best way for the user would be to customize: >=20 > (setq js--treesit-sexp-nodes '("binary_expression")) >=20 > But this is not yet handled by the condition above: >=20 > (not (treesit-node-match-p node-at-point 'sexp t)) >=20 > because 'node-at-point' is "identifier". > So we need to use 'treesit-parent-until' > to check if all parent nodes match > 'js--treesit-sexp-nodes'. Then it will find > the parent "binary_expression". >=20 > I believe something like this will make > treesit-forward-sexp more customizable. 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 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? Yuan=