GNU bug report logs - #60655
30.0.50; tree-sitter: `treesit-transpose-sexps' is broken.

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Mickey Petersen <mickey@HIDDEN>; Done: Juri Linkov <juri@HIDDEN>; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
bug marked as fixed in version 31.0.50, send any further explanations to 60655 <at> debbugs.gnu.org and Mickey Petersen <mickey@HIDDEN> Request was from Juri Linkov <juri@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 60655 <at> debbugs.gnu.org:


Received: (at 60655) by debbugs.gnu.org; 4 Jan 2025 18:32:01 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Jan 04 13:32:01 2025
Received: from localhost ([127.0.0.1]:57316 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tU8wL-0006KO-0r
	for submit <at> debbugs.gnu.org; Sat, 04 Jan 2025 13:32:01 -0500
Received: from relay2-d.mail.gandi.net ([217.70.183.194]:37759)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <juri@HIDDEN>)
 id 1tU8wI-0006K0-9c; Sat, 04 Jan 2025 13:31:59 -0500
Received: by mail.gandi.net (Postfix) with ESMTPSA id AEFF440002;
 Sat,  4 Jan 2025 18:31:48 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
To: Mickey Petersen <mickey@HIDDEN>
Subject: Re: bug#60655: 30.0.50; tree-sitter: `treesit-transpose-sexps' is
 broken.
In-Reply-To: <87ed1p58vp.fsf@HIDDEN> (Juri Linkov's message of "Mon, 
 30 Dec 2024 20:22:02 +0200")
Organization: LINKOV.NET
References: <87r0w5jo0i.fsf@HIDDEN>
 <87ed1p58vp.fsf@HIDDEN>
Date: Sat, 04 Jan 2025 20:30:28 +0200
Message-ID: <87jzbal9dn.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain
X-GND-Sasl: juri@HIDDEN
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 60655
Cc: 60655 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

close 60655 31.0.50
thanks

>> The tree-sitter-enabled function, `treesit-transpose-sexps',
>> that is called by transpose-sexps, is broken.
>
> After many unsuccessful attempts I finally arrived at the
> usable implementation.  For example, typing 'C-M-t'
> between two conditions:

Ok, this is pushed now to master.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#60655; Package emacs. Full text available.

Message received at 60655 <at> debbugs.gnu.org:


Received: (at 60655) by debbugs.gnu.org; 30 Dec 2024 18:25:37 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Dec 30 13:25:37 2024
Received: from localhost ([127.0.0.1]:59921 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tSKSP-0008Ca-3j
	for submit <at> debbugs.gnu.org; Mon, 30 Dec 2024 13:25:37 -0500
Received: from relay1-d.mail.gandi.net ([217.70.183.193]:48671)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1tSKSM-0008CD-4h
 for 60655 <at> debbugs.gnu.org; Mon, 30 Dec 2024 13:25:35 -0500
Received: by mail.gandi.net (Postfix) with ESMTPSA id E9C57240006;
 Mon, 30 Dec 2024 18:25:05 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
To: Mickey Petersen <mickey@HIDDEN>
Subject: Re: bug#60655: 30.0.50; tree-sitter: `treesit-transpose-sexps' is
 broken.
In-Reply-To: <87r0w5jo0i.fsf@HIDDEN> (Mickey Petersen's message of
 "Sun, 08 Jan 2023 10:53:33 +0000")
Organization: LINKOV.NET
References: <87r0w5jo0i.fsf@HIDDEN>
Date: Mon, 30 Dec 2024 20:22:02 +0200
Message-ID: <87ed1p58vp.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-GND-Sasl: juri@HIDDEN
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 60655
Cc: 60655 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

--=-=-=
Content-Type: text/plain

> The tree-sitter-enabled function, `treesit-transpose-sexps',
> that is called by transpose-sexps, is broken.

After many unsuccessful attempts I finally arrived at the
usable implementation.  For example, typing 'C-M-t'
between two conditions:

if (x > 72 &&
    -!-y < 85) { // found
  do_something();
}

swaps these two conditions:

if (y < 85 &&
    x > 72) { // found
  do_something();
}

whereas inside the binary expression

if (x > -!-72 &&
    y < 85) { // found
  do_something();
}

it swaps its components:

if (72 > x &&
    y < 85) { // found
  do_something();
}

Or with point between two objects in an array:

var a = [{
  case: 'zzzz',
  default: 'yyyy'
},
-!-{
  case: 'zzzz2',
  default: 'yyyy'
}];

it swaps these objects:

var a = [{
  case: 'zzzz2',
  default: 'yyyy'
},
{
  case: 'zzzz',
  default: 'yyyy'
}];

whereas with point between two pairs

var a = [{
  case: 'zzzz',
  -!-default: 'yyyy'
}];

it swaps these pairs

var a = [{
  default: 'yyyy',
  case: 'zzzz'
}];

while keeping the right punctuation.

In a string it falls back to the default function.


--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline; filename=treesit-transpose-sexps.patch

diff --git a/lisp/treesit.el b/lisp/treesit.el
index 4fe4f7276f6..c17ffb1f9f4 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -2608,26 +2630,15 @@ treesit-transpose-sexps
 Return a pair of positions as described by
 `transpose-sexps-function' for use in `transpose-subr' and
 friends."
-  ;; First arrive at the right level at where the node at point is
-  ;; considered a sexp. If sexp isn't defined, or we can't find any
-  ;; node that's a sexp, use the node at point.
-  (let* ((node (or (treesit-thing-at-point 'sexp 'nested)
-                   (treesit-node-at (point))))
-         (parent (treesit-node-parent node))
-         (child (treesit-node-child parent 0 t)))
-    (named-let loop ((prev child)
-                     (next (treesit-node-next-sibling child t)))
-      (when (and prev next)
-        (if (< (point) (treesit-node-end next))
-            (if (= arg -1)
-                (cons (treesit-node-start prev)
-                      (treesit-node-end prev))
-              (when-let* ((n (treesit-node-child
-                              parent (+ arg (treesit-node-index prev t)) t)))
-                (cons (treesit-node-end n)
-                      (treesit-node-start n))))
-          (loop (treesit-node-next-sibling prev t)
-                (treesit-node-next-sibling next t)))))))
+  (let* ((pred #'treesit-node-named)
+         (sibling (if (> arg 0)
+                      (treesit-thing-next (point) pred)
+                    (treesit-thing-prev (point) pred))))
+    (or (when sibling
+          (if (> arg 0)
+              (cons (treesit-node-end sibling) (treesit-node-start sibling))
+            (cons (treesit-node-start sibling) (treesit-node-end sibling))))
+        (transpose-sexps-default-function arg))))
 
 ;;; Navigation, defun, things
 ;;

--=-=-=--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#60655; Package emacs. Full text available.

Message received at 60655 <at> debbugs.gnu.org:


Received: (at 60655) by debbugs.gnu.org; 9 Jan 2023 13:37:16 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Jan 09 08:37:16 2023
Received: from localhost ([127.0.0.1]:36048 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1pEsKy-0001X0-57
	for submit <at> debbugs.gnu.org; Mon, 09 Jan 2023 08:37:16 -0500
Received: from out2.migadu.com ([188.165.223.204]:11171)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <theo@HIDDEN>) id 1pEsKv-0001Wl-Rt
 for 60655 <at> debbugs.gnu.org; Mon, 09 Jan 2023 08:37:15 -0500
X-Report-Abuse: Please report any abuse attempt to abuse@HIDDEN and
 include these headers.
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no;
 s=key1; t=1673271432;
 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=BBDiDVFiMgkRE6YsF4N17Jq8zkgm4aIz/Mwlsd+pmhM=;
 b=BXUKzw+CNr2e7LoI+vtVYV3JGQZy8xtZT5vmDJOLzTrpDpqemKlmK/uN0SbBkg927jHZas
 NMsjS6tMLVsrF9dPzj3n2negZrJwPrTy/40Hi/CPyBt3i7P+R3JclprJjwsOz5vQwUAZ6t
 RPv+aoxeRZI8RnVS42ZQzTPsyE0biuOXPhesW20QYm5lfDkpTYIlGr6EX3AHJ0M7LLPgS8
 GLEcvNwtQh+16l3OGMSaw9BCCTyAxDQYA5aTAREiwFiM7o4GNYJ9nO6Up3xpW+mtwIkomw
 Db6ir7v/mDjcmT1b69Ppcg1t079YcWqwxJsft1eJiG+WpXvO1+WT5BdGZ1/pEQ==
