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

From: Mickey Petersen <[email-masked]>
Date: Sun, 08 Jan 2023 10:53:33 +0000

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