emacs-devel
[Top][All Lists]
Advanced

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

Re: Use (eval-when-compile 'treesit) to save us from writing declare-fun


From: Yuan Fu
Subject: Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms
Date: Wed, 11 Dec 2024 22:05:56 -0800


> On Dec 11, 2024, at 4:23 PM, Dmitry Gutov <dmitry@gutov.dev> wrote:
> 
> On 12/12/2024 01:38, Andrea Corallo wrote:
>> The suggestion of having the C functions defined to nops when
>> HAVE_TREE_SITTER is not defined is cleaner in principle, but I think
>> there are two downsides:
>> - We don't tipically do it this way, so it would be an exception
> 
> We also don't typically require a caller to have a 'declare-function' for 
> every function they use from a package that they (require ...) already.
> 
>> - Also we should do it for all the functions in treesit.c, otherwise we
>>   don't solve the original problem of introducing warnings by mistake on
>>   non treesit builds.
> 
> Sure. All non-static ones anyway.

I tried to define all the C functions and it’s not easy to do: doing it in C 
seems pretty tedious, we’d need DEFUN form and defsubr for each function (is 
there a easier way?). If done in lisp, we need to do it in a separate file and 
_load_ it before compiling treesit.el and any other package that uses 
tree-sitter. I’m not familiar with Emacs’s build process so I don’t know how 
and where to add such a file and make Emacs load it on startup.

Can someone enlighten me on how to define these functions in either C or lisp?

I think defining them as no-op for Emacs w/o tree-sitter is a good move, 
because otherwise if some user compiles an Emacs w/o tree-sitter and compiles a 
bunch of packages, and one of the package happens to be based on tree-sitter, 
they’ll see a bunch of warnings unless the package author added 
declare-function forms or the proposed macro. It’s better to have tree-sitter 
functions always defined and save everybody some hassle.

Yuan


reply via email to

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