From: Theodor Thornhill <theo@HIDDEN>
To: Mickey Petersen <mickey@HIDDEN>
Subject: Re: bug#60655: 30.0.50; tree-sitter: `treesit-transpose-sexps' is
 broken.
In-Reply-To: <877cxvj2ou.fsf@HIDDEN>
References: <87r0w5jo0i.fsf@HIDDEN>
 <87sfgkgqlj.fsf@HIDDEN> <878ricjdee.fsf@HIDDEN>
 <87cz7nuc13.fsf@HIDDEN> <877cxvj2ou.fsf@HIDDEN>
Date: Mon, 09 Jan 2023 14:37:11 +0100
Message-ID: <877cxvu8vs.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-Migadu-Flow: FLOW_OUT
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 60655
Cc: 60655 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Mickey Petersen <mickey@HIDDEN> writes:

> Theodor Thornhill <theo@HIDDEN> writes:
>
>> Mickey Petersen <mickey@HIDDEN> writes:
>>
>>> Theodor Thornhill <theo@HIDDEN> writes:
>>>
>>>> Mickey Petersen <mickey@HIDDEN> > The tree-sitter-enabled
>>>> function, `treesit-transpose-sexps', that is called by
>>>> transpose-sexps, is broken.
>>>>>
>>>>> It uses a naive method of sibling adjacency to determine
>>>>> transpositions. But it is unfortunately not correct.
>>>>>
>>>>> Python:
>>>>>
>>>>>
>>>>>   def -!-foo():
>>>>>       pass
>>>>>

[...]

>
> That, in my opinion, is the wrong way to look at it.
>
> `C-M-t' already works well: it transposes stuff around point. Nothing
> more, nothing less.
>
> If I write rubbish code as a human, no amount of machine intelligence
> will (yet) undo that. Nor should a 'clever' mechanism that is only
> clever by half. Trying to transpose things on, near or around
> point is a useful addition if, and only if, it can do so in a manner
> that is sensible, and predictable, to its operator.
>
> You will very quickly run into umpteen problems generalizing this.
> That's why I have shown restraint and limited Combobulate to things
> that I feel are simple (but made it quite easy for someone to
> customize, if they disagree!)

Yes, I agree. But the commands M-t and C-M-t are different for a reason,
so they should be used in different circumstances, right?

>
> As a user, I may well want to put my code into an erroneous state,
> temporarily, because I am doing something that cannot be represented
> atomically as a single command. Therefore, `self-insert-command' (for
> example) does not predict what I am about to type and intercedes when
> it disagrees with me: it merely abides.
>
> When I do this with `C-M-t' it is because it is an intentional act on
> my behalf. The example I gave above is illustrative; it's designed to
> highlight the problem.
>

Sure, I believe I understand what you mean.

>>>
>>>
>>>
>>>>> You could make a cogent argument that both approaches are wrong from a
>>>>> syntactic perspective, but I think that misses the broader point that
>>>>> `C-M-t' now does something errant and unexpected.
>>>>
>>>> I don't really see how "foo def():" is any better at all.  We gain some
>>>> great improvements with this "naive" method - namely:
>>>>
>>>> if 5 + 5 == 10 then 10 else 100 + 100.  If point is on the else the 100
>>>> + 100 wil be swapped by 10, but the old behavior will be broken.
>>>>
>>>
>>> The old behaviour was consistent. It had a simple *modus operandi*:
>>> swap two things around point. As someone who has used `C-M-t' for
>>> decades, I know what it'll do in pretty much all situations, because I
>>> know what `C-M-k` and `C-M-f/b` do at all times.

Yeah, but "thing" is very vague, so the consistency is an accident more
than anything else.

