emacs-devel
[Top][All Lists]
Advanced

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

Re: Tree-sitter api


From: Tuấn-Anh Nguyễn
Subject: Re: Tree-sitter api
Date: Fri, 17 Sep 2021 20:39:27 +0700

On Fri, Sep 17, 2021 at 8:14 PM Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> Why not just `tree-sitter-language-name` which the major mode can set
> buffer-locally.
>
>     (setq-local tree-sitter-language-name 'foo)
>
> is better than
>
>     (add-to-list 'tree-sitter-major-mode-language-alist '(foo-mode . foo))

It can be both, with one being the underlying mechanism for the other. (That's
what I do in my packages.) The alist is a central place that's more convenient
for users (not mode writers) to customize, e.g. in case a major mode hasn't
added itself yet:

    (add-hook 'foo-mode-hook (lambda () (setq tree-sitter-language-name 'foo)))

is less convenient than

    (add-to-list 'tree-sitter-major-mode-language-alist '(foo-mode . foo))

> [ Among other things because it won't signal an error when
>   `tree-sitter.el` is not loaded.  ]

We can make `tree-sitter-major-mode-language-list` autoloaded.

-- 
Tuấn-Anh Nguyễn
Software Engineer



reply via email to

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