GNU bug report logs -
#60128
30.0.50; [PATCH]: Add treesit-transpose-sexps
Previous Next
Reported by: Theodor Thornhill <theo <at> thornhill.no>
Date: Fri, 16 Dec 2022 20:05:01 UTC
Severity: wishlist
Tags: patch
Found in version 30.0.50
Done: Stefan Kangas <stefankangas <at> gmail.com>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Yuan Fu <casouri <at> gmail.com> writes:
>> On Dec 26, 2022, at 12:53 PM, Theodor Thornhill <theo <at> thornhill.no> wrote:
>>
>> Theodor Thornhill <theo <at> thornhill.no> writes:
>>
>>> Theodor Thornhill <theo <at> thornhill.no> writes:
>>>
>>>> Hi there!
>>>>
>>>> Attached is a patch that enables transpose-sexps for tree-sitter enabled
>>>> modes.
>>>>
>>>> This function will swap the node _before_ node-at-point with the node
>>>> _after_, so it would do something like:
>>>>
>>>> foo a|nd bar => bar and foo|
>>>>
>>>> or
>>>> foo(a + 4,| y + c * b, b, d); => foo(y + c * b, a + 4|, b, d);
>>>>
>>>> It will _not_ try to swap things that are not siblings. I think that
>>>> makes sense in the case of non-lisp languages, since _most_ places you
>>>> can transpose-sexps you will end up with broken code.
>>>>
>>>
>>> from 'transpose-subr-1':
>>>
>>> (if (> (cdr pos1) (car pos2)) (error "Don't have two things to
>>> transpose"))
>>>
>>> I added this hack into the function in the patch, but I think that
>>> triggering an error is too much.
>>>
>>> ;; Hack to trigger the error message in `transpose-subr-1' when we
>>> ;; don't have siblings to swap.
>>> (list (cons 0 1) (cons 0 1))))
>>>
>>> I guess I could just follow suit in my function and do like in the
>>> following patch:
>>>
>>> Theo
>>
>>
>> Considering there is both a bug-report _and_ a discussion around this I
>> guess the best idea is to add the patch to this bug report, and continue
>> discussing this in the report rather than emacs-devel?
>>
>> What do you think about this patch?
>>
>> (copied from emacs-devel):
>> It feels a little iffy how to handle the separate return values, but it
>> works. I'd be super happy for some feedback on how to best solve that,
>> though :)
>
> By separate return values, do you mean the function returns a cons of
> cons? It seems fine to me. Though I think the docstring could be more
> specific. Like saying return a cons (REGION . REGION), where REGION is
> (BEG . END), where BEG and END...
>
I updated the patch adressing your comment. The current "protocol" used
on the master branch implies that the regions are calculated by actually
moving inside the buffer and running (point). Because we don't need
that with the ast in hand I'm trying to support a new protocol, where we
just supply the data we need. It's a little difficult to "surgically"
modify the behavior, so I'm very open to suggestions, but I believe it
should work properly as the patch stands.
>>
>> Also, I made the treesit-transpose-sexps a little better imo, in that we
>> only find named nodes to swap, but use every available node for the
>> entry. We rarely, if ever want to swap the unnamed nodes.
>>
>> Eli, does this require a NEWS entry or more documentation?
>
> IMHO a backend/helper function shouldn’t signal a user-error, it’s
> better to return nil and let the command to signal errors.
Yeah, I agree. Adjusted the patch. Let me know what you think!
Theo
[0001-Add-treesit-transpose-sexps-bug-60128.patch (text/x-diff, attachment)]
This bug report was last modified 1 year and 256 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.