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.devel Subject: Re: Can this indentation be achieved with treesit-simple-indent-rules? Date: Tue, 20 Jun 2023 14:53:06 -0700 Message-ID: <3C273F81-DC88-453B-8BE8-B157BA092E47@gmail.com> References: <7014cdc3-d86a-8c7c-138b-ab9edd447ae1@gutov.dev> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.600.7\)) 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="10461"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Dmitry Gutov , emacs-devel@gnu.org To: =?utf-8?Q?Nicol=C3=A1s_Ojeda_B=C3=A4r?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Jun 20 23:54:26 2023 Return-path: Envelope-to: ged-emacs-devel@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 1qBjIw-0002YO-3m for ged-emacs-devel@m.gmane-mx.org; Tue, 20 Jun 2023 23:54:26 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qBjHx-0002kN-2U; Tue, 20 Jun 2023 17:53:25 -0400 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 1qBjHv-0002kB-Cc for emacs-devel@gnu.org; Tue, 20 Jun 2023 17:53:23 -0400 Original-Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBjHt-0006cK-NW for emacs-devel@gnu.org; Tue, 20 Jun 2023 17:53:23 -0400 Original-Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1b512309c86so34654325ad.1 for ; Tue, 20 Jun 2023 14:53:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687298000; x=1689890000; 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=TDV67/W7h9eQypi91SIn6/HNa45bNaADF26N2fHCmjU=; b=FqR2ss2Rm/hTK3+Z6OK4ysOED9LWtXzMB0z3We+4JeClskXHtijTfiVY3AslDc+RFb /kPeEjdNS1utAzP1PgEWzlcbMoImdQegk84py1v/FX8JcnT4SWHO93UFJ1U6Aw2ep3p8 LAb9+/N9+QSWv89O2nOq8ezlPOyFSH/gsvikKL4bD2LspXfvhRZ7N+IeAOya2lqKhxFA R0LHuUe3pl5tVPZ2r8j/Gv1hs7eEpw3H4sK3FE6o9PJupF1Z76MfPx/Flk0mLWjtFyUy CnQrI7t3oZ0cnwQC3L2mAeq9q/GgDb2XhozjgugsCMyrgvRaQMjyOIYwG3IA+Xd3IDux g2eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687298000; x=1689890000; 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=TDV67/W7h9eQypi91SIn6/HNa45bNaADF26N2fHCmjU=; b=fNrLQAdPA98kNg95sv8SmksGPayTCoLA64Fy0/D8O1s9Q/1Qxu7ixNqH1IzfUqJzZy PfIfMUINAWP9KVN6Ub6KrW9Qn7xjnJQsG9JQdcUfjxoezbGoFHtc5n4fb0jBGyh5Dfwh iZlP7lFgUB9UfwuewN+lyvj9dSr9+U7oMs5S5zve23JoWqIcNZFUEvavz4EVXwje/41/ sIxICJYkBoeefLojsV71AgnJ8RchGaVYHQQ2pKFkTilUaQIaM7vKfXIZSEJ6deH09V89 URZrGn9jvsCx+ExnyGxfH7RuxystGQ6H8Vttc7m+QkX41pV3U8fwNB1C1u9hgwKff00g T05A== X-Gm-Message-State: AC+VfDwf+o0bCdcfqGu8Sfgyi3+slLr73DOau6JITYu/AckxvoGB48P3 7hYPP6SlfNQl9K5PYXRjYsw= X-Google-Smtp-Source: ACHHUZ6aZ35XVXaZcKFZ2x+MBXnJdS41Qv5WoomFTIrFLenmdkV9VBUOreHg1apj4W6V9x3agOCb7w== X-Received: by 2002:a17:902:c40d:b0:1ac:6fc3:6beb with SMTP id k13-20020a170902c40d00b001ac6fc36bebmr22854479plk.9.1687297999508; Tue, 20 Jun 2023 14:53:19 -0700 (PDT) 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 4-20020a170902ee4400b001b531e8a000sm2055592plo.157.2023.06.20.14.53.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Jun 2023 14:53:19 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.3731.600.7) Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=casouri@gmail.com; helo=mail-pl1-x632.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:307099 Archived-At: > On Jun 20, 2023, at 9:16 AM, Nicol=C3=A1s Ojeda B=C3=A4r = wrote: >=20 > On Tue, Jun 20, 2023 at 5:34=E2=80=AFPM Dmitry Gutov = wrote: >>=20 >> On 19/06/2023 22:11, Nicol=C3=A1s Ojeda B=C3=A4r wrote: >>> ((parent-is "b") parent-bol 0) >>=20 >> Try 'parent' instead of 'parent-bol'. >=20 > Hello, >=20 > Thanks for the suggestion. >=20 > That would work in the "abstract" example because "a" is of width 1, > but would not work in general. You can see it clearly if we use "aaa", > "bbb" and "ccc" instead of "a", "b", "c": starting from the correctly > indented >=20 > aaa > bbb > ccc >=20 > if we put "bbb" in the same line as "aaa" we will get (using parent > instead of parent-bol) >=20 > aaa bbb > ccc >=20 > but would like to get >=20 > aaa bbb > ccc >=20 > In the concrete example in OCaml I mentioned in a previous reply, = starting from >=20 > let x =3D > match e with > | Foo -> 0 >=20 > if I put the "match" in the same line as the "let" (using parent > instead of parent-bol) I will get >=20 > let x =3D match e with > | Foo -> 0 >=20 > but would like to get instead >=20 > let x =3D match e with > | Foo -> 0 >=20 > Do let me know if anything is still unclear. Thanks for the context. So the logic is =E2=80=9Cthe value of a let =3D = VALUE should have a base indentation of +1 level=E2=80=9D. Maybe you can = add a rule that matches =E2=80=9Cthe line below a let=E2=80=9D, make it = take precedence over other rules. Come to think about it, the indent logic of OCaml seems to be determined = by the previous line: let P be the node at the BOL of the previous line, = and N be the node at the BOL of the current line, if P is some sort of a = sibling of N, they indent the same amount; if P is some sort of = (grand)parent of N, the current line indents one level more. Sans = exceptions like the match arms and the body of a =E2=80=9Clet x =3D y in = body=E2=80=9D, IIRC. Following this line of thought, maybe you can have rules for the = exceptions, followed by two generic rules for the two cases, rather than = writing explicit rules for every scenario? Yuan=