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 02:48:34 -0800 Message-ID: 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="34498"; 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 11:49: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 1p1Q5F-0008mr-Nh for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 03 Dec 2022 11:49:25 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p1Q4t-0004us-KX; Sat, 03 Dec 2022 05:49: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 1p1Q4s-0004ue-4w for bug-gnu-emacs@gnu.org; Sat, 03 Dec 2022 05:49: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 1p1Q4r-00066B-TT for bug-gnu-emacs@gnu.org; Sat, 03 Dec 2022 05:49:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p1Q4r-0007vc-Pe for bug-gnu-emacs@gnu.org; Sat, 03 Dec 2022 05:49:01 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 03 Dec 2022 10:49: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.167006452530463 (code B ref 59686); Sat, 03 Dec 2022 10:49:01 +0000 Original-Received: (at 59686) by debbugs.gnu.org; 3 Dec 2022 10:48:45 +0000 Original-Received: from localhost ([127.0.0.1]:51562 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p1Q4a-0007vH-MM for submit@debbugs.gnu.org; Sat, 03 Dec 2022 05:48:45 -0500 Original-Received: from mail-pj1-f45.google.com ([209.85.216.45]:41514) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p1Q4Y-0007vB-Px for 59686@debbugs.gnu.org; Sat, 03 Dec 2022 05:48:43 -0500 Original-Received: by mail-pj1-f45.google.com with SMTP id w15-20020a17090a380f00b0021873113cb4so7313679pjb.0 for <59686@debbugs.gnu.org>; Sat, 03 Dec 2022 02:48:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:from:to:cc:subject:date:message-id :reply-to; bh=m/ouI0A6hYaCxA8eEvt7q6Dx1AcJNkzUnYu1A06D714=; b=ab3L+TFX8nh+3ebOyCb0h9l+nzQXTrDm7Yty89ro9Karg095TI+pltDpXWn1Eii2Jj SFNiAbRTlCc5ZwquiZIRnhyl0u6pAFuj78e8sWsuUuA0NTyZRJtVteL8Fz0yv3L14Fcc CUxa+aJW3dxxnOIGQ1hTz8+0dB6Zek5DylM7xJW9XGM+Bl8xZ5vsF4KQkRCm6bAwbwTr uPAy+p12zPSu6NcruJckUW8meohL0UzdjPy/f4xTaw/WWTKIVdR3OtjwsqTMOR4X/KQK yhZRkP3zaTdR/n3fNV5U9U7JAARzsr197+urg1a0tD2DXrAA9dfwUHvu8pBw5CdwTUAK Wt9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=m/ouI0A6hYaCxA8eEvt7q6Dx1AcJNkzUnYu1A06D714=; b=z7f7jU501jOhEj6k+j17KWqfrj6azIbgNSjTorBkLoosNvGrNe7Y8jTQc/fkynqAXc hL9NqOvaeX1U8uvG1eolglAv6E6jWY6t1U2vmyrzv1s1KlKEZvfnWlpzZC26HABYH0JH 3X8ya4XmuU2y4UWzFic+T12Q3uZbTsPo5Vgz5W5qt2ARgqKhHp6JSSQMNdLVWV9Y4HJY O1d9sKYbDVO9fWG/MQlN68DUbTSmzDUU0aFz1u+t6y+DNrXHH1/9mReZpdA7VJ/q7tn9 2NcZTxMJReAmIlzWGTMiXXtBj7BczbE7ECfojDPGZVGvAytDjTLiZgNgN1BxwL9Q8Tcj M0Ag== X-Gm-Message-State: ANoB5pnHfdvTf9TrynYXNLsuaQLug1lvwMn5Y/tuQMf5U8avHKINw5C/ S7Zrf58oi1SKfK5aEOrm2tQ= X-Google-Smtp-Source: AA0mqf7iebrJIGic7u0JLGecy+7O7vFt9dOC98WYlOF/m6jydfeS2nbLo/xZrLgWIILOer7gMS9BcA== X-Received: by 2002:a17:90a:94c3:b0:219:e20:9bf7 with SMTP id j3-20020a17090a94c300b002190e209bf7mr41142760pjw.61.1670064517030; Sat, 03 Dec 2022 02:48:37 -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 t68-20020a625f47000000b0056bbd286cf4sm6486920pfb.167.2022.12.03.02.48.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Dec 2022 02:48:36 -0800 (PST) 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:249824 Archived-At: 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. 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 >> situations where I saw the problem are quite natural. >> >> For example, >> >> } else if ( MYSTRCMP (attname, = SOME_PREFIX_X400ADDRESS) || >> 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. >> >> 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. > > 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? I think we can just test for the grandparent, there is an (undocumented) matcher n-p-gp which matches parent and grandparent. Yuan