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: Sat, 03 Dec 2022 12:08:59 +0100 Message-ID: References: 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="15166"; mail-complaints-to="usenet@ciao.gmane.io" Cc: bruce.stephens@isode.com, Eli Zaretskii , 59686@debbugs.gnu.org To: Yuan Fu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 03 12:10:21 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 1p1QPU-0003li-HG for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 03 Dec 2022 12:10:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p1QPD-0008O9-U0; Sat, 03 Dec 2022 06:10: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 1p1QPC-0008Nv-IS for bug-gnu-emacs@gnu.org; Sat, 03 Dec 2022 06: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 1p1QPC-0007sR-7I for bug-gnu-emacs@gnu.org; Sat, 03 Dec 2022 06:10:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p1QPB-00086I-SP for bug-gnu-emacs@gnu.org; Sat, 03 Dec 2022 06:10: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: Sat, 03 Dec 2022 11:10: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.167006578231128 (code B ref 59686); Sat, 03 Dec 2022 11:10:01 +0000 Original-Received: (at 59686) by debbugs.gnu.org; 3 Dec 2022 11:09:42 +0000 Original-Received: from localhost ([127.0.0.1]:51580 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p1QOr-000860-NF for submit@debbugs.gnu.org; Sat, 03 Dec 2022 06:09:42 -0500 Original-Received: from out-18.mta0.migadu.com ([91.218.175.18]:37127) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p1QOp-00085u-VV for 59686@debbugs.gnu.org; Sat, 03 Dec 2022 06:09:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1670065778; 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=3crI0PuhEwOb2adRJsEri4TJhJQ5E/Ri3eIHqu0g3AM=; b=Lkwx1WwwH69xLLdxjlHd6TxiSPXgj3JzkS7egcGeQCzxwDXjVAmnnxtZUlzIp7xIZ/hOUv fkzFluYXM3yMZp/eqwV5jKIeGNLHEr94V1OuYnuuzfABFJqn57xuVscHAZTp9l9GiQtl59 NE9gVjBj0v+ZGYJCzi5R4GewDYTtoRu9D36vVwkIynagJjmJ5hTuXByKqDAuQYzb/rx6/X h4CwjuunwLNgDtqHwzAacmAlb/KxgC9wWtxfM3vloODzqpf2n+L0Jx2NHOBy2jhn1g6X7e xyGU6ayxxLvD+GnC80+5xi50vkCnt4YRHQJqZwH2Fy262CG/UxwpKXk+TUNjVA== X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. In-Reply-To: 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:249826 Archived-At: On 3 December 2022 11:48:34 CET, Yuan Fu wrote: > >Theodor Thornhill writes: > >> 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=2E Users can easily fix that by tweaking t= heir BOLs >>>> where important=2E >>> >>> >>> The example I gave would be unusual, I think, but I'd argue that the >>> situations where I saw the problem are quite natural=2E >>> >>> For example, >>> >>> } else if ( MYSTRCMP (attname, SOME_PREFIX_X400ADDRES= S) || >>> MYSTRCMP (attname, SOME_PREFIX_X400) ) { >>> FOO_ptr orp =3D foo_std2foo (val); >>> >>> or a function declaration with several arguments with types that are >>> rather long=2E >>> >>> I agree it's not a critical bug but if there's no appropriate general >>> fix it would be helpful to have some guidance for users to resolve our >>> specific cases=2E >> >> This is the case I was thinking of=2E In the for-loop a grand-parent-b= ol >> on compound_statement rule would match the 'for' keyword, so the >> indentation will be correct, but this one will not, IIRC=2E I plan to = dig >> into this some more soon, but motivation left me a little on that issue= =2E >> Maybe we could make a preset like: >> >> ``` >> (seq >> (parent-is "compound_statement") parent (parent-is "for_statement") bo= l) >> ``` >> >> >> In other words, make other presets execute sequentially, move point, >> check again, and if all are true, pick indent offset=2E Or allow multi= ple >> 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=2E >> >> What do you think, Yuan? > >I think we can just test for the grandparent, there is an >(undocumented) matcher n-p-gp which matches parent and grandparent=2E > >Yuan Yeah I know, but that doesn't work in every case we see this behavior=2E