[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#60025: [PATCH] Add go-ts-mode and go-mod-ts-mode
From: |
Theodor Thornhill |
Subject: |
bug#60025: [PATCH] Add go-ts-mode and go-mod-ts-mode |
Date: |
Wed, 14 Dec 2022 22:27:05 +0100 |
Randy Taylor <dev@rjt.dev> writes:
> On Wednesday, December 14th, 2022 at 14:55, Yuan Fu <casouri@gmail.com> wrote:
>>
>> > I am having a tiny bit of trouble with a go.mod indentation rule. Using
>> > the patch, create a go.mod file anywhere, activate go-mod-ts-mode and add
>> > the following:
>> >
>> > require ()
>> >
>> > Place point inside the parens, and then hit enter. The expectation is that
>> > point will end up indented inside that block. If you add the text "test
>> > v1.0.0" and hit TAB, it will indent properly (and if you hit enter after
>> > that text it will indent properly for the next entry). If you go to the
>> > end of the line for the top paren and hit enter, it will not indent (and
>> > we want it to). It seems to give us no-node in that circumstance. Is there
>> > a simple indent rule that can match exactly that that I'm missing?
>>
>>
>> I think you can just test for the parent? In C, if point is at an empty line
>> after a statement in a block, like this:
>>
>> int main() {
>> return 0;
>> |
>> }
>>
>> The matched rule is (parent-is “compond_statement”), where
>> compound_statement is the block. In your case, I guess you can test if
>> parent is the argument list.
>>
>> Yuan
>
> I do match for the parent, but it doesn't seem to help.
> Here's what tree-sitter explorer shows for the following:
> require (
>
> )
>
> (require_directive require ( \n ) \n)
>
> If I put point on the line right below r and do C-S-a, tree-sitter explorer
> shows:
> (require_directive require (*\n ) \n)
> The * indicates that part is highlighted.
>
> The second I make it "proper" like so:
> require (
> test v1
> )
>
> I can hit TAB and it will indent properly (but not anything above it, only
> that line and anything below).
>
> I would think that checking parent-is for require_directive would be enough
> but it's not somehow???
> It's instead matching my no-node rule...
Yeah, I seem to remember seeing these \n nodes in the go-mode I made
some time ago. There is no node there, so no-node is the rule that
matches, as there is no parent. I believe you can solve it with
something like
(defun go-backward-up-list ()
(lambda (node parent bol &rest _)
(save-excursion
(backward-up-list 1 nil t)
(back-to-indentation)
(point))))
and use some variant of that. Now you can find a different node without
relying on there being a node where you start.
But I don't remember exactly.
BTW, I tried applying this mode, but it wouldn't apply.
Theo
- bug#60025: [PATCH] Add go-ts-mode and go-mod-ts-mode, Randy Taylor, 2022/12/12
- bug#60025: [PATCH] Add go-ts-mode and go-mod-ts-mode, Eli Zaretskii, 2022/12/13
- bug#60025: [PATCH] Add go-ts-mode and go-mod-ts-mode, Randy Taylor, 2022/12/13
- bug#60025: [PATCH] Add go-ts-mode and go-mod-ts-mode, Eli Zaretskii, 2022/12/14
- bug#60025: [PATCH] Add go-ts-mode and go-mod-ts-mode, Randy Taylor, 2022/12/14
- bug#60025: [PATCH] Add go-ts-mode and go-mod-ts-mode, Yuan Fu, 2022/12/14
- bug#60025: [PATCH] Add go-ts-mode and go-mod-ts-mode, Randy Taylor, 2022/12/14
- bug#60025: [PATCH] Add go-ts-mode and go-mod-ts-mode,
Theodor Thornhill <=
- bug#60025: [PATCH] Add go-ts-mode and go-mod-ts-mode, Randy Taylor, 2022/12/14
- bug#60025: [PATCH] Add go-ts-mode and go-mod-ts-mode, Randy Taylor, 2022/12/14
- bug#60025: [PATCH] Add go-ts-mode and go-mod-ts-mode, Theodor Thornhill, 2022/12/15
- bug#60025: [PATCH] Add go-ts-mode and go-mod-ts-mode, Randy Taylor, 2022/12/15
- bug#60025: [PATCH] Add go-ts-mode and go-mod-ts-mode, Theodor Thornhill, 2022/12/15
- bug#60025: [PATCH] Add go-ts-mode and go-mod-ts-mode, Randy Taylor, 2022/12/15
- bug#60025: [PATCH] Add go-ts-mode and go-mod-ts-mode, Theodor Thornhill, 2022/12/15
- bug#60025: [PATCH] Add go-ts-mode and go-mod-ts-mode, Randy Taylor, 2022/12/15
- bug#60025: [PATCH] Add go-ts-mode and go-mod-ts-mode, Randy Taylor, 2022/12/15
bug#60025: [PATCH] Add go-ts-mode and go-mod-ts-mode, Yuan Fu, 2022/12/13