[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: |
Sun, 8 Dec 2024 17:37:59 -0800 |
> On Dec 8, 2024, at 7:27 AM, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>
>> +(eval-when-compile
>> + (treesit-declare-c-functions))
>
> `treesit-declare-c-functions` is a macro, that expands to
> `declare-function`s, i.e. to "no-ops".
> Why wrap it within `eval-when-compile`?
I thought that might be TRT since they’re only needed for compiling the file.
>
> If it works within an `eval-when-compile`, it's only by accident (just
> like the fact that (eval-when-compile (defvar foo)) "works" is an
> accident): code shouldn't rely on it.
>
> It's not the evaluation of `defvar` or `declare-function` that is needed
> (because such an evaluation should have no effect, as you can see if
> you look at the definition of `declare-function`), but instead the
> "calls" to `defvar` or `declare-function` need to be seen/processed by
> the compiler. By wrapping them within an `eval-when-compile` you risk
> *hiding* them from the compiler.
I thought eval-when-compile is more of a “include if compiling” macro,
should’ve checked :)
We can also go with Dmitry’s idea, and just define all the functions in
treesit.el if Emacs is not built with tree-sitter. We can detect that with
treesit-available-p.
Yuan
- 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, Eli Zaretskii, 2024/12/04
- Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms, Yuan Fu, 2024/12/05
- Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms, Eli Zaretskii, 2024/12/05
- Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms, Yuan Fu, 2024/12/06
- Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms, Eli Zaretskii, 2024/12/07
- Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms, Stefan Monnier, 2024/12/07
- 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, Eli Zaretskii, 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, Stefan Monnier, 2024/12/08
- Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms,
Yuan Fu <=
- 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, 2024/12/12
- 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