From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Nicol=C3=A1s_Ojeda_B=C3=A4r?= Newsgroups: gmane.emacs.devel Subject: Re: Can this indentation be achieved with treesit-simple-indent-rules? Date: Tue, 20 Jun 2023 12:16:46 +0200 Message-ID: References: <1527B47A-3A4B-4336-8D4A-7E9024F61B08@gmail.com> 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="33433"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Jun 20 12:50:13 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 1qBYw8-0008VY-Fz for ged-emacs-devel@m.gmane-mx.org; Tue, 20 Jun 2023 12:50:12 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qBYvQ-0001Fr-6b; Tue, 20 Jun 2023 06:49:28 -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 1qBYQG-0004Wb-G3 for emacs-devel@gnu.org; Tue, 20 Jun 2023 06:17:16 -0400 Original-Received: from mail-yb1-xb35.google.com ([2607:f8b0:4864:20::b35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBYQE-0007Rf-OI for emacs-devel@gnu.org; Tue, 20 Jun 2023 06:17:16 -0400 Original-Received: by mail-yb1-xb35.google.com with SMTP id 3f1490d57ef6-bb3a77abd7bso4564739276.0 for ; Tue, 20 Jun 2023 03:17:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687256233; x=1689848233; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ujYHVSYxAPhck+zy7ZvuvMNOUkiZvNf8A6HgIfYNZDY=; b=AZb+aZbcDsBxhJJhYxKvwzwMGWXIkz+xvyYUMvepK1t2WNtB6OBOgQXmaZHundUjL2 QQLTKCaYTdrIlg/Clm/LFOrCNLiuODgHjv+ZPCYgRbm0XbYikraqsWxa6RqNhVTA815X DxJ/2O6/4L6xXvOaOSvyhZiMDP1znt2fH1kxHrUEba5THNom9gTee5OkPlSILVSPs6cA u6bLaySLHqhJYYHf12f+rd2UgBqhuN+rtSCQNu9DLhPAQF0HsXJiBc2DwyDWmDqF7DBm ys3C5G12LUrdMz2lyfDMi55FYzVlTzVp8KEoDBDO63LC1tS0PVyQ9lC1hboRrXFHQ179 4OxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687256233; x=1689848233; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ujYHVSYxAPhck+zy7ZvuvMNOUkiZvNf8A6HgIfYNZDY=; b=YDtCPsWtYsmS5Jj0pGVwJy7rRy95nREYys+6jA3Svb4ukFOZnE8Vjy2gb/y8jVK75P BRruqzFvM3YIbQIiZxBHLXKbTmqOaPA8jhbKSWgfQPUzfVtVyzOOd5SHbHVTxysQfGPQ iRhR7XTrNkj9Y9bZk5K7+7YHyCxt28FqOk36d5u9AMCBd4lmvgKuA23E4idgTmRW0Uvt h+QWbpE7AM+wvMg22NNnK7JOfwcG9031pL+F/qt6PFljgkuGN5Xo0VhKQonm7PgeO/Eh yvXlftVS+wIHCbyGHa0QR34A9cHpa07a/0whkgR6P0Y32h9CsY1mu8JWUs42YGxzccdq EB2Q== X-Gm-Message-State: AC+VfDztycf936RlPOeBPUPCL1Y7fYlkoUXAKfLq8bB5xfFdlOTWcQY/ 4IcJx0XGRP7ELTJ0H42enjGmKgJ7awXaPVV8KTg= X-Google-Smtp-Source: ACHHUZ5AIijAyx4NHFxLYpDVpkBShvMT1po7Ewz6RB2CJYGbb+gmZ7ajCoHbkYlmlBT++Gg7Qr8qRJXPzc/8IPD+WB4= X-Received: by 2002:a25:5008:0:b0:bd0:8895:78ce with SMTP id e8-20020a255008000000b00bd0889578cemr8599006ybb.18.1687256233438; Tue, 20 Jun 2023 03:17:13 -0700 (PDT) In-Reply-To: <1527B47A-3A4B-4336-8D4A-7E9024F61B08@gmail.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::b35; envelope-from=n.oje.bar@gmail.com; helo=mail-yb1-xb35.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-Mailman-Approved-At: Tue, 20 Jun 2023 06:49:26 -0400 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:307080 Archived-At: Dear Yuan, Thanks for your response. Let me give you a bit of context. I am trying writing a major mode for OCaml. For indentation, I am trying to replicate (as much as possible) the popular tool `ocp-indent` (https://github.com/OCamlPro/ocp-indent). As far as I can see, this tool tries to produce indentations which are "diff-friendly", that is, such that breaking a line does not cause indentation to change in the following lines. Concretely, consider the (indented) example ``` let x =3D match e with | Foo -> 0 ``` If we move the `match` construct to the same line as `let`, I would like the result to be indented as follows: ``` let x =3D match e with | Foo -> 0 ``` and _not_ ``` let x =3D match e with | Foo -> 0 ``` (in the context of my original message, "a" was the "let" expression, "b", the "match" expression, and "c" the match clause "| Foo -> 0"). I hope that clarifies a bit my motivation. Do let me know if anything is unclear. Cheers, Nicolas On Tue, Jun 20, 2023 at 8:12=E2=80=AFAM Yuan Fu wrote: > > > > > On Jun 19, 2023, at 12:11 PM, Nicol=C3=A1s Ojeda B=C3=A4r wrote: > > > > Hello, > > > > I am trying my hand at writing a tree-sitter major mode. I am using > > "treesit-simple-indent-rules" for indentation, but have not managed to > > get the indentation style that I am looking for. > > > > Suppose that the AST that you are trying to indent is (a (b c)) and > > that you have > > the indentation rules > > > > ((parent-is "a") parent-bol 2) > > ((parent-is "b") parent-bol 0) > > > > Then the following is well-indented: > > > > a > > b > > c > > > > However, if "b" is in the same line as "a", then the result of indentat= ion is: > > > > a b > > c > > > > But I would like to have instead > > > > a b > > c > > > > That is, I would like "c" to be indented _as if_ "b" was on a separate > > line. Is there a way to achieve this? > > There are different approaches to this. Could you maybe explain why you w= ant to indent it like this, so that I know what=E2=80=99s your intent? Mayb= e also give a concert example? I=E2=80=99m guessing something like a is spe= cial and you only want one level of indentation for the whole statement, ev= en if it occupies multiple lines; or it could be that b and c are special a= nd should align? > > Yuan