From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill Newsgroups: gmane.emacs.devel Subject: Re: Plug treesit.el into other emacs constructs Date: Tue, 13 Dec 2022 19:27:58 +0100 Message-ID: <87r0x3gnv5.fsf@thornhill.no> References: <87wn6whete.fsf@thornhill.no> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9724"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org, eliz@gnu.org, casouri@gmail.com To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Dec 13 19:28:59 2022 Return-path: Envelope-to: ged-emacs-devel@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 1p5A1S-0002Lu-MQ for ged-emacs-devel@m.gmane-mx.org; Tue, 13 Dec 2022 19:28:59 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p5A0o-00023b-R4; Tue, 13 Dec 2022 13:28:20 -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 1p5A0f-00022o-Ey for emacs-devel@gnu.org; Tue, 13 Dec 2022 13:28:09 -0500 Original-Received: from out2.migadu.com ([2001:41d0:2:aacc::]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5A0c-0000yR-Sl; Tue, 13 Dec 2022 13:28:09 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1670956083; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=XKWI7wbQ5wKDLE3JR/QOoib0zK3eKkDYefo59TrUdgU=; b=UfnozKjExRxyw2Ys5wVjcSJhe187HMiJXav75OxoX0SPlqjJKKsZOypqufCk3HDy8nFytl cFgkZjs85h+3FsyDx/8QluCBiQiWuDAHiZHYJXSsC/X8sJRLC9idY408KbrAqsdfhbMsKh CZyzwI9xxAG0NAHIVcS1yFkJ4KXGQKif/uSs7Yds3mcLbhyaFsRe6nx1cxNsMRsO5PyK1r Q28ln+iue8woyO/TTFqEVOr6cXysHSO4d4ibkg3mU8sb1aVwuUXUXXDxbigvWubyBoeeBC luuHdUxUT2nO/WW1DTLfMPvpMYnpABFln1AIFUVZ6w69F9+mIipUSkbusMgPMw== In-Reply-To: X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=2001:41d0:2:aacc::; envelope-from=theo@thornhill.no; helo=out2.migadu.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:301342 Archived-At: Stefan Monnier writes: > Cool, thanks, a few comments (based on my experience with adding > similar things based on `smie`): > >> ** Forward-sexp: >> Executing C-M-f repeatedly will go from: >> ``` >> public void foo(|String bar, String baz) {} >> ``` >> to >> ``` >> public void foo(String bar|, String baz) {} >> ``` > > That looks wrong. `String` is a valid AST node. Whether it gets a node > in tree-sitter or not, I don't know, but here there are several "sexps" > that start at point and I think `forward-sexp` should be conservative > and keep advancing by the smallest option. I understand. My reasoning is that 'forward-word' is suitable for that, and to actually gain something from these we need to use a little bigger constructs. In tree-sitter 'String' isn't really valid, because you need the identifier to create a complete node. > > There can be many more than 2 choices, of course, e.g.: > > x = |f (x) * 3 + 2; > > Here "f" is the smallest sexp after point, "f (x)" is the next one up, > then "f (x) * 3" and finally "f (x) * 3 + 2". > In this case I'd think that forward-sexp would do: ``` x = |f (x) * 3 + 2; x = f (x)| * 3 + 2; x = f (x) * 3| + 2; x = f (x) * 3 + 2;| ``` Or something like that. So that multiple transpose-sexps would move 'f(x)' over the operators, swapping with the integers. >> ``` >> public void foo(String bar, String baz|) {} >> ``` > > That one's right :-) > Why is this one right, and the above not? >> ** transpose-sexp: >> Executing C-M-t repeatedly will go from: >> ``` >> public void foo(int bar,| String baz) {} >> ``` >> to >> ``` >> public void foo(String baz, int bar|) {} >> ``` > > And this one it right as well (regardless if | starts after or before the comma). > > Does it work as well for infix keywords that are made of normal letters, > like say `else` (or the `and` and `or` used in some languages instead > of `&&` and `||`)? I see no reason it shouldn't but I need to investigate that a bit further. I'm still trying to understand how all the forward-* functions work, to see whether I need to modify my functions. Thanks for the feedback so far. I interpret this that this feature is wanted, so I'll make a more serious effort and get back to you. BTW, where are the semantics for these movement functions defined? I mean, what construct is each one expected to jump over? Theo