>>
>> It may be consistent, but imo it is too close to transpose-words, and
>> too likely to create useless code in non-lisp languages.
>>
>
> No, transpose word and transpose sexp are very different; do different
> things; and apply in vastly different circumstances:
>
> Let -!- be point:
>
>     d = {'Hello, World!': -!- 1}
>
>     # C-M-t
>     d = {1: 'Hello, World!'}
>
>     # M-t
>     d = {'Hello, 1!': World}
>
> `transpose-sexps' works just fine the way it is: enriching it with a
> greater understanding of certain contexts is a fruitful endeavour, if
> it is done sympathetically.
>

You say they are used in vastly different circumstances, and I argued
that the "def foo" case is a case where it should't be used.  I still
believe there are oceans of improvements to be made, but I don't
understand the desire not to improve what is there, whatever an
improvement is considered to be.

>>>
>>> Neither approach is great if you holistically approach this task as
>>> "making it correct at all times", and it is easy to confect scenarios
>>> that result in something that is semantically wrong, but syntactically
>>> correct; something that is plain wrong, both semantically and
>>> syntactically; and something that is occasionally correct.
>>>
>>
>> I see what you mean, but to me semantically _and_ syntactically correct
>> is the benefit we should pursue when we actually have the parse tree.
>> The current implementation will semantically correct in many interesting
>> cases, such as the one I outlined, and is a huge improvement to the
>> current "transpose-words"-like behavior.
>>
>

I see two directions myself.  Either we try to make a point that
transpose-words and transpose-sexps operate on different contexts, or we
try our best to blend the two, to avoid backwards incompatible changes.
I'm ok with both, myself.  We could even try to make a transpose-dwim
command that will guess the surroundings and choose modus-operandi
accordingly?


>
> Sure. But please be careful when you make changes to `transpose-subr'
> (or `transpose-subr-1') so that they don't break its existing contract
> with its current users. It is a *very* powerful set of commands that
> can swap arbitrary tracts of text.
>

Of course - I'm trying hard to be conservative :)

Theo




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#60655; Package emacs. Full text available.

Message received at 60655 <at> debbugs.gnu.org:


Received: (at 60655) by debbugs.gnu.org; 9 Jan 2023 12:46:40 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Jan 09 07:46:40 2023
Received: from localhost ([127.0.0.1]:35996 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1pErXz-000060-G8
	for submit <at> debbugs.gnu.org; Mon, 09 Jan 2023 07:46:40 -0500
Received: from mail-lo2gbr01on2097.outbound.protection.outlook.com
 ([40.107.10.97]:14800 helo=GBR01-LO2-obe.outbound.protection.outlook.com)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <mickey@HIDDEN>) id 1pErXw-00005k-Dq
 for 60655 <at> debbugs.gnu.org; Mon, 09 Jan 2023 07:46:37 -0500
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
 b=R32ETjzjlHmKkDRflS3fb+TgF5QBxGOsjykAA+shyARWh4S/AXC2RSvh8Dl7Ew2d1wMi6LRd+kqxzsmeNkiIuDTQxQS3Xyes2jyYw3XWIe8a9b97TeFDiNRHBm8Pp6mi7NONh9dCmW8Z97h73YNp5/vTXRdM4JpO81r/wQC8o9v/bnaCnTvUidGhUTIrv3a8Z2asCN/u+Eq62vZenm2f3HtVpEvSZexvElMMo4ek+D1uqnSqMAiD6uAj6B28zifwOO37+lQYA+0MoCsHCqRtCWfQZcdCFM6WhzslSLXIH2KR9WB+fh6GwuP115tz1u2swXa82ytDT4TkGmjCoS/PNA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; 
 s=arcselector9901;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;
 bh=/oJM6Jpn1jKkf4WzbEvPzktUJii07NjORHf+/Em9hns=;
 b=HPhzs4PsvB2oBReqgeUBfYWcUqr5YKhDFFt4GsjgjnnuX+4eurvn3iu+oL8pC9brfji68VliufqpfrTtSl3TNNixnaoXSQu6507A3QLaXqMveRswtK582bJRsMhy3/VSwNIgMv7QZ67VFIa/05YjvGYujvRlbTjUvgfPYGVjoHmWPBkm0BEZq887JYaF41KfvTRs8M8zOBGH9IbsWVCzhHUhWfdGvXdS+lk3tUMuUJBxVLJVAjSAcSIHbBoJM46XmLlXgcUzksaHXufJwJQVBavxu3O3MRYagM/ZL8bdfZ0wyMrDXTsBqi8/QuMyDHPBhEAXqdYTajEad/qi9k3LwQ==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is
 178.79.136.144) smtp.rcpttodomain=debbugs.gnu.org
 smtp.mailfrom=masteringemacs.org; dmarc=pass (p=none sp=none pct=100)
 action=none header.from=masteringemacs.org; dkim=pass (signature was
 verified) header.d=masteringemacs.org; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=semantical.onmicrosoft.com; s=selector1-semantical-onmicrosoft-com;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=/oJM6Jpn1jKkf4WzbEvPzktUJii07NjORHf+/Em9hns=;
 b=Db6qpYMT9RrPLpmmNf5bH/30NTdG0CkdCVY1OGzhDGaVUMKqlPW53caLpuY3CtoOolEf4IQZw3sMfLGwH6ob4GGUXLvzeFUNOo3QJBNSsawqHrzGmHfj+dqNuZlykgWKKUyGcLa/rLBGIXBr+6Id+sRBL69EWTwVMJ3/TOttdak=
Received: from LO2P265CA0246.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:8a::18)
 by LO2P265MB5887.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:26c::10) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Mon, 9 Jan
 2023 12:46:29 +0000
Received: from CWLGBR01FT007.eop-gbr01.prod.protection.outlook.com
 (2603:10a6:600:8a:cafe::10) by LO2P265CA0246.outlook.office365.com
 (2603:10a6:600:8a::18) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18 via Frontend
 Transport; Mon, 9 Jan 2023 12:46:28 +0000
X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 178.79.136.144)
 smtp.mailfrom=masteringemacs.org; dkim=pass (signature was verified)
 header.d=masteringemacs.org;dmarc=pass action=none
 header.from=masteringemacs.org;
Received-SPF: Pass (protection.outlook.com: domain of masteringemacs.org
 designates 178.79.136.144 as permitted sender)
 receiver=protection.outlook.com; client-ip=178.79.136.144;
 helo=semantical.co.uk; pr=C
Received: from semantical.co.uk (178.79.136.144) by
 CWLGBR01FT007.mail.protection.outlook.com (10.152.40.96) with Microsoft SMTP
 Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.20.5986.18 via Frontend Transport; Mon, 9 Jan 2023 12:46:28 +0000
Received: by semantical.co.uk (Postfix, from userid 5001)
 id 3E509114002; Mon,  9 Jan 2023 12:46:28 +0000 (GMT)
DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=masteringemacs.org;
 s=masteringemacs.org; t=1673268388;
 bh=6FIu6yC+zpj71QrDgPyr+fur3/jCZvXuMF//nn8kk8k=;
 h=References:From:To:Cc:Subject:Date:In-reply-to:From;
 b=dNwUcFI5fYDwLo+vFBhiavLKEEOQyWdD+RP+0Yn8tdLEy4xbQmW6fKJxRHHd/DyZM
 r5npKI9vpjv5QVT2jJey8knezZAmNO/36P6P4CEndRxzLjQN52bxo1rnsURNt1IlIs
 7E2WrPOhsQ9+NfrwuxOyrcnhJWVPUtOmcWO+K+Nw=
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on semantical.co.uk
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NO_RECEIVED,
 NO_RELAYS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2
References: <87r0w5jo0i.fsf@HIDDEN>
 <87sfgkgqlj.fsf@HIDDEN> <878ricjdee.fsf@HIDDEN>
 <87cz7nuc13.fsf@HIDDEN>
User-agent: mu4e @VERSION@; emacs 30.0.50
From: Mickey Petersen <mickey@HIDDEN>
To: Theodor Thornhill <theo@HIDDEN>
Subject: Re: bug#60655: 30.0.50; tree-sitter: `treesit-transpose-sexps' is
 broken.
Date: Mon, 09 Jan 2023 12:30:11 +0000
Organization: Mastering Emacs
In-reply-to: <87cz7nuc13.fsf@HIDDEN>
Message-ID: <877cxvj2ou.fsf@HIDDEN>
Content-Type: text/plain
X-EOPAttributedMessage: 0
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: CWLGBR01FT007:EE_|LO2P265MB5887:EE_
MIME-Version: 1.0
X-MS-Office365-Filtering-Correlation-Id: 9c93476c-7bb4-4045-46ed-08daf23f86e2
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam: BCL:0;
X-Microsoft-Antispam-Message-Info: N8qk12qgi8Ofpacdyc/aKnMU/e/nFFayUiuC9993DsbTEQtN6+wDdDHz+pxHIVxNPBAlbSJt4omFVlMjdTED082Eb3OEWKNbwcU3KTuOdamHaZT+NJ5ccMnjg5kqVGSteqM5JkWh9qnrprA9Ncjkpt+nr7Fwf3r5LmLr73ztYg05FTwoXJIVPvbfw51uJCV/CiS9xV1fKdWT1Z6rkNKYEWUHchtMb/IOFd9wJRg9t5uVesK56QE+rYgoZE1/fMMBY/iiybWhd9QLD3Mc7Kcjhrr9tpfmyNSRjfhOIY6EKFetvptxis3cSspDJUzcOe65gEOd0U99jYshdshilxXoQD5J7ZdY7Me6ubvLd3TeThrEBSSEhS3/TWlbkyjTV6XauEj0LT9skA+qhmam9kZysomqy07VJtH9MCq+AkvVtEa0XxKpDqfi/3yKZf+A6Oc6lhWXk63UPENc9rWFW0peFYvwk8lSDsEBEaRwsE7eoD3L8U9d6iVsR/E04WOM2+x9+EObUvOE7t34z6DFnrmZP+T2NbQKDhin/3z6AOYuTeZtogAfU+M41o0F03yKRJkANuxXUhhVziOJV4rTi0+XBzSX7hnTPGplNd3U3YGEJJ0DbGvgdhxteSFVgBQ5iRtwVPhaesaIVkYuTCbXTDLnSZUcepHt4jug+p4okJSjhYTf2FBAqlVzbo0OI49BQghszz1nzlN2QN3eZt26V6/WB92mn9zo3oX2gBRKOzAto0EKSVF7CsK0bMzs5hkGUkf59O22wdXRkxKwkZ9ZXIwGoQ==
X-Forefront-Antispam-Report: CIP:178.79.136.144; CTRY:GB; LANG:en; SCL:1; SRV:;
 IPV:NLI; SFV:NSPM; H:semantical.co.uk; PTR:semantical.co.uk; CAT:NONE;
 SFS:(13230022)(376002)(39830400003)(136003)(396003)(346002)(451199015)(36840700001)(46966006)(4326008)(42186006)(70586007)(70206006)(316002)(8676002)(36916002)(356005)(2906002)(7636003)(5660300002)(8936002)(7596003)(41300700001)(47076005)(6862004)(86362001)(36860700001)(478600001)(83380400001)(6666004)(336012)(6266002)(186003)(26005)(2616005)(40480700001)(36756003)(82310400005)(38230200001)(81973001)(79816003)(14776008);
 DIR:OUT; SFP:1102; 
X-OriginatorOrg: masteringemacs.org
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jan 2023 12:46:28.5715 (UTC)
X-MS-Exchange-CrossTenant-Network-Message-Id: 9c93476c-7bb4-4045-46ed-08daf23f86e2
X-MS-Exchange-CrossTenant-Id: a4e27e3d-bab0-45e8-8942-e64cf9fbd34f
X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=a4e27e3d-bab0-45e8-8942-e64cf9fbd34f; Ip=[178.79.136.144];
 Helo=[semantical.co.uk]
X-MS-Exchange-CrossTenant-AuthSource: CWLGBR01FT007.eop-gbr01.prod.protection.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Anonymous
X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem
X-MS-Exchange-Transport-CrossTenantHeadersStamped: LO2P265MB5887
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 60655
Cc: 60655 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)


Theodor Thornhill <theo@HIDDEN> writes:

