emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: toml-ts-mode: first draft


From: Theodor Thornhill
Subject: Re: toml-ts-mode: first draft
Date: Mon, 12 Dec 2022 14:53:23 +0100

Jostein Kjønigsen <jostein@secure.kjonigsen.net> writes:

> On 12.12.2022 00:01, Yuan Fu wrote:
>> Looks great!
> Thanks!
>> +  (unless (treesit-ready-p 'toml)
>> +    (error "Tree-sitter for TOML isn't avilable”))
>>
>> Treesit-ready-p already raises a warning when something goes wrong. So you 
>> want to either pass the QUIET argument or let it do the barking ;-)
>>
>> Yuan
>
> Sure, I can fix that.
>
> I notice though that this is not applied consistently in the other 
> tree-sitter based major-modes.
>
>  From json-ts-mode.el:
>
>  >  (unless (treesit-ready-p 'json)
>  >   (error "Tree-sitter for JSON isn't available"))
>
>  From csharp-mode.el:
>
>  >  (unless (treesit-ready-p 'c-sharp)
>  >    (error "Tree-sitter for C# isn't available"))
>
>  From typescript-ts-mode.el:
>
>  >  (when (treesit-ready-p 'tsx)
>  >    (treesit-parser-create 'tsx)
>
>  From python.el:
>
>  >  (when (treesit-ready-p 'python)
>  >    (treesit-parser-create 'python)
>
> I see in the (treesit-ready-p) it clearly throws when language is missing.
>
> So from what I can tell all of the "established" forms are doing too much:
>
> * checking return-value (not required because of throwing)
> * creating errors

IIRC I had some issues with that form some time in the past.  I think
we should abstract this away completely and let treesit-major-mode-setup
do it, by doing something like:

```
(treesit-major-mode-setup 'java)
```

and inside of that function do the

(when (treesit-ready-p lang)
  (treesit-parser-create lang)
  ....)

Then this could be removed from all modes:

  (unless (treesit-ready-p 'java)
    (error "Tree-sitter for Java isn't available"))

  (treesit-parser-create 'java)

Most init is just setq-locals anyway.

Is there a reason we cannot do that?

Theo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]