From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#59686: 30.0.50; tree-sitter indentation in some loops and conditional statements is wrong Date: Fri, 02 Dec 2022 12:51:14 +0100 Message-ID: <87v8munhvx.fsf@thornhill.no> References: <9F4F5716-F492-479A-869F-94D8A9391285@gmail.com> <83v8mufbd2.fsf@gnu.org> <86268d17-402f-6ae3-9ed7-100a2591e04d@isode.com> Reply-To: Theodor Thornhill Mime-Version: 1.0 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="23311"; mail-complaints-to="usenet@ciao.gmane.io" Cc: casouri@gmail.com, 59686@debbugs.gnu.org To: Bruce Stephens , Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Dec 02 12:52:22 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 1p14ac-0005kE-4F for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 02 Dec 2022 12:52:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p14aI-0000VT-Mn; Fri, 02 Dec 2022 06:52:02 -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 1p14aI-0000VF-19 for bug-gnu-emacs@gnu.org; Fri, 02 Dec 2022 06:52: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 1p14aH-0004vw-PB for bug-gnu-emacs@gnu.org; Fri, 02 Dec 2022 06:52:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p14aH-0008Jf-Jx for bug-gnu-emacs@gnu.org; Fri, 02 Dec 2022 06:52:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Theodor Thornhill Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 02 Dec 2022 11:52:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59686 X-GNU-PR-Package: emacs Original-Received: via spool by 59686-submit@debbugs.gnu.org id=B59686.166998188331928 (code B ref 59686); Fri, 02 Dec 2022 11:52:01 +0000 Original-Received: (at 59686) by debbugs.gnu.org; 2 Dec 2022 11:51:23 +0000 Original-Received: from localhost ([127.0.0.1]:46236 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p14Ze-0008Iu-I7 for submit@debbugs.gnu.org; Fri, 02 Dec 2022 06:51:22 -0500 Original-Received: from out-70.mta0.migadu.com ([91.218.175.70]:28824) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p14Zc-0008Io-Fc for 59686@debbugs.gnu.org; Fri, 02 Dec 2022 06:51:21 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1669981876; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O3jATdpKi1dmxkHcgjwA4Oc+8TohaUyGziDsu2afyJs=; b=h1f5MvxxmOgFJXbpeiLS6RinpCZTJmbcB9VHifbHiCqssUVxdfkkUzB36Lvo1znbdfkq2m 829Dnvpa6nudXbF2WyqYB5GHwkez9aZw0CudrshqwnVLupgFt5bFCFVDuPrKZw7ZMAWACF mtY09zJuTnyYMa3bTFI4DA64n/oQxmftpea9jPrV0z91Dk1908VJQZh48y5VGxusvuLT2S jE+G8serjdfwfURVF6y+GPE9ICgPY+QxkMF5DTSkxBVEfGS00EWlr0zV57qVJ+IQwAJNVn fBlUz1YEX29++il1zdpNVsxrdR+04y8VDdRH2uw+CQlKIlz7g/hu6hd5UuxkUw== In-Reply-To: <86268d17-402f-6ae3-9ed7-100a2591e04d@isode.com> X-Migadu-Flow: FLOW_OUT 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:249733 Archived-At: Bruce Stephens writes: > On 02/12/2022 08:39, Eli Zaretskii wrote: > >> FWIW, this is an unusual style, so I see no catastrophe if it is not 110% >> according to expectations. Users can easily fix that by tweaking their = BOLs >> where important. > > > The example I gave would be unusual, I think, but I'd argue that the=20 > situations where I saw the problem are quite natural. > > For example, > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 } else if ( MYSTRCMP (attname, SOME_PREFIX_X400ADDRESS) = || > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 MYSTRCMP (attname, SOME_PREFIX_X400) ) { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 FOO_ptr orp =3D foo_std2foo (val= ); > > or a function declaration with several arguments with types that are=20 > rather long. > > I agree it's not a critical bug but if there's no appropriate general=20 > fix it would be helpful to have some guidance for users to resolve our=20 > specific cases. This is the case I was thinking of. In the for-loop a grand-parent-bol on compound_statement rule would match the 'for' keyword, so the indentation will be correct, but this one will not, IIRC. I plan to dig into this some more soon, but motivation left me a little on that issue. Maybe we could make a preset like: ``` (seq (parent-is "compound_statement") parent (parent-is "for_statement") bol) ``` In other words, make other presets execute sequentially, move point, check again, and if all are true, pick indent offset. Or allow multiple captures, like so: ``` (for_statement @offset-anchor body: (compound_statement (_) @to-indent)) ``` Here the @to-indent capture would get the new indent level based on treesit-node-start of for_statement. What do you think, Yuan? Theo