> Mickey Petersen <mickey@HIDDEN> writes:
>
>> Theodor Thornhill <theo@HIDDEN> writes:
>>
>>> Mickey Petersen <mickey@HIDDEN> > The tree-sitter-enabled
>>> function, `treesit-transpose-sexps', that is called by
>>> transpose-sexps, is broken.
>>>>
>>>> It uses a naive method of sibling adjacency to determine
>>>> transpositions. But it is unfortunately not correct.
>>>>
>>>> Python:
>>>>
>>>>
>>>>   def -!-foo():
>>>>       pass
>>>>
>>>> Turns into this with `C-M-t':
>>>>
>>>>   def ()foo:
>>>>       pass
>>>>
>>>> But it ought to be:
>>>>
>>>>   foo def():
>>>>       pass
>>>>
>>>>
>>>> It's swapping two siblings that are indeed adjacent in the tree, but
>>>> not on screen, which is confusing and a regression from its previous
>>>> behaviour.
>>>>
>>>
>>> I can try to make transpose-sexps rely on only swapping "allowed"
>>> node-types?  That would be able to keep the new, better function, yet
>>> still disallow these syntax-breaking transposes.  What do you think?
>>>
>>
>> This is a hard problem. I'm building the self-same in Combobulate, so
>> when I saw this implementation I saw a well-trodden path by myself.
>> There's a lot of subtlety to it, and it is not immediately possible to
>> accurately gauge the right things to swap with simple (or not so
>> simple) sibling transpositions.
>>
>> Using a defined list is better, but with the caveat that it requires manual
>> intervention per mode. This is a really tricky thing to build well.
>
> Yeah, but I guess that is a sensible change.  It isn't easy, no, so I'm
> open for suggestions and improvements.  IMO an improvement would be to
> increase the likelihood that a transpose-sexps will still be valid code.
> I don't really think it is useful to do things like "def foo() -> foo
> def()" because that is nonsensical code, and is covered by
> transpose-words anyway.  To me a _more_ sensible approach here would be
> to transpose the defun at point with the next one, as they are usually
> interchangeable.  I am looking into such an improvement, and have been
> for a while.
>

That, in my opinion, is the wrong way to look at it.

`C-M-t' already works well: it transposes stuff around point. Nothing
more, nothing less.

If I write rubbish code as a human, no amount of machine intelligence
will (yet) undo that. Nor should a 'clever' mechanism that is only
clever by half. Trying to transpose things on, near or around
point is a useful addition if, and only if, it can do so in a manner
that is sensible, and predictable, to its operator.

You will very quickly run into umpteen problems generalizing this.
That's why I have shown restraint and limited Combobulate to things
that I feel are simple (but made it quite easy for someone to
customize, if they disagree!)

As a user, I may well want to put my code into an erroneous state,
temporarily, because I am doing something that cannot be represented
atomically as a single command. Therefore, `self-insert-command' (for
example) does not predict what I am about to type and intercedes when
it disagrees with me: it merely abides.

When I do this with `C-M-t' it is because it is an intentional act on
my behalf. The example I gave above is illustrative; it's designed to
highlight the problem.

>>
>>
>>
>>>> You could make a cogent argument that both approaches are wrong from a
>>>> syntactic perspective, but I think that misses the broader point that
>>>> `C-M-t' now does something errant and unexpected.
>>>
>>> I don't really see how "foo def():" is any better at all.  We gain some
>>> great improvements with this "naive" method - namely:
>>>
>>> if 5 + 5 == 10 then 10 else 100 + 100.  If point is on the else the 100
>>> + 100 wil be swapped by 10, but the old behavior will be broken.
>>>
>>
>> The old behaviour was consistent. It had a simple *modus operandi*:
>> swap two things around point. As someone who has used `C-M-t' for
>> decades, I know what it'll do in pretty much all situations, because I
>> know what `C-M-k` and `C-M-f/b` do at all times.
>
> It may be consistent, but imo it is too close to transpose-words, and
> too likely to create useless code in non-lisp languages.
>

No, transpose word and transpose sexp are very different; do different
things; and apply in vastly different circumstances:

Let -!- be point:

    d = {'Hello, World!': -!- 1}

    # C-M-t
    d = {1: 'Hello, World!'}

    # M-t
    d = {'Hello, 1!': World}

`transpose-sexps' works just fine the way it is: enriching it with a
greater understanding of certain contexts is a fruitful endeavour, if
it is done sympathetically.

>>
>> Neither approach is great if you holistically approach this task as
>> "making it correct at all times", and it is easy to confect scenarios
>> that result in something that is semantically wrong, but syntactically
>> correct; something that is plain wrong, both semantically and
>> syntactically; and something that is occasionally correct.
>>
>
> I see what you mean, but to me semantically _and_ syntactically correct
> is the benefit we should pursue when we actually have the parse tree.
> The current implementation will semantically correct in many interesting
> cases, such as the one I outlined, and is a huge improvement to the
> current "transpose-words"-like behavior.
>

There is no such thing as "syntactically correct" if you allow a user
unfettered access to type in a buffer. Merely typing in the wrong
place will break that promise. And who are we to judge what someone
writes and where?

The resting state of all code is "almost always broken" as you're
typing out your code.

