[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: |
Eli Zaretskii |
Subject: |
Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms |
Date: |
Thu, 12 Dec 2024 08:43:39 +0200 |
> From: Yuan Fu <casouri@gmail.com>
> Date: Wed, 11 Dec 2024 22:05:56 -0800
> Cc: Andrea Corallo <acorallo@gnu.org>,
> Eli Zaretskii <eliz@gnu.org>,
> emacs-devel@gnu.org
>
>
>
> > 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.
FWIW, I'd rather we didn't go this way, for the reasons Andrea
explained (and I agreed). Inventing some new technique or tricks just
for this one case, when we don't do anything like that in any other
similar case, doesn't sound like a good idea, because it would mean
one more subtle protocol to support in Emacs development. It gets in
the way while reviewing patches, for example, because it is not easy
to remember when special conventions must be observed. E.g., should
someone come up with a new DEFUN in treesit.c, someone should remember
that a no-op function by the same name should be defined at the same
time. Or we'd need to #ifdef out the body of each DEFUN, which makes
the code harder to read.
Can we find some other way of making this easier, without defining
no-op functions in treesit.c?
- Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms, (continued)
- Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms, Stefan Monnier, 2024/12/08
- Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms, Yuan Fu, 2024/12/08
- Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms, Stefan Monnier, 2024/12/08
- Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms, Dmitry Gutov, 2024/12/10
- Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms, Dmitry Gutov, 2024/12/08
- Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms, Andrea Corallo, 2024/12/11
- Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms, Dmitry Gutov, 2024/12/11
- Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms, Yuan Fu, 2024/12/12
- Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms,
Eli Zaretskii <=
- Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms, Yuan Fu, 2024/12/13
- Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms, Eli Zaretskii, 2024/12/12
- Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms, Eli Zaretskii, 2024/12/12