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#59662: 29.0.50; [PATCH] Add treesit--indent-defun Date: Wed, 7 Dec 2022 15:09:22 -0800 Message-ID: References: <87a63zyo4k.fsf@thornhill.no> <840EC1DB-C322-494D-96DA-5D9582E0C8C5@gmail.com> <6AD2610D-8A71-4F34-A8CC-119C2FB55C40@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="9362"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , 59662@debbugs.gnu.org, mardani29@yahoo.es To: Theodor Thornhill Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 08 00:10:29 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 1p33Ya-0002Dt-33 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 08 Dec 2022 00:10:28 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p33YC-0005BG-66; Wed, 07 Dec 2022 18:10:04 -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 1p33YA-0005B6-MX for bug-gnu-emacs@gnu.org; Wed, 07 Dec 2022 18:10: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 1p33YA-0002s8-DZ for bug-gnu-emacs@gnu.org; Wed, 07 Dec 2022 18:10:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p33YA-0004OW-2b for bug-gnu-emacs@gnu.org; Wed, 07 Dec 2022 18:10:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 07 Dec 2022 23:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59662 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 59662-submit@debbugs.gnu.org id=B59662.167045457616882 (code B ref 59662); Wed, 07 Dec 2022 23:10:02 +0000 Original-Received: (at 59662) by debbugs.gnu.org; 7 Dec 2022 23:09:36 +0000 Original-Received: from localhost ([127.0.0.1]:52728 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p33Xj-0004OE-Hv for submit@debbugs.gnu.org; Wed, 07 Dec 2022 18:09:35 -0500 Original-Received: from mail-pl1-f178.google.com ([209.85.214.178]:44861) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p33Xe-0004O5-QJ for 59662@debbugs.gnu.org; Wed, 07 Dec 2022 18:09:33 -0500 Original-Received: by mail-pl1-f178.google.com with SMTP id g10so18466320plo.11 for <59662@debbugs.gnu.org>; Wed, 07 Dec 2022 15:09:30 -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=XSmcx9Lb0XTSo1wpuDffC35awnMChdM+F02IFIDj24Y=; b=MrA8AKYkFElu59o9t2jKZ91GjW3ePz2AXl4hLZVXB/3x5LUNMCM748VP7VNeqbTBRY HO+FnM+ATR5JcPFRUF58qje15L3mQMRb/aRne0QWL6j8LlJ9s7v7cIOytXMyHOCmjLwH Q3qSnfex+EQmAZH+EsxUorCC3HMAEJKtQGe5Z0Fbb3THeqDumVix+IwwPWqUEi09FQ9t ICpdysNPU5SUoTcTj9ySwoIHtMJfjSbQvBO0haVtwA0VN1MhbxyNwu2IXinstIxu+EyT LdfRe6imUxxxAQsgQDuQ7ETewzIKZFkEzmMj/4EdsR/YH1MdGW40ahhOEKZ1r+RIsCdV DDeA== 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=XSmcx9Lb0XTSo1wpuDffC35awnMChdM+F02IFIDj24Y=; b=R9TmdonnQMZD/Up2LmTfMu4wXwcmkk+vRmjFx3BFWCv5oTAtKudr4cN03JUbg3vWe1 KuFuRMHjp3nyIyBKfRLd3L/PvPMKnPjD/z1KTAnFJO/yRUEpYd7WKbhh1TAaMZfz7IBn qKcOmCpvmcKW92emZ6hKdEa4WQtn7SbU0d6U35wSPO+ZQczSPVTdDp4cA9JOjsjKB1Tu VX1ch4d3wYeW2//HwXabOBiLCd6nzlTR94Bk3uwKt4vWvJGAukD+LOThkJ9nOwK6P261 K0AExvll+xHyVER6wc1eSfjq4oPVLCytMEnHe9Gb2BI3Ma+Y2Au/runxK15GY2zrt/zH M8pA== X-Gm-Message-State: ANoB5pmOjxcGzNnLbbGLkKQ26ftv7BAodkAVsCFo0OI7H7+UoV3mETuq Ud6zj10bDqrmbmZN7VSQxbg= X-Google-Smtp-Source: AA0mqf6wNqBqkb5CHCsTZ2DWnIKxeJGkmTQgR6TGsZrpeYybZ4eE2HDfPus+2s1QDihbl0tdxS1xIw== X-Received: by 2002:a05:6a20:9d92:b0:a3:c2a2:260f with SMTP id mu18-20020a056a209d9200b000a3c2a2260fmr1510599pzb.48.1670454564837; Wed, 07 Dec 2022 15:09:24 -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 h13-20020a65468d000000b00477f5ae26bbsm11959418pgr.50.2022.12.07.15.09.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Dec 2022 15:09:23 -0800 (PST) In-Reply-To: <6AD2610D-8A71-4F34-A8CC-119C2FB55C40@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:250224 Archived-At: > On Dec 7, 2022, at 1:53 PM, Theodor Thornhill = wrote: >=20 >=20 >=20 > On 7 December 2022 22:40:31 CET, Yuan Fu wrote: >>=20 >>=20 >>> On Dec 7, 2022, at 12:06 PM, Theodor Thornhill = wrote: >>>=20 >>> Yuan Fu writes: >>>=20 >>>> Theodor Thornhill writes: >>>>=20 >>>>> Eli Zaretskii writes: >>>>>=20 >>>>>>> From: Theodor Thornhill >>>>>>> Cc: "Theodor Thornhill via Bug reports for GNU Emacs, the Swiss = army knife >>>>>>> of text editors" , Eli Zaretskii = , >>>>>>> casouri@gmail.com, 59662@debbugs.gnu.org >>>>>>> Date: Sun, 04 Dec 2022 13:33:35 +0100 >>>>>>>=20 >>>>>>> Theodor Thornhill writes: >>>>>>>=20 >>>>>>>> On 2 December 2022 22:09:55 CET, "Daniel Mart=C3=ADn" = wrote: >>>>>>>>> Theodor Thornhill writes: >>>>>>>>>=20 >>>>>>>>>> Right - thanks. However, this makes me wonder - should we = really be >>>>>>>>>> setting mark here? I see that c-indent-defun does not, and it = feels >>>>>>>>>> weird that indenting adds to the mark ring. What do you = think? My >>>>>>>>>> first patch used >>>>>>>>>>=20 >>>>>>>>>> (indent-region >>>>>>>>>> (treesit-node-start node) >>>>>>>>>> (treesit-node-end node)) >>>>>>>>>>=20 >>>>>>>>>> Which behaves similarly to c-indent-defun. >>>>>>>>>>=20 >>>>>>>>>> See attached patch. >>>>>>>>>=20 >>>>>>>>> I don't have a strong opinion, but if we can indent without = setting the >>>>>>>>> mark, I think it'd be a cleaner command. Specially if = c-indent-defun >>>>>>>>> doesn't set the mark either. >>>>>>>>=20 >>>>>>>> Yeah, we don't need to set the mark. Thanks for the feedback :) >>>>>>>> Theo >>>>>>>=20 >>>>>>> Eli, do you have any opinion on this matter? Should we implement = this >>>>>>> function without using marks? That will make the function a = smidge >>>>>>> bigger, but would not mess up the mark-ring. I think that's = desirable, >>>>>>> at least. >>>>>>=20 >>>>>> IMO, it is better not to set the mark, indeed. >>>>>=20 >>>>> Agreed, see attached patch. What do you think, Yuan and Eli? >>>>>=20 >>>>> Should we expose the internal helper I used, or maybe this = function >>>>> could just as well live in treesit.c? >>>>>=20 >>>>> Theo >>>>>=20 >>>>=20 >>>> Very nice, I applied this patch with some changes to the function. = I >>>> think using treesit-beginning/end-of-defun is more robust. >>>>=20 >>>> Yuan >>>=20 >>> Thanks! Would you mind describing why? >>=20 >> Yes, sorry. I=E2=80=99m planning to change treesit-beginning-of-defun = and treesit-end-of-defun so they can behave differently according to = user configuration, basically they can decide whether to skip nested = defuns or not. If we use these functions rather than re-implementing = their logic (to some extent) in c-ts-mode-indent-defun, any improvement = to defun navigation would automatically benefit c-ts-mode-indent-defun. >>=20 >> Yuan >=20 > Thanks for explaining your rationale.=20 >=20 > By the way, there's an issue with the patch you applied: >=20 > void > foo() > { > ... > } >=20 > If point is at the v in void, the current implementation will not = reinvent. I didn't get time to debug yet, though. Possibly that will be = fixed after your rework as well. Ah, thanks, I=E2=80=99ll fix that. And I=E2=80=99ll ask for your opinion = before making changes next time, however innocent I thought the change = is :-) Yuan=