>> 'Like' siblings are an easy way out of this mess with the caveat, as
>> you'll see, but now you need to carefully pluck the right nodes from
>> the tree!
>>
>> Consider the node type `pair' in a dict in Python. They are easily transposable for
>> that very reason, notwithstanding the anonymous "," node betwixt them.
>>
>> That is why Combobulate has a list of stuff that it can safely
>> transpose, and for everything else it defaults to the "classic"
>> transpose.
>>
>
> Yeah, such an approach seems reasonable, and there is already precedence
> in defining such "things" in Emacs.  As for the default fallback, I'll
> see what I can do in the "treesit-transpose-sexps" function.  The
> machinery in transpose-subr and friends is a little finicky, so to
> adhere to that mechanism isn't the easiest thing.
>

Sure. But please be careful when you make changes to `transpose-subr'
(or `transpose-subr-1') so that they don't break its existing contract
with its current users. It is a *very* powerful set of commands that
can swap arbitrary tracts of text.

>>>>
>>>> Worse, it's not possible to revert to the old behaviour (see
>>>> bug#60654)
>>>>
>>>>
>>
>> Thanks for fixing that!
>>
>
> No problem - hopefully it is installed pretty soon.
>
> Theo





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#60655; Package emacs. Full text available.

Message received at 60655 <at> debbugs.gnu.org:


Received: (at 60655) by debbugs.gnu.org; 9 Jan 2023 12:29:18 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Jan 09 07:29:18 2023
Received: from localhost ([127.0.0.1]:35966 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1pErHB-0005n7-NI
	for submit <at> debbugs.gnu.org; Mon, 09 Jan 2023 07:29:18 -0500
Received: from out-4.mta0.migadu.com ([91.218.175.4]:34220)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <theo@HIDDEN>) id 1pErH9-0005mv-MI
 for 60655 <at> debbugs.gnu.org; Mon, 09 Jan 2023 07:29:16 -0500
X-Report-Abuse: Please report any abuse attempt to abuse@HIDDEN and
 include these headers.
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no;
 s=key1; t=1673267354;
 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=7hMMt8sFthqDgWH4qtbi0FFipQpYkix4QrfUSZdZz6E=;
 b=yRA6pkT+ioTuZSI0HGgih5SAr6Xw+WAh447Ix0EXwvOVGlk2taj7KZ8V5LftknwvSinXtm
 g9wLjKdPhyy60BkmKwyNaIL0buA5db8QkZzQQaTdWlRC10BvLUrW+eTPhicTJme6rrxMWA
 wG3klI6j7NEUj8riIYPfWRTYkSsiQHcMvPKU+y4qNMT04RncZjI3xCIARlR6UK0TD1ivxd
 tI/AEpVzOTSrjDzhsl4q6mEbDsLbsM9ClfSO+ti7oJos5c/Ff+NV9S0+VbGwV1wAoCuNMw
 H9hRIx6twNctBsdULYFsNK4ZyA5LC6W9hrnKaIpeGhaT+pXO5pmSu8z70PXNXw==
From: Theodor Thornhill <theo@HIDDEN>
To: Mickey Petersen <mickey@HIDDEN>
Subject: Re: bug#60655: 30.0.50; tree-sitter: `treesit-transpose-sexps' is
 broken.
In-Reply-To: <878ricjdee.fsf@HIDDEN>
References: <87r0w5jo0i.fsf@HIDDEN>
 <87sfgkgqlj.fsf@HIDDEN> <878ricjdee.fsf@HIDDEN>
Date: Mon, 09 Jan 2023 13:29:12 +0100
Message-ID: <87cz7nuc13.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-Migadu-Flow: FLOW_OUT
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 60655
Cc: 60655 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Mickey Petersen <mickey@HIDDEN> writes:

> Theodor Thornhill <theo@HIDDEN> writes:
>
>> Mickey Petersen <mickey@HIDDEN> > The tree-sitter-enabled
>> function, `treesit-transpose-sexps', that is called by
>> transpose-sexps, is broken.
>>>
>>> It uses a naive method of sibling adjacency to determine
>>> transpositions. But it is unfortunately not correct.
>>>
>>> Python:
>>>
>>>
>>>   def -!-foo():
>>>       pass
>>>
>>> Turns into this with `C-M-t':
>>>
>>>   def ()foo:
>>>       pass
>>>
>>> But it ought to be:
>>>
>>>   foo def():
>>>       pass
>>>
>>>
>>> It's swapping two siblings that are indeed adjacent in the tree, but
>>> not on screen, which is confusing and a regression from its previous
>>> behaviour.
>>>
>>
>> I can try to make transpose-sexps rely on only swapping "allowed"
>> node-types?  That would be able to keep the new, better function, yet
>> still disallow these syntax-breaking transposes.  What do you think?
>>
>
> This is a hard problem. I'm building the self-same in Combobulate, so
> when I saw this implementation I saw a well-trodden path by myself.
> There's a lot of subtlety to it, and it is not immediately possible to
> accurately gauge the right things to swap with simple (or not so
> simple) sibling transpositions.
>
> Using a defined list is better, but with the caveat that it requires manual
> intervention per mode. This is a really tricky thing to build well.

Yeah, but I guess that is a sensible change.  It isn't easy, no, so I'm
open for suggestions and improvements.  IMO an improvement would be to
increase the likelihood that a transpose-sexps will still be valid code.
I don't really think it is useful to do things like "def foo() -> foo
def()" because that is nonsensical code, and is covered by
transpose-words anyway.  To me a _more_ sensible approach here would be
to transpose the defun at point with the next one, as they are usually
interchangeable.  I am looking into such an improvement, and have been
for a while.

>
>
>
>>> You could make a cogent argument that both approaches are wrong from a
>>> syntactic perspective, but I think that misses the broader point that
>>> `C-M-t' now does something errant and unexpected.
>>
>> I don't really see how "foo def():" is any better at all.  We gain some
>> great improvements with this "naive" method - namely:
>>
>> if 5 + 5 == 10 then 10 else 100 + 100.  If point is on the else the 100
>> + 100 wil be swapped by 10, but the old behavior will be broken.
>>
>
> The old behaviour was consistent. It had a simple *modus operandi*:
> swap two things around point. As someone who has used `C-M-t' for
> decades, I know what it'll do in pretty much all situations, because I
> know what `C-M-k` and `C-M-f/b` do at all times.

It may be consistent, but imo it is too close to transpose-words, and
too likely to create useless code in non-lisp languages.

>
> Neither approach is great if you holistically approach this task as
> "making it correct at all times", and it is easy to confect scenarios
> that result in something that is semantically wrong, but syntactically
> correct; something that is plain wrong, both semantically and
> syntactically; and something that is occasionally correct.
>

I see what you mean, but to me semantically _and_ syntactically correct
is the benefit we should pursue when we actually have the parse tree.
The current implementation will semantically correct in many interesting
cases, such as the one I outlined, and is a huge improvement to the
current "transpose-words"-like behavior.  

> 'Like' siblings are an easy way out of this mess with the caveat, as
> you'll see, but now you need to carefully pluck the right nodes from
> the tree!
>
> Consider the node type `pair' in a dict in Python. They are easily transposable for
> that very reason, notwithstanding the anonymous "," node betwixt them.
>
> That is why Combobulate has a list of stuff that it can safely
> transpose, and for everything else it defaults to the "classic"
> transpose.
>

Yeah, such an approach seems reasonable, and there is already precedence
in defining such "things" in Emacs.  As for the default fallback, I'll
see what I can do in the "treesit-transpose-sexps" function.  The
machinery in transpose-subr and friends is a little finicky, so to
adhere to that mechanism isn't the easiest thing.

>>>
>>> Worse, it's not possible to revert to the old behaviour (see
>>> bug#60654)
>>>
>>>
>
> Thanks for fixing that!
>

No problem - hopefully it is installed pretty soon.

Theo




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#60655; Package emacs. Full text available.

Message received at 60655 <at> debbugs.gnu.org:


Received: (at 60655) by debbugs.gnu.org; 9 Jan 2023 08:55:22 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Jan 09 03:55:22 2023
Received: from localhost ([127.0.0.1]:35734 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1pEnwA-0005xe-7u
	for submit <at> debbugs.gnu.org; Mon, 09 Jan 2023 03:55:22 -0500
Received: from mail-lo2gbr01on2120.outbound.protection.outlook.com
 ([40.107.10.120]:22400 helo=GBR01-LO2-obe.outbound.protection.outlook.com)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <mickey@HIDDEN>) id 1pEnw5-0005xH-A9
 for 60655 <at> debbugs.gnu.org; Mon, 09 Jan 2023 03:55:20 -0500
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
 b=O5nAmZh821eBbKYftRya1iAzbab5jPOPryqsHdEKNug5vRboVzibJEl+h/vDVvgVlew7iZhtep+QGXQBo5eRRrRuAxcraxEkrmq/K0+SzjOoBQs4fSnlpvbLz6rlZARslRlVa15jXDDLuzcbTY0LiTclD+LPmdI6ajEap0NheciGf3MSe1ZtGoRhBvTsao0hSQtOC+hVobcbwg5skdpael+naELQnp0wnHQd8on2/rGQI1aEknVD5McbeQtskC6o/WaompXLE3ThDwtEBqWGQzF+TC/SLlFqHNRsi8Nur1PmsKG9obThiInWtRR1lnLe08ZQ94oEXAryeEinC7at8Q==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; 
 s=arcselector9901;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;
 bh=8qtW1v0do1k44lg4gSAnGPu16dlrd26mOFRuGgbNbbs=;
 b=nJgtaYE0t+DopEMZNHUHRqErL3XZdqywKarhd2g93YTe2WHWaC967b75Q0L52jMtyh8uqcyaH+MwzkJpXVwj+ZAJ6Dq56XYe6E+o14/WksZzLmV95d+n6mBIgYEqlK/pg76P9xfPwu3FbZrp4WUMHnQw/CdRiOeGItDLIBqlsSmv4Ui+k0ecW1Ep/YdZrSrH2XBcxc8j4CJu4vOaOb1l88pOMKMaca/MeXqRklLavlH2MhMptCaSBRDobAC9Xn5JLfpdJBDxqJn9FbBFsMaew+43bgP9wsBZG67zqehNxLCnIJY+9jcRb9qx0LlaNKnmRgyhPduJuHqc5Eu36hKxog==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is
 178.79.136.144) smtp.rcpttodomain=debbugs.gnu.org
 smtp.mailfrom=masteringemacs.org; dmarc=pass (p=none sp=none pct=100)
 action=none header.from=masteringemacs.org; dkim=pass (signature was
 verified) header.d=masteringemacs.org; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=semantical.onmicrosoft.com; s=selector1-semantical-onmicrosoft-com;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=8qtW1v0do1k44lg4gSAnGPu16dlrd26mOFRuGgbNbbs=;
 b=GI5OjQpkKJmd1D2TtoXXA0yf0BdlmLK2v2Y/L58O4vekiQv9ZJYjmmJgzqNaJMnHU2tkqtmbgQLBaXYMeoQvSUJXB+CLad3ZioTTgc+Dpecuuyb6tAsene14mgTuz/xPfpp2JloW4pcrPIZrrMTqFA6IQ/UWVX3oFNvOORyJou4=
Received: from LO4P123CA0346.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18d::9)
 by LO6P265MB6542.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2d2::6) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Mon, 9 Jan
 2023 08:55:10 +0000
Received: from CWLGBR01FT036.eop-gbr01.prod.protection.outlook.com
 (2603:10a6:600:18d:cafe::7f) by LO4P123CA0346.outlook.office365.com
 (2603:10a6:600:18d::9) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18 via Frontend
 Transport; Mon, 9 Jan 2023 08:55:10 +0000
X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 178.79.136.144)
 smtp.mailfrom=masteringemacs.org; dkim=pass (signature was verified)
 header.d=masteringemacs.org;dmarc=pass action=none
 header.from=masteringemacs.org;
Received-SPF: Pass (protection.outlook.com: domain of masteringemacs.org
 designates 178.79.136.144 as permitted sender)
 receiver=protection.outlook.com; client-ip=178.79.136.144;
 helo=semantical.co.uk; pr=C
Received: from semantical.co.uk (178.79.136.144) by
 CWLGBR01FT036.mail.protection.outlook.com (10.152.40.164) with Microsoft SMTP
 Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.20.5986.18 via Frontend Transport; Mon, 9 Jan 2023 08:55:09 +0000
Received: by semantical.co.uk (Postfix, from userid 5001)
 id AD7CF114003; Mon,  9 Jan 2023 08:55:08 +0000 (GMT)
DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=masteringemacs.org;
 s=masteringemacs.org; t=1673254508;
 bh=yfexhumUbs5QWkcdZBhYtaOdsyUGEKisNU9BGXZSb88=;
 h=References:From:To:Cc:Subject:Date:In-reply-to:From;
 b=n3L07HjPowm/Cyv+yCRPSuQGfpBu50t5VbRV7KUCC2T6BMawzYd9/7N1wYBWUdZfM
 9G2ueZNCYff9ATg/y6WsBE0lWlGDEUoEHq1coNvKW3uVNzaaW6mUoNN6ossr58bIVi
 5d2orm7Y3mDLoV9dzse9p/NvsUvXaRE1z7uNmMa4=
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on semantical.co.uk
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NO_RECEIVED,
 NO_RELAYS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no
 version=3.4.2
References: <87r0w5jo0i.fsf@HIDDEN> <87sfgkgqlj.fsf@HIDDEN>
User-agent: mu4e @VERSION@; emacs 30.0.50
From: Mickey Petersen <mickey@HIDDEN>
To: Theodor Thornhill <theo@HIDDEN>
Subject: Re: bug#60655: 30.0.50; tree-sitter: `treesit-transpose-sexps' is
 broken.
Date: Mon, 09 Jan 2023 08:48:04 +0000
Organization: Mastering Emacs
In-reply-to: <87sfgkgqlj.fsf@HIDDEN>
Message-ID: <878ricjdee.fsf@HIDDEN>
Content-Type: text/plain
X-EOPAttributedMessage: 0
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: CWLGBR01FT036:EE_|LO6P265MB6542:EE_
MIME-Version: 1.0
X-MS-Office365-Filtering-Correlation-Id: e7cd996d-a0e6-498e-a3c5-08daf21f3637
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam: BCL:0;
X-Microsoft-Antispam-Message-Info: m/qxfnF9g0SmeZZPJHVQLLNxCrf54eAhkaQ65y/CVK62dfi5Jw4cG9bw7bUwzheqIvUxkeU8l5t+JJ1PTUumLgcIMhxxTPBejKAZjj7j3cPDdW1vmajxqf3Fk0a7ZXOcU0BqJtB18ipmgvi25umS9JKu2Fd9Uc+bvrHHLugcl3M+GZQnHn3qHiV1lwpM9QDp8bATjA0TK+nv4Wf8c8hP82eh3tM/TApajLNjY8RhYv4FGL3HtaaUNvQ6b+n62LHChxOgebhqyFHTqEoRthtMoSWsKKDpUVAewnt4amFzrHnqfVD+/qOHKYxFRtZSy/VJXVwdyj5qeLAwghEQpF6Z/IM5v81q3l/4xnvLgC/RHCXPrH0B4FUJvlna+x3pPD3lZwRzm33kEoVquuLYclg8zlCy9A00LJOhCgUEVZtOtfNUq9VboMFLF0y/RUAtfoX6YETIuw7DvGovnOKh0OUMyIsPxkfK9Lo93//8cgLltT8L9r83zFYPyjmtMQH9OmIh9v77NNK1KkdAsmfAjv25M9fobmf4ieDVz0fRiQS/HKukFv/J0YaVDn01M/e7YxLgHbj6ZeDsdqyOIf8V3/q+YCnIz9aFk2u0LdkjJvj/XOYeYIq6xMXxgZ+dvA2woytai4tg+yRMM9pHMESYx5ZeY3YJ2u3eYbXknF2LeOBpmW/ANVh7jMRmM6+ivxYVeHcmsUxyvUrbvTv500UmMAjwEhyneJLaDmDpDbmImoj3rE0WOy96eoFRM91RTIU4CD5LSVGxJXRNBrRE3uDolmAGmQ==
X-Forefront-Antispam-Report: CIP:178.79.136.144; CTRY:GB; LANG:en; SCL:1; SRV:;
 IPV:NLI; SFV:NSPM; H:semantical.co.uk; PTR:semantical.co.uk; CAT:NONE;
 SFS:(13230022)(346002)(396003)(376002)(136003)(39830400003)(451199015)(46966006)(36840700001)(36860700001)(6666004)(7596003)(7636003)(356005)(2906002)(478600001)(2616005)(26005)(36916002)(186003)(6266002)(5660300002)(316002)(40480700001)(83380400001)(8936002)(6862004)(82310400005)(36756003)(42186006)(86362001)(41300700001)(47076005)(70586007)(70206006)(8676002)(336012)(4326008)(38230200001)(81973001)(14776008)(79816003);
 DIR:OUT; SFP:1102; 
X-OriginatorOrg: masteringemacs.org
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jan 2023 08:55:09.3605 (UTC)
X-MS-Exchange-CrossTenant-Network-Message-Id: e7cd996d-a0e6-498e-a3c5-08daf21f3637
X-MS-Exchange-CrossTenant-Id: a4e27e3d-bab0-45e8-8942-e64cf9fbd34f
X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=a4e27e3d-bab0-45e8-8942-e64cf9fbd34f; Ip=[178.79.136.144];
 Helo=[semantical.co.uk]
X-MS-Exchange-CrossTenant-AuthSource: CWLGBR01FT036.eop-gbr01.prod.protection.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Anonymous
X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem
X-MS-Exchange-Transport-CrossTenantHeadersStamped: LO6P265MB6542
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 60655
Cc: 60655 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)


