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#68899: Treesitter's forward-sexp-function Date: Sun, 4 Feb 2024 16:50:28 -0800 Message-ID: <3CEDAD3C-C789-49B1-B007-9764EF1A0364@gmail.com> References: <981BC2F8-9B7F-40AC-9C1A-C995A71F5C97@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) 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="38109"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 68899@debbugs.gnu.org To: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Feb 05 01:52: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 1rWnDZ-0009ll-Iu for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 05 Feb 2024 01:52:13 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rWnDD-0004vt-Vd; Sun, 04 Feb 2024 19:51:52 -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 1rWnDC-0004vb-Ia for bug-gnu-emacs@gnu.org; Sun, 04 Feb 2024 19:51:50 -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 1rWnDC-0001N5-A7 for bug-gnu-emacs@gnu.org; Sun, 04 Feb 2024 19:51:50 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rWnDO-00040t-GH for bug-gnu-emacs@gnu.org; Sun, 04 Feb 2024 19:52: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: Mon, 05 Feb 2024 00:52:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68899 X-GNU-PR-Package: emacs Original-Received: via spool by 68899-submit@debbugs.gnu.org id=B68899.170709426415362 (code B ref 68899); Mon, 05 Feb 2024 00:52:02 +0000 Original-Received: (at 68899) by debbugs.gnu.org; 5 Feb 2024 00:51:04 +0000 Original-Received: from localhost ([127.0.0.1]:50285 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rWnCR-0003zi-Lx for submit@debbugs.gnu.org; Sun, 04 Feb 2024 19:51:04 -0500 Original-Received: from mail-oa1-x29.google.com ([2001:4860:4864:20::29]:47147) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rWnCN-0003z8-D3 for 68899@debbugs.gnu.org; Sun, 04 Feb 2024 19:51:02 -0500 Original-Received: by mail-oa1-x29.google.com with SMTP id 586e51a60fabf-2196dd318feso706510fac.2 for <68899@debbugs.gnu.org>; Sun, 04 Feb 2024 16:50:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707094241; x=1707699041; 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=ooCD9nDpR5i7LQ/M/mYslH1LcLVpqH2knidtwVqvhws=; b=XkbmLFrOZ2oOqIMX6kqmks9CxHdP4hPiQukXABKdX13xPLN+Qyyn753m+Nn1FJ/xzF HAi0sbWPTDblnobIjwlEA+eoXLJO+Dpu63jZUSxYnivbGjgCUJ7epWGRJzW9hM+pvccd xM8GewGOuWbWBJuzoPblRDnf937IaVO/9CkEZ9Zx2/vl8gLA+KoO+8OD6r91F3kYuuQf D8GZCg6qqzpiCw7n6FJiHgtSzfcGNDCkb281mUCcWTBq2JqgBozyY3ph2YzRNUz6e6w8 nyEv72zvcnRzSQPM8+KmXDs18xOBBew8IXTkC/bGtRusJ+AxN6NHoKYqMvc4uDYuFHov USuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707094241; x=1707699041; 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=ooCD9nDpR5i7LQ/M/mYslH1LcLVpqH2knidtwVqvhws=; b=RnUhGwwblQdtZbgA9N3DsocYZSgmOkd8xoF8FP2doKUawDMRAReXlNuBWFwORKHVef /lr7tfW6ZO/EftSk+vN6fLVo+jsVU3vhZqo/+8w2zFatw60KVMGrmq5lSd/gWYhcyL/4 /RBWgwYVaMUdbhqIegY/Wt0r9U+OmrEcNs2YCvGVfrJTux02xWqi05EhNEuY9IL0uY9n epcSZYgCrK78Qh8LZ69bQ/wST+SAYtcx8jXvMmrZWyWxiUALSsV0TmoMkoqi1SBuuE4E Wk3nB0V49+H7aQ/fZwTjy8purG5cw3dHIxueX11criqxL+MmmpYr7yKBrCiL5OTVxlCc vSWw== X-Gm-Message-State: AOJu0YybwHNA+WVcckdogYWbtZ0UW7eMNtwTTjPuN+GiVj/xJlUBEgPp 92IFsJdFmPRDF6tHIS4WAh1bOM/p3s0jJkJgKlG16UroU5GC38N5 X-Google-Smtp-Source: AGHT+IEimmTTzNLiQ5MnvSk+GveypcrNXsTdlmyT0q2mgWiRgSBdbR/+8Jhk0LfyrrDGMLMdO7v1vw== X-Received: by 2002:a05:6870:8a14:b0:219:8d3b:f83c with SMTP id p20-20020a0568708a1400b002198d3bf83cmr812247oaq.50.1707094241068; Sun, 04 Feb 2024 16:50:41 -0800 (PST) Original-Received: from smtpclient.apple (172-117-161-177.res.spectrum.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id r22-20020a635156000000b005d651d4236dsm5699457pgl.86.2024.02.04.16.50.40 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Feb 2024 16:50:40 -0800 (PST) In-Reply-To: X-Mailer: Apple Mail (2.3731.700.6) 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:279427 Archived-At: > On Feb 4, 2024, at 4:40 AM, Jo=C3=A3o T=C3=A1vora = wrote: >=20 > On Sun, Feb 4, 2024 at 5:35=E2=80=AFAM Yuan Fu = wrote: >=20 >> Thanks for looking into this, Joao. IME a very useful characteristic = of forward-sexp is that it stays in the same =E2=80=9Clevel=E2=80=9D and = doesn=E2=80=99t go up automatically when there=E2=80=99s no siblings = (when there=E2=80=99s a closing delimiter). Eg, in an Elisp buffer, = forward-sexp stops at the closing parenthesis, in C, it should stop at = the closing bracket. >=20 > I agree. There are other useful characteristics, but this is one of = them. > It allows be to mark regions of text up to points that I'm not even = seeing. >=20 >> Also you don=E2=80=99t want to check for prev when moving forward, = and vice >> versa, ie, we don=E2=80=99t want to check (null next) and (null prev) = together. >=20 > I get it. I used those existing results as a proxy to know if we're > in the middle > of a leaf. I _think_ it's sound (maybe I'm wrong). >=20 >> So, how do you like this patch: >=20 > It works fine, but as far as I can tell does exactly the same as mine, = and > looks to be slightly more difficult to read and uses a further treesit > query to check if this is a leaf node. But it's absolutley fine = really. >=20 > One way my patch can be described in plain english is > "if we're not at an inter-thing boundary, we navigate to such = boundary" > And then the meaning of checking prev _and_ next becomes obvious > and it isn't necessary to perform the additional check that we're in a > leaf node. >=20 > So go ahead and push whichever patch you prefer, and thanks. >=20 > Jo=C3=A3o Initially I was worried about the case below: void main (void) { } But I get you now; if we define =E2=80=9Cleaf thing=E2=80=9D as not = having any nested child thing, and we allow ourselves to move to the end = of leaf thing, then in this case we indeed should move out of the = closing bracket. I like your definition of =E2=80=9Cleaf thing=E2=80=9D = better since it=E2=80=99s more general than =E2=80=9Cleaf node=E2=80=9D, = and I like the simpler code too. So applied your patch with some comments added, thanks! Yuan=