emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can this indentation be achieved with treesit-simple-indent-rules?


From: Yuan Fu
Subject: Re: Can this indentation be achieved with treesit-simple-indent-rules?
Date: Tue, 20 Jun 2023 14:53:06 -0700


> On Jun 20, 2023, at 9:16 AM, Nicolás Ojeda Bär <n.oje.bar@gmail.com> wrote:
> 
> On Tue, Jun 20, 2023 at 5:34 PM Dmitry Gutov <dmitry@gutov.dev> wrote:
>> 
>> On 19/06/2023 22:11, Nicolás Ojeda Bär wrote:
>>>     ((parent-is "b") parent-bol 0)
>> 
>> Try 'parent' instead of 'parent-bol'.
> 
> Hello,
> 
> Thanks for the suggestion.
> 
> 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
> 
> aaa
>  bbb
>  ccc
> 
> if we put "bbb" in the same line as "aaa" we will get (using parent
> instead of parent-bol)
> 
> aaa bbb
>    ccc
> 
> but would like to get
> 
> aaa bbb
>  ccc
> 
> In the concrete example in OCaml I mentioned in a previous reply, starting 
> from
> 
> let x =
>  match e with
>  | Foo -> 0
> 
> if I put the "match" in the same line as the "let" (using parent
> instead of parent-bol) I will get
> 
> let x = match e with
>        | Foo -> 0
> 
> but would like to get instead
> 
> let x = match e with
>  | Foo -> 0
> 
> Do let me know if anything is still unclear.

Thanks for the context. So the logic is “the value of a let = VALUE should have 
a base indentation of +1 level”. Maybe you can add a rule that matches “the 
line below a let”, 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 “let x = y in body”, 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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]