[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Would (Eval-when-compile (require 'treesit)) eliminate the need for
From: |
Stefan Monnier |
Subject: |
Re: Would (Eval-when-compile (require 'treesit)) eliminate the need for (declare-function)s? |
Date: |
Mon, 17 Apr 2023 13:25:26 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
>> I’ve made the mistake of forgetting to add (declare-function treesit-xxx)
>> when using functions from treesit.c far too many times (sorry!). Since
>> treesit.el contains declare-function’s for every function in treesit.c, if
>> we use (eval-when-compile (require ’treesit)), would it eliminate the need
>> for adding declare-function’s?
I hope it doesn't: `declare-function` is supposed to affect only the
"current scope", like `(defvar <VAR>)`.
>> Should we do that?
IIUC one way to look at this is that `treesit.el` wants to "re-export"
the functions provided by `treesit.c` so users of `treesit.el` don't
need to know whether the function they call is implemented in C or
in ELisp?
That makes a lot of sense, and I don't think we have a good way to do
that currently :-(
I suspect in most cases we avoid the problem in one of two ways:
- Always define the C function (rather than being conditional on some
compilation flag as is the case for `treesit.c` functions).
- Export from C only "internal functions" so all the non-internal API is
implemented in ELisp.
> Even if it does work reliably, I'm not sure we want that. It is
> better to have declare-function where the function is used, as that
> makes maintenance easier and less error-prone.
But it makes sense for packages that do
(require 'treesit)
to be able to use those functions implemented in `treesit.c` without
bothering with `declare-function`.
Stefan