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#59686: 30.0.50; tree-sitter indentation in some loops and conditional statements is wrong Date: Sat, 3 Dec 2022 03:19:45 -0800 Message-ID: <2DADEBEF-A7CD-45C6-9B2B-1B766D14788E@gmail.com> References: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22043"; mail-complaints-to="usenet@ciao.gmane.io" Cc: bruce.stephens@isode.com, Eli Zaretskii , 59686@debbugs.gnu.org To: Theodor Thornhill Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 03 12:20:26 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 1p1QZF-0005Ue-Th for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 03 Dec 2022 12:20:26 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p1QYu-00019l-DQ; Sat, 03 Dec 2022 06:20: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 1p1QYs-00019Q-W5 for bug-gnu-emacs@gnu.org; Sat, 03 Dec 2022 06:20:03 -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 1p1QYs-0005DJ-Kc for bug-gnu-emacs@gnu.org; Sat, 03 Dec 2022 06:20:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p1QYs-0008B0-34 for bug-gnu-emacs@gnu.org; Sat, 03 Dec 2022 06:20: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: Sat, 03 Dec 2022 11:20:02 +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.167006639831420 (code B ref 59686); Sat, 03 Dec 2022 11:20:02 +0000 Original-Received: (at 59686) by debbugs.gnu.org; 3 Dec 2022 11:19:58 +0000 Original-Received: from localhost ([127.0.0.1]:51585 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p1QYn-0008Ai-UU for submit@debbugs.gnu.org; Sat, 03 Dec 2022 06:19:58 -0500 Original-Received: from mail-pg1-f182.google.com ([209.85.215.182]:45707) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p1QYi-0008Aa-TX for 59686@debbugs.gnu.org; Sat, 03 Dec 2022 06:19:56 -0500 Original-Received: by mail-pg1-f182.google.com with SMTP id r18so6439328pgr.12 for <59686@debbugs.gnu.org>; Sat, 03 Dec 2022 03:19:52 -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=4NjYztyLW9VszXoMt45vMju+KI4vYzF66AczmQQ1MYc=; b=XVLgqKdfiV6L/aaJzsmBgZFLpHC7aVkr5UKaO3otaiyDiN+hfKNDTZmeFydNzl1onZ Rk4BB2PfzPYftRvV5FytywSL/e8gZE9aUkDdprI/fc2A2YqUmOUaV6EZVgj3+DZNiOfI gzonH/aFcFXQUNaYdvGC1YbsiVf1nYKFIeusU7L5AUuknOW89KHvySUpIKuKNsaGYQci 3gMo69kIMiBOWGRVYCb45effgZ1O4rN9V1Y7T7Wy25cPGbnPqgMd46/AO7OJCgbYuyH5 kpeWi4cTRMym90ddewTtUyj6BnaFAbbv90bf3rHAf/FpKhN0KWVuAvOe2NcyGDDw0Yx9 9bLg== 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=4NjYztyLW9VszXoMt45vMju+KI4vYzF66AczmQQ1MYc=; b=rO1BySgeArPFviEhadxzJyBmAdXuaMA1cNWnY30NNRlJAlVnMOe5bAlevkCN2REC3e XOTGXBRemiMj5fvcswYOqgC9KWMnMp41DzctKPuFlPniDw+TP6tGPDhwZoh5tEDp1gcx z9nZTwPt10jm10+rOubiybpGKTmJOcTaAzAWhdQd2vb9HyIRDvoA70vZ9tg6z1+/bSZe /R6yOsNSDTWCxjpGruk1r1o1uFiIEx5lK40NLMIMKQ0St4l/4yXITfEE4TTZUpEDZ6Q4 elABmfUNGT35ztV4hB7Wjx+FEIW4kuYAp5KaJMjnOKlp1aKBKFb6pyqOW7uvTwJzmKhE mNFw== X-Gm-Message-State: ANoB5pl0xmDiTTg7uin8PsIRYuk2nDdZ0ykvApHaKVkR2wks7hxVQlya 02105gAfV78NP+9DNiZne94= X-Google-Smtp-Source: AA0mqf4WC4DaMhPGXw41by7PlKVxfeCFLZYiC/FUDG8tOH+fFypswe2BJH2xSLbLMCIsIutLesmxFQ== X-Received: by 2002:a63:5146:0:b0:477:86c1:640f with SMTP id r6-20020a635146000000b0047786c1640fmr49508770pgl.231.1670066386879; Sat, 03 Dec 2022 03:19:46 -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 e1-20020a621e01000000b0057621a437d7sm4583487pfe.116.2022.12.03.03.19.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Dec 2022 03:19:46 -0800 (PST) In-Reply-To: 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:249827 Archived-At: > On Dec 3, 2022, at 3:08 AM, Theodor Thornhill = wrote: >=20 >=20 >=20 > On 3 December 2022 11:48:34 CET, Yuan Fu wrote: >>=20 >> Theodor Thornhill writes: >>=20 >>> Bruce Stephens writes: >>>=20 >>>> On 02/12/2022 08:39, Eli Zaretskii wrote: >>>>=20 >>>>> 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. >>>>=20 >>>>=20 >>>> The example I gave would be unusual, I think, but I'd argue that = the >>>> situations where I saw the problem are quite natural. >>>>=20 >>>> For example, >>>>=20 >>>> } else if ( MYSTRCMP (attname, = SOME_PREFIX_X400ADDRESS) || >>>> MYSTRCMP (attname, SOME_PREFIX_X400) ) = { >>>> FOO_ptr orp =3D foo_std2foo (val); >>>>=20 >>>> or a function declaration with several arguments with types that = are >>>> rather long. >>>>=20 >>>> 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. >>>=20 >>> 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: >>>=20 >>> ``` >>> (seq >>> (parent-is "compound_statement") parent (parent-is "for_statement") = bol) >>> ``` >>>=20 >>>=20 >>> 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: >>>=20 >>> ``` >>> (for_statement @offset-anchor >>> body: (compound_statement (_) @to-indent)) >>> ``` >>>=20 >>> Here the @to-indent capture would get the new indent level based on >>> treesit-node-start of for_statement. >>>=20 >>> What do you think, Yuan? >>=20 >> I think we can just test for the grandparent, there is an >> (undocumented) matcher n-p-gp which matches parent and grandparent. >>=20 >> Yuan >=20 > Yeah I know, but that doesn't work in every case we see this behavior. I see, but at least it fixes common cases that I can think of right now, = namely if, for, while. What are some other cases? Yuan