all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Yuan Fu <casouri@gmail.com>
To: Theodor Thornhill <theo@thornhill.no>
Cc: 60128@debbugs.gnu.org, eliz@gnu.org,
	Stefan Monnier <monnier@iro.umontreal.ca>
Subject: bug#60128: 30.0.50; [PATCH]: Add treesit-transpose-sexps
Date: Mon, 26 Dec 2022 13:26:54 -0800	[thread overview]
Message-ID: <0D9F1198-B5FB-451D-B0E8-DB22910DAB58@gmail.com> (raw)
In-Reply-To: <873591honu.fsf@thornhill.no>



> On Dec 26, 2022, at 12:53 PM, Theodor Thornhill <theo@thornhill.no> wrote:
> 
> Theodor Thornhill <theo@thornhill.no> writes:
> 
>> Theodor Thornhill <theo@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




  reply	other threads:[~2022-12-26 21:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-16 20:04 bug#60128: 30.0.50; [PATCH]: Add treesit-transpose-sexps Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-17 12:52 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-26 20:53   ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-26 21:26     ` Yuan Fu [this message]
2022-12-26 22:37       ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-27 11:56     ` Eli Zaretskii
2023-01-07 23:18 ` Yuan Fu
2023-01-08 11:56   ` Eli Zaretskii
2023-01-08 12:13     ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-05 15:56       ` Stefan Kangas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0D9F1198-B5FB-451D-B0E8-DB22910DAB58@gmail.com \
    --to=casouri@gmail.com \
    --cc=60128@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=theo@thornhill.no \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.