From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.bugs Subject: bug#60128: 30.0.50; [PATCH]: Add treesit-transpose-sexps Date: Mon, 26 Dec 2022 13:26:54 -0800 Message-ID: <0D9F1198-B5FB-451D-B0E8-DB22910DAB58@gmail.com> References: <87a63nru7n.fsf@thornhill.no> <87edsytcoh.fsf@thornhill.no> <873591honu.fsf@thornhill.no> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33383"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 60128@debbugs.gnu.org, eliz@gnu.org, Stefan Monnier To: Theodor Thornhill Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Dec 26 22:28:13 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p9v13-0008We-BJ for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 26 Dec 2022 22:28:13 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p9v0t-0000A5-Lz; Mon, 26 Dec 2022 16:28:03 -0500 Original-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 ) id 1p9v0s-00009w-FS for bug-gnu-emacs@gnu.org; Mon, 26 Dec 2022 16:28:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p9v0s-0002Bw-7Z for bug-gnu-emacs@gnu.org; Mon, 26 Dec 2022 16:28:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p9v0r-0002jE-Rb for bug-gnu-emacs@gnu.org; Mon, 26 Dec 2022 16:28:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 26 Dec 2022 21:28:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60128 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 60128-submit@debbugs.gnu.org id=B60128.167209002710401 (code B ref 60128); Mon, 26 Dec 2022 21:28:01 +0000 Original-Received: (at 60128) by debbugs.gnu.org; 26 Dec 2022 21:27:07 +0000 Original-Received: from localhost ([127.0.0.1]:54260 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p9uzz-0002hg-3Y for submit@debbugs.gnu.org; Mon, 26 Dec 2022 16:27:07 -0500 Original-Received: from mail-pj1-f42.google.com ([209.85.216.42]:40638) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p9uzu-0002h7-V2 for 60128@debbugs.gnu.org; Mon, 26 Dec 2022 16:27:05 -0500 Original-Received: by mail-pj1-f42.google.com with SMTP id c8-20020a17090a4d0800b00225c3614161so8445121pjg.5 for <60128@debbugs.gnu.org>; Mon, 26 Dec 2022 13:27:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=NAVMBJQpYm7cNEc4854yeykl1mCf0Io7FFJc7Cq7okI=; b=htCgzk7CsISnWzR8SP8qCBhouyxrvea/WAArZSCQwq7f66fJm7FfZChZDE95pnhsiI OWBkRfvYyeEu2bQkIsStJMJmJgSCc6I1e6RK88U3QeIeKz0hfd9M4nBjQgFfR4VLon4S wVBYLdqjUml5869nkOw9gcOAMl3g7nqQeqLtuGjfmTbQOVIVVIshwKh09Aif9LFL1sdh zw1wgIEw3a6mFbHX0i7xXzijjf6G99Wt3iXlPQ4AMJ5fdysMn55bAVNnAAQNKhSDAF+z zETouI47Av0TxQzLbnmumn6lcFvKGZbUjEjAclFv8hK61e7lGkuB6/SIVZw/uY/Sa+xX doNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NAVMBJQpYm7cNEc4854yeykl1mCf0Io7FFJc7Cq7okI=; b=nmLtF1UcGzFLDAssNefhxoNbSP2SjJkYpVVXe6lsEYaTPIF5oikJIMsJ36APLMJjFp 5GHp6LM0v1KhsGnK9UMvnJkBlrRX2099KD5UGzW3bL8pq9jjc0Vwra1KBzdyGlydm5Hs yVeHUzsSq9mQ5Bh6bI2DLmIV0243Rwk2omx2SXREECVk/fABgNGDvWZs+Fh1gWgifYjy z4NunfT05P2rZUvcPUB4EUF/mUPMKLr5tXzNerQ6dTtXzKF+eRGPnmBkxc/y7fwFdytB kwfXAjByXRs5mdL5OO4nOlLgM2qKXEQxL0dEoRa3cgO8c8rWYSoECNeFBeYj0NI/LqtW W3og== X-Gm-Message-State: AFqh2krKg8hfO3Sv/Nq9nX8DTqZ9iaQ2JXzdZn/jQhI5B3GOKmcSBNXh cZBdHZpROf2wT2Owost32TE= X-Google-Smtp-Source: AMrXdXtEAUua9QvVMDldq/9/0BOQieLGZ8+WCULO5CR90IiI0G866rvhVJh2P9JyeB9rfoD17MoVfw== X-Received: by 2002:a17:902:7584:b0:191:35c9:db30 with SMTP id j4-20020a170902758400b0019135c9db30mr19571753pll.5.1672090016975; Mon, 26 Dec 2022 13:26:56 -0800 (PST) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id l6-20020a170903120600b00190c6518e30sm7471478plh.243.2022.12.26.13.26.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Dec 2022 13:26:56 -0800 (PST) In-Reply-To: <873591honu.fsf@thornhill.no> X-Mailer: Apple Mail (2.3696.120.41.1.1) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:251917 Archived-At: > On Dec 26, 2022, at 12:53 PM, Theodor Thornhill = wrote: >=20 > Theodor Thornhill writes: >=20 >> Theodor Thornhill writes: >>=20 >>> Hi there! >>>=20 >>> Attached is a patch that enables transpose-sexps for tree-sitter = enabled >>> modes. >>>=20 >>> This function will swap the node _before_ node-at-point with the = node >>> _after_, so it would do something like: >>>=20 >>> foo a|nd bar =3D> bar and foo| >>>=20 >>> or >>> foo(a + 4,| y + c * b, b, d); =3D> foo(y + c * b, a + 4|, b, = d); >>>=20 >>> 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. >>>=20 >>=20 >> from 'transpose-subr-1': >>=20 >> (if (> (cdr pos1) (car pos2)) (error "Don't have two things to >> transpose")) >>=20 >> I added this hack into the function in the patch, but I think that >> triggering an error is too much. >>=20 >> ;; 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)))) >>=20 >> I guess I could just follow suit in my function and do like in the >> following patch: >>=20 >> Theo >=20 >=20 > 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? >=20 > What do you think about this patch? >=20 > (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... >=20 > 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. >=20 > Eli, does this require a NEWS entry or more documentation? IMHO a backend/helper function shouldn=E2=80=99t signal a user-error, = it=E2=80=99s better to return nil and let the command to signal errors. Yuan=