[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: |
Thu, 15 Dec 2022 08:20:46 +0100 |
Randy Taylor <dev@rjt.dev> writes:
> On Wednesday, December 14th, 2022 at 16:27, Theodor Thornhill
> <theo@thornhill.no> wrote:
>>
>> 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.
>
> Thanks Theo, that worked perfectly. We should consider adding
> something like this to the documentation somewhere, since I didn't see
> anything like this anywhere (although maybe I missed it).
I'm glad! Could be part of a tips and tricks or something?
[...]
> +(defvar go-ts-mode--indent-rules
> + `((go
> + ((node-is ")") parent-bol 0)
> + ((node-is "]") parent-bol 0)
> + ((node-is "}") parent-bol 0)
> + ((node-is "labeled_statement") no-indent)
> + ((parent-is "argument_list") parent-bol go-ts-mode-indent-offset)
> + ((parent-is "block") parent-bol go-ts-mode-indent-offset)
> + ((parent-is "const_declaration") parent-bol go-ts-mode-indent-offset)
> + ((parent-is "default_case") parent-bol go-ts-mode-indent-offset)
> + ((parent-is "expression_case") parent-bol go-ts-mode-indent-offset)
> + ((parent-is "expression_switch_statement") parent-bol 0)
> + ((parent-is "field_declaration_list") parent-bol
> go-ts-mode-indent-offset)
> + ((parent-is "import_spec_list") parent-bol go-ts-mode-indent-offset)
> + ((parent-is "labeled_statement") parent-bol go-ts-mode-indent-offset)
> + ((parent-is "literal_value") parent-bol go-ts-mode-indent-offset)
> + ((parent-is "type_spec") parent-bol go-ts-mode-indent-offset)
> + ((parent-is "var_declaration") parent-bol go-ts-mode-indent-offset)
> + (no-node parent-bol 0)))
> + "Tree-sitter indent rules for `go-ts-mode'.")
No rules for comment?
[...]
> +;; go.mod support.
> +
> +(defvar go-mod-ts-mode--syntax-table
> + (let ((table (make-syntax-table)))
> + (modify-syntax-entry ?/ ". 124b" table)
> + (modify-syntax-entry ?\n "> b" table)
> + table)
> + "Syntax table for `go-mod-ts-mode'.")
> +
> +(defvar go-mod-ts-mode--indent-rules
> + `((gomod
> + ((node-is ")") parent-bol 0)
> + ((parent-is "exclude_directive") parent-bol go-ts-mode-indent-offset)
> + ((parent-is "module_directive") parent-bol go-ts-mode-indent-offset)
> + ((parent-is "replace_directive") parent-bol go-ts-mode-indent-offset)
> + ((parent-is "require_directive") parent-bol go-ts-mode-indent-offset)
> + ((parent-is "retract_directive") parent-bol go-ts-mode-indent-offset)
> + ((go-mod-ts-mode--in-directive-p) no-indent go-ts-mode-indent-offset)
> + (no-node no-indent 0)))
> + "Tree-sitter indent rules for `go-mod-ts-mode'.")
No rules for comment here either?
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, 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, 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/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
bug#60025: [PATCH] Add go-ts-mode and go-mod-ts-mode, Yuan Fu, 2022/12/15