From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Plug treesit.el into other emacs constructs Date: Tue, 13 Dec 2022 18:10:12 -0500 Message-ID: References: <87wn6whete.fsf@thornhill.no> <87r0x3gnv5.fsf@thornhill.no> <87o7s7gji0.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="22546"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: emacs-devel@gnu.org, eliz@gnu.org, casouri@gmail.com To: Theodor Thornhill Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Dec 14 00:11:56 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 1p5ERH-0005d7-C0 for ged-emacs-devel@m.gmane-mx.org; Wed, 14 Dec 2022 00:11:55 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p5EPx-0005p4-2q; Tue, 13 Dec 2022 18:10:33 -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 1p5EPu-0005ob-TU for emacs-devel@gnu.org; Tue, 13 Dec 2022 18:10:30 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5EPm-0001Qp-Gf; Tue, 13 Dec 2022 18:10:25 -0500 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 95C0F80323; Tue, 13 Dec 2022 18:10:20 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 75C428025B; Tue, 13 Dec 2022 18:10:14 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1670973014; bh=1kjQSgoA25mrGEC7V1KZYVO3NEv/p6pcb5zm87TeML0=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=g04kk5VsVbqaW9DWz269BHqtYq5mhrYzq/kBDsRliDciZKb7Jx5qQoUYJnteZ5qJg /Cl7bnJJTxxuQkLODoMocFhBN2wB0qKHYJdPlslrO2kxz1M9NVwZkfud+CaTwUFv5c SsEskN6xerhw79BH5Fz3fSDhY/cCzfRMOSizFkM+1l/Wn0yJX9cie94ll4fC1pJiJV IR6EwXYThR2A7N4cZY519tZeV+b0TC1Xtj8ZUGBg8Da/wNGNeHT5OeSHDC6mPCMjbE XLA/kzZdl6Aj5mM/0Zho4EyKMc1+D9unQuKWI3F6e3l/90sVpdmUP2F71wgZyPHRiB FDLkZkPz4isqg== Original-Received: from pastel (unknown [45.72.193.52]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 4989912041B; Tue, 13 Dec 2022 18:10:14 -0500 (EST) In-Reply-To: <87o7s7gji0.fsf@thornhill.no> (Theodor Thornhill's message of "Tue, 13 Dec 2022 21:02:15 +0100") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=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:301364 Archived-At: > And in this case multiple forward-sexps would be > > ``` > |public void foo(Array, String>> bar, String baz) > public| void foo(Array, String>> bar, String baz) > public void| foo|(Array, String>> bar, String baz) > public void foo(Array|, String>> bar, String baz) No, from before the paren, it should skip to after the paren, like it has done in the past. > public void foo(Array, String>> bar, String baz) > public void foo(Array, String>> bar, String baz) Similarly here, I'd expect to jump over the whole `, String>`. >> Because point was left of the comma and the smallest right child of the >> corresponding node is "String bar" and not "String" (which is more like >> the left child of the node that covers "String bar"). > Ok, so you mean that forward-sexp should incrementally cover more and > more of a node, but transpose-sexp would find the _whole_ node, then > swap it with the one "in front" of it? > > so in 'void(String foo, int bar)' > > forward-sexp would go word by word, but transpose-sexp would capture > "String foo" and "int bar" when point is on the comma? When point is left of a comma, it can't be claimed to be "just before String foo" because there's a comma between the two, so `forward-sexp` can skip over the whole right-hand-side of the comma: (y + 2,| x + 4) ==forward-sexp==> (y + 2, x| + 4) (y + 2|, x + 4) ==forward-sexp==> (y + 2, x + 4|) Similarly when going backward, if we're to the *right* of a comma, we'd want to jump over the whole left-hand side of the comma: (y + 2,| x + 4) ==backward-sexp==> (|y + 2, x + 4) (y + 2|, x + 4) ==backward-sexp==> (y + |2, x + 4|) For `transpose-sexp` we want to transpose two nodes at the same level of the tree, so regardless if we're to the left or to the right of a comma, we want to swap the whole left/right hand sides: (y + 2,| x + 4) ==backward-sexp==> (x + 4, y + 2|) (y + 2|, x + 4) ==backward-sexp==> (x + 4, y + 2|) For SMIE this happens "automatically" because `transpose-sexp` first "steps back" before jumping over a sexp: it skips punctuation backward before jumping with `forward-sexp` and skips punctuation forward before jump with `backward-sexp`. This works for infix operators that use punctuation syntax, but not for infix operators like `else`. >>> I mean, what construct is each one expected to jump over? >> In my book "sexp" movement should jump over subtrees of the AST. > So given this ast point should move over each named node, no matter if > transposing them would create broken code? Sorry, I don't understand what you mean by "move over each named node". > Forgive my stupid questions, I just want it to be clear to me what I'm > doing here ;) The semantics I advocate aren't necessarily the "right" one. It's the one I came up with when I tried to make sense of it for SMIE. I think they make sense and I find it hard to imagine others that make as much sense, but if I can't convince you, maybe there's something better out there. Stefan