Subject: Re: bug#60602: 29.0.60; treesit-simple-indent doesn't work for top-level nodes

From: Dmitry Gutov <[email-masked]>
Date: Fri, 6 Jan 2023 16:55:07 +0200

On 06/01/2023 15:40, Piotr Trojanek wrote:
> Note that other tree-sitter modes have similar indentation rules, e.g.
> ruby-ts-mode.el:
> 
>     ;; Slam all top level nodes to the left margin
>     ((parent-is "program") parent 0)
> 
> and same for typescript-ts-mode.el:
> 
>    ((parent-is "program") parent-bol 0)

Probably relatedly, in ruby-ts-mode (and probably others), when the 
first child of a block node (e.g. sequence statements) is reindended, 
it's often that its parent is passed to the rules, not that actual 
child. Which makes the indentation rules irregular, forcing us to add 
extra cases.

Note this comment at ruby-ts-mode:635:

            ;; well as statements.  Note that the first statement of a
            ;; body_statement hits the node as "body_statement" and not
            ;; as the assignment, etc.

and the rules below.

Not sure if there is an easy fix for this, however, given that both 
body_statement and its first child start at the same position. Perhaps a 
translation step before the rules are applied? E.g. in case of Ruby 
body_statement or block_body we would translate to the first child node 
first, to then apply the rules to it. Same for 'program', I guess.