all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Would (Eval-when-compile (require 'treesit)) eliminate the need for (declare-function)s?
@ 2023-04-17  3:12 Yuan Fu
  2023-04-17  3:31 ` Ruijie Yu via Emacs development discussions.
  2023-04-17 17:05 ` Eli Zaretskii
  0 siblings, 2 replies; 7+ messages in thread
From: Yuan Fu @ 2023-04-17  3:12 UTC (permalink / raw)
  To: emacs-devel

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? Should we do that?

Yuan


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

* Re: Would (Eval-when-compile (require 'treesit)) eliminate the need for (declare-function)s?
  2023-04-17  3:12 Would (Eval-when-compile (require 'treesit)) eliminate the need for (declare-function)s? Yuan Fu
@ 2023-04-17  3:31 ` Ruijie Yu via Emacs development discussions.
  2023-04-17 13:29   ` Philip Kaludercic
  2023-04-17 17:05 ` Eli Zaretskii
  1 sibling, 1 reply; 7+ messages in thread
From: Ruijie Yu via Emacs development discussions. @ 2023-04-17  3:31 UTC (permalink / raw)
  To: Yuan Fu; +Cc: emacs-devel


Yuan Fu <casouri@gmail.com> writes:

> 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? Should we do that?
>
> Yuan

According to Eli
(https://lists.gnu.org/archive/html/emacs-devel/2023-03/msg00673.html),
no, it wouldn't work.

[ Also, for some reason I cannot find the message using the msgid,
83ilezegs1.fsf@gnu.org? ]

-- 
Best,


RY



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

* Re: Would (Eval-when-compile (require 'treesit)) eliminate the need for (declare-function)s?
  2023-04-17  3:31 ` Ruijie Yu via Emacs development discussions.
@ 2023-04-17 13:29   ` Philip Kaludercic
  0 siblings, 0 replies; 7+ messages in thread
From: Philip Kaludercic @ 2023-04-17 13:29 UTC (permalink / raw)
  To: Ruijie Yu via Emacs development discussions.; +Cc: Yuan Fu, Ruijie Yu

Ruijie Yu via "Emacs development discussions." <emacs-devel@gnu.org>
writes:

> Yuan Fu <casouri@gmail.com> writes:
>
>> 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? Should we do that?
>>
>> Yuan
>
> According to Eli
> (https://lists.gnu.org/archive/html/emacs-devel/2023-03/msg00673.html),
> no, it wouldn't work.

Strictly speaking, he was referring to removing `declare-function',
without replacing it with anything else.  Replacing that with

  (eval-when-compile (require 'treesit))
        ^
        or "eval-and-compile"?

would be a different matter, since that file contains all the treesit
definitions, which I *believe* should be inherited by the requiring
file.

> [ Also, for some reason I cannot find the message using the msgid,
> 83ilezegs1.fsf@gnu.org? ]

[ I could access the message, but I am accessing the list via NNTP ]



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

* Re: Would (Eval-when-compile (require 'treesit)) eliminate the need for (declare-function)s?
  2023-04-17  3:12 Would (Eval-when-compile (require 'treesit)) eliminate the need for (declare-function)s? Yuan Fu
  2023-04-17  3:31 ` Ruijie Yu via Emacs development discussions.
@ 2023-04-17 17:05 ` Eli Zaretskii
  2023-04-17 17:25   ` Stefan Monnier
  1 sibling, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2023-04-17 17:05 UTC (permalink / raw)
  To: Yuan Fu, Lars Ingebrigtsen, Stefan Monnier; +Cc: emacs-devel

> From: Yuan Fu <casouri@gmail.com>
> Date: Sun, 16 Apr 2023 20:12:22 -0700
> 
> 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? Should we do that?

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.

Lars, Stefan: WDYT?



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

* Re: Would (Eval-when-compile (require 'treesit)) eliminate the need for (declare-function)s?
  2023-04-17 17:05 ` Eli Zaretskii
@ 2023-04-17 17:25   ` Stefan Monnier
  2023-04-17 17:39     ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2023-04-17 17:25 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Yuan Fu, Lars Ingebrigtsen, emacs-devel

>> 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




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

* Re: Would (Eval-when-compile (require 'treesit)) eliminate the need for (declare-function)s?
  2023-04-17 17:25   ` Stefan Monnier
@ 2023-04-17 17:39     ` Eli Zaretskii
  2023-04-18 17:46       ` Yuan Fu
  0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2023-04-17 17:39 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: casouri, larsi, emacs-devel

> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Cc: Yuan Fu <casouri@gmail.com>,  Lars Ingebrigtsen <larsi@gnus.org>,
>   emacs-devel@gnu.org
> Date: Mon, 17 Apr 2023 13:25:26 -0400
> 
> > 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`.

That's what I'm not sure about.



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

* Re: Would (Eval-when-compile (require 'treesit)) eliminate the need for (declare-function)s?
  2023-04-17 17:39     ` Eli Zaretskii
@ 2023-04-18 17:46       ` Yuan Fu
  0 siblings, 0 replies; 7+ messages in thread
From: Yuan Fu @ 2023-04-18 17:46 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Stefan Monnier, larsi, emacs-devel

> 
> 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?

Not quite IMO, see below.

>> 
>>> 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`.
> 
> That's what I'm not sure about.

If emacs isn’t built with tree-sitter it doesn’t make much sense to use functions in treesit.c anyway. The real problem is that some files need to be byte-compiled even when emacs isn’t built with tree-sitter. And it’s easy to miss adding declare-function’s. 

Is there any other way to help the situation that we can do in Lisp? Ie, without making all functions always defined in treesit.c? Because I played it in my head a bit, and it looks really messy.

Yuan


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

end of thread, other threads:[~2023-04-18 17:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-17  3:12 Would (Eval-when-compile (require 'treesit)) eliminate the need for (declare-function)s? Yuan Fu
2023-04-17  3:31 ` Ruijie Yu via Emacs development discussions.
2023-04-17 13:29   ` Philip Kaludercic
2023-04-17 17:05 ` Eli Zaretskii
2023-04-17 17:25   ` Stefan Monnier
2023-04-17 17:39     ` Eli Zaretskii
2023-04-18 17:46       ` Yuan Fu

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.