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: Wed, 14 Dec 2022 21:04:03 +0100 Message-ID: <87bko521n0.fsf@thornhill.no> References: <87wn6whete.fsf@thornhill.no> <87r0x3gnv5.fsf@thornhill.no> <04BB786A-3ED1-4918-8583-17AA01A1E453@gmail.com> <4E3940CA-67A6-45B7-8785-4E60FDECCDFB@gmail.com> <4315EFC6-7AA8-4A48-845C-9CA8B88034D9@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="35719"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Yuan Fu , emacs-devel@gnu.org, eliz@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Dec 14 21:05:06 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 1p5Y01-00090x-1V for ged-emacs-devel@m.gmane-mx.org; Wed, 14 Dec 2022 21:05:05 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p5XzB-0007gz-8W; Wed, 14 Dec 2022 15:04:13 -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 1p5Xz9-0007dy-LJ for emacs-devel@gnu.org; Wed, 14 Dec 2022 15:04:11 -0500 Original-Received: from out-93.mta0.migadu.com ([91.218.175.93]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5Xz7-0002m3-56 for emacs-devel@gnu.org; Wed, 14 Dec 2022 15:04:11 -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=1671048246; 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=fRoeuKN2qQ04iFv9wrKmIqWllnnHxUYNZNnF8QNSWxA=; b=SNTOu5cTm1v2dpqP9JBykTtlmYm1uchofjO9HcLDVhpVSmdCA5gG/rK0U+S6P6haQabMUs bRNIiBGdAMU6FX8lYvl2mIy/3to5cSQC0w9LfdRHqO9+1KxLXiLDDzOtwRXW+ejo1uhBnR L3mBSWHrp6Wqt92KJA/gAfONX+Hg+Nmw467QSLPMkZRDMXOsgx8352zMU/YzDjKSqS7xqK 239VJ3KTkNn3RlyhO1/rIzr9AOE9n1Ock5ZvGc4QYngOXA0s8pdJ94Vo73UuDZ2ZnZvt7C 1eI3XYJZyu0LYyRrBy8sEUks+DjygKYG2b04arBjtNP09h3NgWQYpKE/DRtt/g== In-Reply-To: X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=91.218.175.93; envelope-from=theo@thornhill.no; helo=out-93.mta0.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, 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:301409 Archived-At: Stefan Monnier writes: >>>In this case, yes. But in other cases it will move at different levels >>>of the tree. E.g.: >>> >>> int x = f (b + 4, c * 7 - z * 2, d, e); >>> >>>It will sometimes move over the whole instruction, and other times over >>>just a single variable or over a whole argument or over just a "factor". >>>This depends on where point is when `forward/backward-sexp` is called. >> >> Yeah. I think this example shows what I find unintuitive. If point is right >> before the first comma, and we transpose-sexps, it could end up swapping >> 4 for c * 7 - z * 2, which would rarely make sense in this context. > > If so, that would be a bug in `transpose-sexp`, agreed. > I'm talking here about `forward/backward-sexp`. > The two are linked, but we shouldn't use one to justify a bug in the other. Sure, but I think they necessarily needs to be viewed as a whole. If we drop tree-sitter or SMIE (which I actually know pretty well) for one moment, the cc-mode based java-mode would exhibit the exact behavior I described. If it's a bug in tranpsose-sexps it is definitely an issue with forward/backward-sexp, because in every situation the positions to be swapped is just "backward-sexp - forward-sexp - forward-sexp - backward-sexp", right? And the thing in the middle, usually a comma, operators or other is the space between that doesn't move. I also observe this fixme inside of transpose-words: ;; FIXME: `foo a!nd bar' should transpose into `bar and foo'. I read this more like it's how transpose-sexps should behave on text. There are almost no differences between forward-word and forward-sexp in normal prose, bar the case of delimiters, IIUC. Wouldn't it make sense to make transpose-sexps actually do what that fixme asks? And why is the (cons (progn (funcall mover x) (point)) (progn (funcall mover (- x)) (point))) in this form, and not some pseudo-code like: (cons '(backward-thing-from-start-point forward-thing-point) '(forward-thing-from-start-point backward-thing-point)) So that 'foo a|nd bar' would create these points: |foo| a|nd |bar| 1 2 ^ 4 3 start Then forward-word could behave like it does now. Now I'm having issues where movement over sexps ends up not in the same place. > > `Forward-sexp` from > > int x = f (b + 4|, c * 7 - z * 2, d, e); > > should work by delimiting the two things to swap *plus* the thing > in-between, and in this case it should be: > > int x = f (, , d, e); > > Notice how it needs to figure out the ", ". Once this is figured out, > it's easy to use `forward/backward-sexp` to find the other 2 boundaries > (if you want to re-use the `forward/backward-sexp`, like the code > currently does): > > Use `forward-sexp` from > > int x = f (b + 4|, c * 7 - z * 2, d, e); > > and `backward-sexp` from > > int x = f (b + 4, |c * 7 - z * 2, d, e); > >> Swapping b + 4 with c * 7 - z * 2 would make sense here, imo. >> I believe this is not how you see it? > > Looks like I wasn't clear enough. I do agree with you on this, and SMIE > agrees with you as well, if you try `M-C-t` on the above code in > tuareg-mode. I think we agree, yes. Thanks for taking the time :-) Theo