Theodor Thornhill <theo@HIDDEN> writes:

> Mickey Petersen <mickey@HIDDEN> > The tree-sitter-enabled
> function, `treesit-transpose-sexps', that is called by
> transpose-sexps, is broken.
>>
>> It uses a naive method of sibling adjacency to determine
>> transpositions. But it is unfortunately not correct.
>>
>> Python:
>>
>>
>>   def -!-foo():
>>       pass
>>
>> Turns into this with `C-M-t':
>>
>>   def ()foo:
>>       pass
>>
>> But it ought to be:
>>
>>   foo def():
>>       pass
>>
>>
>> It's swapping two siblings that are indeed adjacent in the tree, but
>> not on screen, which is confusing and a regression from its previous
>> behaviour.
>>
>
> I can try to make transpose-sexps rely on only swapping "allowed"
> node-types?  That would be able to keep the new, better function, yet
> still disallow these syntax-breaking transposes.  What do you think?
>

This is a hard problem. I'm building the self-same in Combobulate, so
when I saw this implementation I saw a well-trodden path by myself.
There's a lot of subtlety to it, and it is not immediately possible to
accurately gauge the right things to swap with simple (or not so
simple) sibling transpositions.

Using a defined list is better, but with the caveat that it requires manual
intervention per mode. This is a really tricky thing to build well.



