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.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 60128 in the body.
You can then email your comments to 60128 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
casouri <at> gmail.com, monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org
:
bug#60128
; Package
emacs
.
(Fri, 16 Dec 2022 20:05:01 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Theodor Thornhill <theo <at> thornhill.no>
:
New bug report received and forwarded. Copy sent to
casouri <at> gmail.com, monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org
.
(Fri, 16 Dec 2022 20:05:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
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.
What do you think? I think this makes sense on the master branch, not
release.
Theo
[0001-Add-treesit-transpose-sexps.patch (text/x-diff, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#60128
; Package
emacs
.
(Sat, 17 Dec 2022 12:53:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 60128 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
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
[0001-Add-treesit-transpose-sexps.patch (text/x-diff, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#60128
; Package
emacs
.
(Mon, 26 Dec 2022 20:55:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 60128 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
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 :)
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?
Theo
[0001-Add-treesit-transpose-sexps-bug-60128.patch (text/x-diff, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#60128
; Package
emacs
.
(Mon, 26 Dec 2022 21:28:01 GMT)
Full text and
rfc822 format available.
Message #14 received at 60128 <at> debbugs.gnu.org (full text, mbox):
> 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...
>
> 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.
Yuan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#60128
; Package
emacs
.
(Mon, 26 Dec 2022 22:38:01 GMT)
Full text and
rfc822 format available.
Message #17 received at 60128 <at> debbugs.gnu.org (full text, mbox):
[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)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#60128
; Package
emacs
.
(Tue, 27 Dec 2022 11:57:02 GMT)
Full text and
rfc822 format available.
Message #20 received at 60128 <at> debbugs.gnu.org (full text, mbox):
> From: Theodor Thornhill <theo <at> thornhill.no>
> Cc: casouri <at> gmail.com, Stefan Monnier <monnier <at> iro.umontreal.ca>, eliz <at> gnu.org
> Date: Mon, 26 Dec 2022 21:53:57 +0100
>
> Eli, does this require a NEWS entry or more documentation?
A NEWS entry should be enough.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#60128
; Package
emacs
.
(Sat, 07 Jan 2023 23:19:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 60128 <at> debbugs.gnu.org (full text, mbox):
Eli Zaretskii <eliz <at> gnu.org> writes:
>> From: Theodor Thornhill <theo <at> thornhill.no>
>> Cc: casouri <at> gmail.com, Stefan Monnier <monnier <at> iro.umontreal.ca>, eliz <at> gnu.org
>> Date: Mon, 26 Dec 2022 21:53:57 +0100
>>
>> Eli, does this require a NEWS entry or more documentation?
>
> A NEWS entry should be enough.
IIRC this is pushed to master right? If so I’ll close this.
Yuan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#60128
; Package
emacs
.
(Sun, 08 Jan 2023 11:57:01 GMT)
Full text and
rfc822 format available.
Message #26 received at 60128 <at> debbugs.gnu.org (full text, mbox):
> From: Yuan Fu <casouri <at> gmail.com>
> Date: Sat, 7 Jan 2023 15:18:17 -0800
> Cc: Theodor Thornhill <theo <at> thornhill.no>,
> 60128 <at> debbugs.gnu.org,
> monnier <at> iro.umontreal.ca
>
>
> Eli Zaretskii <eliz <at> gnu.org> writes:
>
> >> From: Theodor Thornhill <theo <at> thornhill.no>
> >> Cc: casouri <at> gmail.com, Stefan Monnier <monnier <at> iro.umontreal.ca>, eliz <at> gnu.org
> >> Date: Mon, 26 Dec 2022 21:53:57 +0100
> >>
> >> Eli, does this require a NEWS entry or more documentation?
> >
> > A NEWS entry should be enough.
>
> IIRC this is pushed to master right?
I don't see it there, no.
I asked to add a NEWS entry, and then it can be installed on master.
Theo?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#60128
; Package
emacs
.
(Sun, 08 Jan 2023 12:14:02 GMT)
Full text and
rfc822 format available.
Message #29 received at 60128 <at> debbugs.gnu.org (full text, mbox):
Eli Zaretskii <eliz <at> gnu.org> writes:
>> From: Yuan Fu <casouri <at> gmail.com>
>> Date: Sat, 7 Jan 2023 15:18:17 -0800
>> Cc: Theodor Thornhill <theo <at> thornhill.no>,
>> 60128 <at> debbugs.gnu.org,
>> monnier <at> iro.umontreal.ca
>>
>>
>> Eli Zaretskii <eliz <at> gnu.org> writes:
>>
>> >> From: Theodor Thornhill <theo <at> thornhill.no>
>> >> Cc: casouri <at> gmail.com, Stefan Monnier <monnier <at> iro.umontreal.ca>, eliz <at> gnu.org
>> >> Date: Mon, 26 Dec 2022 21:53:57 +0100
>> >>
>> >> Eli, does this require a NEWS entry or more documentation?
>> >
>> > A NEWS entry should be enough.
>>
>> IIRC this is pushed to master right?
>
> I don't see it there, no.
>
> I asked to add a NEWS entry, and then it can be installed on master.
>
> Theo?
Yeah, it was added in 7e98b8a0fa67f51784024fac3199d774dfa77192 and
commited by Stefan :-)
Should I add anything else?
Theo
Severity set to 'wishlist' from 'normal'
Request was from
Stefan Kangas <stefankangas <at> gmail.com>
to
control <at> debbugs.gnu.org
.
(Mon, 04 Sep 2023 15:14:01 GMT)
Full text and
rfc822 format available.
Reply sent
to
Stefan Kangas <stefankangas <at> gmail.com>
:
You have taken responsibility.
(Tue, 05 Sep 2023 15:57:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Theodor Thornhill <theo <at> thornhill.no>
:
bug acknowledged by developer.
(Tue, 05 Sep 2023 15:57:02 GMT)
Full text and
rfc822 format available.
Message #36 received at 60128-done <at> debbugs.gnu.org (full text, mbox):
Theodor Thornhill <theo <at> thornhill.no> writes:
> Eli Zaretskii <eliz <at> gnu.org> writes:
>
>>> From: Yuan Fu <casouri <at> gmail.com>
>>> Date: Sat, 7 Jan 2023 15:18:17 -0800
>>> Cc: Theodor Thornhill <theo <at> thornhill.no>,
>>> 60128 <at> debbugs.gnu.org,
>>> monnier <at> iro.umontreal.ca
>>>
>>>
>>> Eli Zaretskii <eliz <at> gnu.org> writes:
>>>
>>> >> From: Theodor Thornhill <theo <at> thornhill.no>
>>> >> Cc: casouri <at> gmail.com, Stefan Monnier <monnier <at> iro.umontreal.ca>, eliz <at> gnu.org
>>> >> Date: Mon, 26 Dec 2022 21:53:57 +0100
>>> >>
>>> >> Eli, does this require a NEWS entry or more documentation?
>>> >
>>> > A NEWS entry should be enough.
>>>
>>> IIRC this is pushed to master right?
>>
>> I don't see it there, no.
>>
>> I asked to add a NEWS entry, and then it can be installed on master.
>>
>> Theo?
>
> Yeah, it was added in 7e98b8a0fa67f51784024fac3199d774dfa77192 and
> commited by Stefan :-)
>
> Should I add anything else?
>
> Theo
It seems like this bug is done, as the patch was committed. Closing.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Wed, 04 Oct 2023 11:24:15 GMT)
Full text and
rfc822 format available.
This bug report was last modified 1 year and 219 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.