On Wed, Jan 22 2025, Thomas S. Dye wrote:
> Aloha all,
>
> I'm drafting ob-doc-forth.org and haven't been able to get ob-forth.el to
> recognize a working GForth in Spacemacs.  I get "Symbol's function
> definition is void: forth-proc" when I evaluate a Forth source block.
>
> In ob-forth.el there is this: (declare-function forth-proc "ext:gforth" ())
>
> My hunch is that the ext: part of ext:gforth expects that forth-mode is
> setup to use the forth-mode distributed with GForth.

No. `declare-function` doesn't do anything except silence the
byte-compiler. It's used when you use a function in your Elisp source that
may not be loaded into your running Emacs session while editing the .el
file. In such a case, the byte compiler cannot find the function, so it
issues a warning. With `declare-function`, you tell the byte compiler where
to look for the function. The prefix "ext:" indicates that the file is an
external file (i.e., doesn't come with Emacs), so it may not even be found
at all, and that if that happens, the byte compiler still shouldn't complain.

The important thing to note is that `declare-function` doesn't make the
function available for *running* the code, it really is meant *just* for
the byte compiler. To make sure `gforth.el` is loaded, you need to use a
`require` in your source code.

> Spacemacs appears to
> use forth-mode from Elpa, instead, and I find forth-mode.el in the elpa
> subdirectory of my Spacemacs.

The `declare-function` call says that `forth-proc` can be found in
`gforth.el`, so the fact that you have `forth-mode.el` installed is
(probably) irrelevant. What you need is the file `gforth.el`. Where it
comes from is irrelevant, it just needs to be on Emacs' `load-path`. (And
it needs to actually provide `forth-proc`, of course, and make it
autoloadable, but I assume that's the case.)

What I don't understand, though, is why there's no `(require 'gforth)` in
`ob-forth.el`. It seems that `forth-proc` is essential for running Forth
source blocks, so a `require` seems in order.

The point is that `declare-function` is usually only used to declare
functions that are optional, meaning that `ob-forth.el` should check if
it's available and gracefully handle the case where it's not.

> What is the best way forward here?

What does the documentation for `ob-forth.el` say? Does it say `gforth.el`
needs to be installed? Otherwise perhaps ask the Org mailing list or the
ob-forth maintainer directly?

-- 
Joost Kremers
Life has its moments

Reply via email to