GNU bug report logs -
#60025
[PATCH] Add go-ts-mode and go-mod-ts-mode
Previous Next
Reported by: Randy Taylor <dev <at> rjt.dev>
Date: Tue, 13 Dec 2022 02:15:01 UTC
Severity: normal
Tags: patch
Done: Randy Taylor <dev <at> rjt.dev>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
Randy Taylor <dev <at> rjt.dev> writes:
> On Wednesday, December 14th, 2022 at 16:27, Theodor Thornhill <theo <at> 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
This bug report was last modified 2 years and 215 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.