>> You could make a cogent argument that both approaches are wrong from a
>> syntactic perspective, but I think that misses the broader point that
>> `C-M-t' now does something errant and unexpected.
>
> I don't really see how "foo def():" is any better at all.  We gain some
> great improvements with this "naive" method - namely:
>
> if 5 + 5 == 10 then 10 else 100 + 100.  If point is on the else the 100
> + 100 wil be swapped by 10, but the old behavior will be broken.
>

The old behaviour was consistent. It had a simple *modus operandi*:
swap two things around point. As someone who has used `C-M-t' for
decades, I know what it'll do in pretty much all situations, because I
know what `C-M-k` and `C-M-f/b` do at all times.

Neither approach is great if you holistically approach this task as
"making it correct at all times", and it is easy to confect scenarios
that result in something that is semantically wrong, but syntactically
correct; something that is plain wrong, both semantically and
syntactically; and something that is occasionally correct.

'Like' siblings are an easy way out of this mess with the caveat, as
you'll see, but now you need to carefully pluck the right nodes from
the tree!

Consider the node type `pair' in a dict in Python. They are easily transposable for
that very reason, notwithstanding the anonymous "," node betwixt them.

That is why Combobulate has a list of stuff that it can safely
transpose, and for everything else it defaults to the "classic"
transpose.

>>
>> Worse, it's not possible to revert to the old behaviour (see
>> bug#60654)
>>
>>

Thanks for fixing that!

Kind regards,

Mickey.

>
> Right.
>
> Thanks,
> Theo





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#60655; Package emacs. Full text available.

Message received at 60655 <at> debbugs.gnu.org:


Received: (at 60655) by debbugs.gnu.org; 9 Jan 2023 06:38:22 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Jan 09 01:38:22 2023
Received: from localhost ([127.0.0.1]:35627 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1pElnZ-0002Qj-Nk
	for submit <at> debbugs.gnu.org; Mon, 09 Jan 2023 01:38:22 -0500
Received: from out2.migadu.com ([188.165.223.204]:38134)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <theo@HIDDEN>) id 1pElnX-0002QZ-2u
 for 60655 <at> debbugs.gnu.org; Mon, 09 Jan 2023 01:38:19 -0500
X-Report-Abuse: Please report any abuse attempt to abuse@HIDDEN and
 include these headers.
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no;
 s=key1; t=1673246298;
 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=hZr47NKwMOI+PWxgj9vjkTRXxqHTsJJO4f6s9NkMBhE=;
 b=e5jRgoUfzffWny6MCeHnShGbx0aEq2phh7RB/FzRvDWjSyYlZkWnwQTS1Ty3a68/XFN/u1
 63ZOXOmNepS3dQXX2xKuZM3v11gqhjuidP8Oqu3A8M5AxjPN9uTSaMISgW9AcVFm3LEPqz
 Ia6cA5m2sQyaqsQmUSC5jtx+GOmhqSGcEZG6zhhBUvF6vLK7epBDzmOVXRiR3Dnluhy/hT
 VIxRVs2idjYjho1ak8l65hSsppGxFr3153UiywB4U60xqIU8D4BEIavJU9QzInFIODh2zE
 fKyZJ6AqUQ9lmso6bORLbeYVeqdAg3d2b/MTEvWaXjEcasmnub0qlsjgMUwumA==
From: Theodor Thornhill <theo@HIDDEN>
To: Mickey Petersen <mickey@HIDDEN>
Subject: Re: bug#60655: 30.0.50; tree-sitter: `treesit-transpose-sexps' is
 broken.
In-Reply-To: <87r0w5jo0i.fsf@HIDDEN> (Mickey Petersen's message of
 "Sun, 08 Jan 2023 10:53:33 +0000")
References: <87r0w5jo0i.fsf@HIDDEN>
Date: Mon, 09 Jan 2023 07:38:16 +0100
Message-ID: <87sfgkgqlj.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-Migadu-Flow: FLOW_OUT
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 60655
Cc: 60655 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Mickey Petersen <mickey@HIDDEN> > The tree-sitter-enabled function, `treesit-transpose-sexps', that is called by transpose-sexps, is broken.
>
> It uses a naive method of sibling adjacency to determine
> transpositions. But it is unfortunately not correct.
>
> Python:
>
>
>   def -!-foo():
>       pass
>    
> Turns into this with `C-M-t':
>
>   def ()foo:
>       pass
>
> But it ought to be:
>
>   foo def():
>       pass
>
>
> It's swapping two siblings that are indeed adjacent in the tree, but
> not on screen, which is confusing and a regression from its previous
> behaviour.
>

I can try to make transpose-sexps rely on only swapping "allowed"
node-types?  That would be able to keep the new, better function, yet
still disallow these syntax-breaking transposes.  What do you think?

