unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Use (eval-when-compile 'treesit) to save us from writing declare-function forms
@ 2024-12-03  6:31 Yuan Fu
  2024-12-03  8:30 ` Andrea Corallo
  2024-12-03 13:12 ` Eli Zaretskii
  0 siblings, 2 replies; 6+ messages in thread
From: Yuan Fu @ 2024-12-03  6:31 UTC (permalink / raw)
  To: Emacs Devel

Some of my recent changes to c-ts-mode.el uses some more C treesit functions, and I (again) forgot to add their declare-function forms to c-ts-mode.el, and Andrea has to fix it for me. The main problem for me is that (I think) you don’t get warning for them unless you build a non-tree-sitter build of Emacs. So I’m prone to forgot about them. Also it’s a burden for anyone wanting to use tree-sitter functions.

treesit.el already has all the declare-function forms, how about we use (eval-when-compile 'treesit) in other files? I believe that should alleviate us from adding those declare-function forms in other files?

I want to ask because IIRC I proposed this a while back but there were objections, the details of which I forgot.

Yuan


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms
  2024-12-03  6:31 Use (eval-when-compile 'treesit) to save us from writing declare-function forms Yuan Fu
@ 2024-12-03  8:30 ` Andrea Corallo
  2024-12-04 18:21   ` Yuan Fu
  2024-12-03 13:12 ` Eli Zaretskii
  1 sibling, 1 reply; 6+ messages in thread
From: Andrea Corallo @ 2024-12-03  8:30 UTC (permalink / raw)
  To: Yuan Fu; +Cc: Emacs Devel

Yuan Fu <casouri@gmail.com> writes:

> Some of my recent changes to c-ts-mode.el uses some more C treesit
> functions, and I (again) forgot to add their declare-function forms to
> c-ts-mode.el, and Andrea has to fix it for me. The main problem for me
> is that (I think) you don’t get warning for them unless you build a
> non-tree-sitter build of Emacs. So I’m prone to forgot about
> them. Also it’s a burden for anyone wanting to use tree-sitter
> functions.
>
> treesit.el already has all the declare-function forms, how about we
> use (eval-when-compile 'treesit) in other files? I believe that should
> alleviate us from adding those declare-function forms in other files?
>
> I want to ask because IIRC I proposed this a while back but there were objections, the details of which I forgot.
>
> Yuan

Hi Yuan,

I was not part of the discussion and I don't know what's the downside of
(eval-when-compile 'treesit), maybe another alternative would be to have
like a dedicated treesit-delcs.el to require where necessary?

  Andrea



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms
  2024-12-03  6:31 Use (eval-when-compile 'treesit) to save us from writing declare-function forms Yuan Fu
  2024-12-03  8:30 ` Andrea Corallo
@ 2024-12-03 13:12 ` Eli Zaretskii
  2024-12-04 18:19   ` Yuan Fu
  1 sibling, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2024-12-03 13:12 UTC (permalink / raw)
  To: Yuan Fu; +Cc: emacs-devel

> From: Yuan Fu <casouri@gmail.com>
> Date: Mon, 2 Dec 2024 22:31:48 -0800
> 
> Some of my recent changes to c-ts-mode.el uses some more C treesit functions, and I (again) forgot to add their declare-function forms to c-ts-mode.el, and Andrea has to fix it for me. The main problem for me is that (I think) you don’t get warning for them unless you build a non-tree-sitter build of Emacs. So I’m prone to forgot about them. Also it’s a burden for anyone wanting to use tree-sitter functions.
> 
> treesit.el already has all the declare-function forms, how about we use (eval-when-compile 'treesit) in other files? I believe that should alleviate us from adding those declare-function forms in other files?

I don't understand" c-ts-mode.el already does

  (require 'treesit)

So what would eval-when-compile add to that?



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms
  2024-12-03 13:12 ` Eli Zaretskii
@ 2024-12-04 18:19   ` Yuan Fu
  2024-12-04 18:57     ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Yuan Fu @ 2024-12-04 18:19 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel



> On Dec 3, 2024, at 5:12 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Mon, 2 Dec 2024 22:31:48 -0800
>> 
>> Some of my recent changes to c-ts-mode.el uses some more C treesit functions, and I (again) forgot to add their declare-function forms to c-ts-mode.el, and Andrea has to fix it for me. The main problem for me is that (I think) you don’t get warning for them unless you build a non-tree-sitter build of Emacs. So I’m prone to forgot about them. Also it’s a burden for anyone wanting to use tree-sitter functions.
>> 
>> treesit.el already has all the declare-function forms, how about we use (eval-when-compile 'treesit) in other files? I believe that should alleviate us from adding those declare-function forms in other files?
> 
> I don't understand" c-ts-mode.el already does
> 
>  (require 'treesit)
> 
> So what would eval-when-compile add to that?

When Emacs is built without tree-sitter, none of the treesit.c functions are available (except for treesit-ready-p). Now if this Emacs compiles c-ts-mode.el, it’ll signal undefined function error for all those functions. So we add declare-function forms for all the treesit.c functions used in c-ts-mode.el, and have to update the declare-function forms whenever we use some new treesit.c functions.

If we use eval-when-compile, we don’t need to write declare-function forms in c-ts-mode.el anymore, because treesit.el has declare-function forms for all treesit.c functions.

Yuan


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms
  2024-12-03  8:30 ` Andrea Corallo
@ 2024-12-04 18:21   ` Yuan Fu
  0 siblings, 0 replies; 6+ messages in thread
From: Yuan Fu @ 2024-12-04 18:21 UTC (permalink / raw)
  To: Andrea Corallo; +Cc: Emacs Devel



> On Dec 3, 2024, at 12:30 AM, Andrea Corallo <acorallo@gnu.org> wrote:
> 
> Yuan Fu <casouri@gmail.com> writes:
> 
>> Some of my recent changes to c-ts-mode.el uses some more C treesit
>> functions, and I (again) forgot to add their declare-function forms to
>> c-ts-mode.el, and Andrea has to fix it for me. The main problem for me
>> is that (I think) you don’t get warning for them unless you build a
>> non-tree-sitter build of Emacs. So I’m prone to forgot about
>> them. Also it’s a burden for anyone wanting to use tree-sitter
>> functions.
>> 
>> treesit.el already has all the declare-function forms, how about we
>> use (eval-when-compile 'treesit) in other files? I believe that should
>> alleviate us from adding those declare-function forms in other files?
>> 
>> I want to ask because IIRC I proposed this a while back but there were objections, the details of which I forgot.
>> 
>> Yuan
> 
> Hi Yuan,
> 
> I was not part of the discussion and I don't know what's the downside of
> (eval-when-compile 'treesit), maybe another alternative would be to have
> like a dedicated treesit-delcs.el to require where necessary?
> 

That’ll be ok too. Though 99.99% the case, if some package uses tree-sitter, they’d need something in treesit.el too.

Yuan


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Use (eval-when-compile 'treesit) to save us from writing declare-function forms
  2024-12-04 18:19   ` Yuan Fu
@ 2024-12-04 18:57     ` Eli Zaretskii
  0 siblings, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2024-12-04 18:57 UTC (permalink / raw)
  To: Yuan Fu; +Cc: emacs-devel

> From: Yuan Fu <casouri@gmail.com>
> Date: Wed, 4 Dec 2024 10:19:42 -0800
> Cc: emacs-devel@gnu.org
> 
> 
> 
> > On Dec 3, 2024, at 5:12 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> > 
> > I don't understand" c-ts-mode.el already does
> > 
> >  (require 'treesit)
> > 
> > So what would eval-when-compile add to that?
> 
> When Emacs is built without tree-sitter, none of the treesit.c functions are available (except for treesit-ready-p). Now if this Emacs compiles c-ts-mode.el, it’ll signal undefined function error for all those functions. So we add declare-function forms for all the treesit.c functions used in c-ts-mode.el, and have to update the declare-function forms whenever we use some new treesit.c functions.
> 
> If we use eval-when-compile, we don’t need to write declare-function forms in c-ts-mode.el anymore, because treesit.el has declare-function forms for all treesit.c functions.

That's what I don't understand: how will eval-when-compile which loads
treesit.el be different from (require 'treesit) we already have in
c-ts-mode?  Don't they both load treesit.el?



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-12-04 18:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-03  6:31 Use (eval-when-compile 'treesit) to save us from writing declare-function forms Yuan Fu
2024-12-03  8:30 ` Andrea Corallo
2024-12-04 18:21   ` Yuan Fu
2024-12-03 13:12 ` Eli Zaretskii
2024-12-04 18:19   ` Yuan Fu
2024-12-04 18:57     ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).