[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#60602: 29.0.60; treesit-simple-indent doesn't work for top-level nod
From: |
Theodor Thornhill |
Subject: |
bug#60602: 29.0.60; treesit-simple-indent doesn't work for top-level nodes |
Date: |
Fri, 20 Jan 2023 22:40:51 +0100 |
Hi there!
Yuan Fu <casouri@gmail.com> writes:
> Piotr Trojanek <piotr.trojanek@gmail.com> writes:
>
>> This problem can be reproduced with a correctly configured c-ts-mode,
>> which fails to indent the first line of a code like this, i.e. with
>> extra space at the very beginning of file and cursor positioned at
>> "main"):
>>
>> ===
>> int main (int argc, char *argv[])
>> {
>> return 0;
>> }
>> ===
>>
>> The intent of c-ts-mode--indent-styles is clearly to indent this line
>> to 0th column:
>>
>> (defun c-ts-mode--indent-styles (mode)
>> ...
>> `(((parent-is "translation_unit") parent-bol 0)
>>
>> However, when indenting this line treesit-simple-indent is called with
>> node=translation_unit and parent=nil. It exits too early and doesn't
>> consider any indentation rules:
>>
>> (defun treesit-simple-indent (node parent bol)
>> "..."
>> (if (null parent)
>> (progn (when treesit--indent-verbose
>> (message "PARENT is nil, not indenting"))
>> (cons nil nil))
>>
>> 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)
>>
>> Perhaps the early exit from treesit-simple-indent could be removed, so
>> the indentation rules can decide how to handle a nil parent.
>
> Now NODE is never the root node, so parent is never nil. I believe this
> is the best approach. And personally I think the rule should be
>
> ((parent-is "program") point-min 0)
>
> Yuan
You okay with this patch, Piotr and Dmitry?
Theo
0001-Use-point-min-to-anchor-top-level-constructs-bug-606.patch
Description: Text Data