> You could make a cogent argument that both approaches are wrong from a
> syntactic perspective, but I think that misses the broader point that
> `C-M-t' now does something errant and unexpected.

I don't really see how "foo def():" is any better at all.  We gain some
great improvements with this "naive" method - namely:

if 5 + 5 == 10 then 10 else 100 + 100.  If point is on the else the 100
+ 100 wil be swapped by 10, but the old behavior will be broken. 

>
> Worse, it's not possible to revert to the old behaviour (see
> bug#60654)
>
>

Right.

Thanks,
Theo




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#60655; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 8 Jan 2023 10:53:48 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Jan 08 05:53:48 2023
Received: from localhost ([127.0.0.1]:59993 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1pETJE-00042H-8b
	for submit <at> debbugs.gnu.org; Sun, 08 Jan 2023 05:53:48 -0500
Received: from lists.gnu.org ([209.51.188.17]:53070)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <mickey@HIDDEN>) id 1pETJC-000429-BN
 for submit <at> debbugs.gnu.org; Sun, 08 Jan 2023 05:53:46 -0500
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 <mickey@HIDDEN>)
 id 1pETJC-0004e2-33
 for bug-gnu-emacs@HIDDEN; Sun, 08 Jan 2023 05:53:46 -0500
Received: from mail-cwlgbr01on2139.outbound.protection.outlook.com
 ([40.107.11.139] helo=GBR01-CWL-obe.outbound.protection.outlook.com)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <mickey@HIDDEN>)
 id 1pETJ6-00069r-J1
 for bug-gnu-emacs@HIDDEN; Sun, 08 Jan 2023 05:53:45 -0500
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
 b=Hj427ztQXYm+xTU81o0GJFSv4C1qz2G8JzirI7o+F0iB7RYhPIMQ8HLcUvIJUVpowbaegqud1PjfPjJ7oS+EM6ysFRgIwdGUuZ77AfYjhQYHscRgQ7HpPK12QFCNNowFD2+fz+wbABL1l7sY0h6GNTntthjOvNqzPUyCIMZvRj0JjHLIGzroPHCs6q8U7y4wU+JGzHat0FxTHXC6WbbquGI2IUr0Zanm88dWulI/GlFdo99/EKPKkMPLRHmttPQnECFAXBLmBWcDiHm71RNIX377swh/ycmhKPYchaVJ2ZAkkj764zqFKrmkMs2gkjJb94mDlYhTtGEzD/qLnyQhKA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; 
 s=arcselector9901;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;
 bh=ZZ+8dUst+aCSYYu26M8+ezdzwj7AFIoMoWq7Yk0rxM0=;
 b=bhL2fvfBNvfNQDlh8EcidR7570VcjJWD46CFcGs+9lJeOoHkb4GoV2OHSFzK/6oMt1A/0Kns/AT+4Dd8r1FgWZvag/XDifJZbmpFD8F9zMK9KP3Lm5Ex3ej+MWDhXc3F5nuXDU9BLBXKdVNITrfDD8lAfXWqKA4yv5vYmEJMhrPqtYqxpt34pRn4b9VVheBWA5lxpa8kGiAwymed8Dpsr1EWVOoEs4l3RcIqUeOPLVz9rP2h7Sq5Qn4lHQoBU9eUZW/1cEgNYQM3umPj+Q7L/9ssnlzEc/4WDTUryqMFF6RUDur8Gjzq5FhL15CmkXbIRyxa/g2hITLFkRnZFSVJ0Q==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is
 178.79.136.144) smtp.rcpttodomain=gnu.org smtp.mailfrom=masteringemacs.org;
 dmarc=pass (p=none sp=none pct=100) action=none
 header.from=masteringemacs.org; dkim=pass (signature was verified)
 header.d=masteringemacs.org; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=semantical.onmicrosoft.com; s=selector1-semantical-onmicrosoft-com;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=ZZ+8dUst+aCSYYu26M8+ezdzwj7AFIoMoWq7Yk0rxM0=;
 b=bDqTFmhfM+8RiNUfFCl+TzEEYGeowD5b8DFxFPYqdxDTmosTMQz0g98fHWm3RkQjPVz1f8xMgVzE4UCDzrghattycl/jv+nX+L449qALZWskfsnMfoOoHeAeBOOn0eo1DlhCRoY/GC68iqYyF0Lawmef/YZn2ycT1L7P16Tjb9A=
Received: from LO6P123CA0025.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:313::18)
 by LO4P265MB6252.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:27f::12)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Sun, 8 Jan
 2023 10:53:36 +0000
Received: from CWLGBR01FT035.eop-gbr01.prod.protection.outlook.com
 (2603:10a6:600:313:cafe::ab) by LO6P123CA0025.outlook.office365.com
 (2603:10a6:600:313::18) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18 via Frontend
 Transport; Sun, 8 Jan 2023 10:53:36 +0000
X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 178.79.136.144)
 smtp.mailfrom=masteringemacs.org; dkim=pass (signature was verified)
 header.d=masteringemacs.org;dmarc=pass action=none
 header.from=masteringemacs.org;
Received-SPF: Pass (protection.outlook.com: domain of masteringemacs.org
 designates 178.79.136.144 as permitted sender)
 receiver=protection.outlook.com; client-ip=178.79.136.144;
 helo=semantical.co.uk; pr=C
Received: from semantical.co.uk (178.79.136.144) by
 CWLGBR01FT035.mail.protection.outlook.com (10.152.40.163) with Microsoft SMTP
 Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.20.5966.17 via Frontend Transport; Sun, 8 Jan 2023 10:53:36 +0000
Received: by semantical.co.uk (Postfix, from userid 5001)
 id 99D8D114002; Sun,  8 Jan 2023 10:53:35 +0000 (GMT)
DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=masteringemacs.org;
 s=masteringemacs.org; t=1673175215;
 bh=JLQXXjFESZWQRpsB0zslI5WMkKM+85yk5SAcHgyDWqQ=;
 h=From:To:Subject:Date:From;
 b=ICoxkyrCMVewo2DANb7o+SNVfKIg1VOstEjc5s5cYOoBTI3xCTxeFvohjOlJtrpeE
 U8++ZburjzJLxWuJXzCnQDgmKIKGB8HWMMWzQ8Ygzt4xDCXsgFv1xd469w+2lGbIxa
 pQh5w5mHgQPgaxbI/+rA5n0OPuXQ2hj6+ccQFd0E=
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on semantical.co.uk
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NO_RECEIVED,
 NO_RELAYS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2
From: Mickey Petersen <mickey@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: 30.0.50; tree-sitter: `treesit-transpose-sexps' is broken.
Date: Sun, 08 Jan 2023 10:53:33 +0000
Message-ID: <87r0w5jo0i.fsf@HIDDEN>
Content-Type: text/plain
X-EOPAttributedMessage: 0
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: CWLGBR01FT035:EE_|LO4P265MB6252:EE_
MIME-Version: 1.0
X-MS-Office365-Filtering-Correlation-Id: c3532b31-297f-48ae-4688-08daf16697b5
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam: BCL:0;
X-Microsoft-Antispam-Message-Info: 9vwaoH2VDmltd4hzl6F0A05dvKGXFo97fAPQ7BTyIjDpq7UBbU1R2bS+DQU201nxMjtIiRaWCMDBC+Olq2jYe/C3uGC9xy6BLynnx8TudSfVsb8QD1Pt/D5sGmjZGElm3OYRUP21tDYUmZMAkog9qYDQ9NwHYdLSoKfywGrJH/rTvexE1b12cBbWxTk1/ydR2A4+ihGA5WUWhs7iPMikqRRU+yE+6ETu3vWqYGEIN5+LkXqYigMnaxsg+9KCJhRX1KIemSEqGoHUwi1qv4u2mfIosqPfROOvSmqiaWxGgWo9GSRDNosUXWmZGNTtaTaByUqu7SMoESMIakTXlpr+tVJTEdA5FBXep6qSjs9REXil50vJrTBySpiAKmJnFtpOuXeaOPeClh5Wug9s6FMcJXPRacEB1XwoiDMGPy3dzT8+PD3LC9W9iq8wUViJJ07W5maxK4t2QlKcbexKX/PvvRbxZkIRfHWaeuEcC5ksDYZPKxwQBa+2yE10LacS8ZN8O3Z95J234W/1vy6llShikPnhCIi3ZXmGIAUGoFnUSlaQt4QDRZNv/PXjgxt/6wbyxhAstdVM7vg8vRiHG0CwjarYzeWFlEVXalxj47qt6pJFzpsl8YH4weERNeKSuYHnur8vMsA4j9OIDgi3cu1fQ6RoKmn9bUjGuFraIp90hGE7H7R+LdzVePmuzFzzyzGBz4qWjVGJHgtyQ9E4At3nQ+KkXT7gOV+eds10vEOcYlcLKpE+b4NpvV9EY8REw0lIyYOa0mpffjPr9TlrJP7K4g==
X-Forefront-Antispam-Report: CIP:178.79.136.144; CTRY:GB; LANG:en; SCL:1; SRV:;
 IPV:NLI; SFV:NSPM; H:semantical.co.uk; PTR:semantical.co.uk; CAT:NONE;
 SFS:(13230022)(346002)(396003)(136003)(376002)(39830400003)(451199015)(36840700001)(46966006)(36860700001)(7596003)(7636003)(356005)(2906002)(478600001)(2616005)(186003)(6266002)(26005)(5660300002)(316002)(40480700001)(82310400005)(8936002)(36756003)(42186006)(86362001)(41300700001)(47076005)(336012)(8676002)(70586007)(70206006)(6916009)(38230200001)(81973001)(14776008)(79816003);
 DIR:OUT; SFP:1102; 
X-OriginatorOrg: masteringemacs.org
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jan 2023 10:53:36.0075 (UTC)
X-MS-Exchange-CrossTenant-Network-Message-Id: c3532b31-297f-48ae-4688-08daf16697b5
X-MS-Exchange-CrossTenant-Id: a4e27e3d-bab0-45e8-8942-e64cf9fbd34f
X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=a4e27e3d-bab0-45e8-8942-e64cf9fbd34f; Ip=[178.79.136.144];
 Helo=[semantical.co.uk]
X-MS-Exchange-CrossTenant-AuthSource: CWLGBR01FT035.eop-gbr01.prod.protection.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Anonymous
X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem
X-MS-Exchange-Transport-CrossTenantHeadersStamped: LO4P265MB6252
Received-SPF: pass client-ip=40.107.11.139;
 envelope-from=mickey@HIDDEN;
 helo=GBR01-CWL-obe.outbound.protection.outlook.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,
 RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -1.4 (-)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.4 (--)


The tree-sitter-enabled function, `treesit-transpose-sexps', that is called by transpose-sexps, is broken.

It uses a naive method of sibling adjacency to determine transpositions. But it is unfortunately not correct.

Python:


  def -!-foo():
      pass
   
Turns into this with `C-M-t':

  def ()foo:
      pass

But it ought to be:

  foo def():
      pass


It's swapping two siblings that are indeed adjacent in the tree, but not on screen, which is confusing and a regression from its previous behaviour. 

You could make a cogent argument that both approaches are wrong from a syntactic perspective, but I think that misses the broader point that `C-M-t' now does something errant and unexpected.

Worse, it's not possible to revert to the old behaviour (see bug#60654)



In GNU Emacs 30.0.50 (build 6, x86_64-pc-linux-gnu, GTK+ Version
 3.24.20, cairo version 1.16.0) of 2023-01-02 built on mickey-work
Repository revision: c209802f7b3721a1b95113290934a23fee88f678
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12013000
System Description: Ubuntu 20.04.3 LTS




Acknowledgement sent to Mickey Petersen <mickey@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#60655; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sun, 12 Jan 2025 05:45:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.