Yet another Fennel shim for Neovim.
A tiny(iest?) Fennel shim.
I was really curious to see what does it take to do it, specifically: what is the least amount of work you needed to do.
That, and I wanted to write it in Fennel itself, as much as possible 😎
Inspired by Moonwalk.
It adds a fennel loader to package.loaders
and it hooks up to SourceCmd
for
*.fnl
so it can resolve :source
and :runtime
commands.
It also adds a caching layer on top of that. That's it.
Get it in your rtp
"somehow" (use your plugin manager, git clone it, whatever)
and then load it before you attempt to run any .fnl
code. You can see an example
of being used here.
What works:
require()
any<rtp>/fnl/**/*.fnl
(from either Lua or Fennel);:source
fennel scripts;<rtp>[/after]/plugin/**/*.fnl
automatic loading;- optional
<rtp>/ftplugin/*.fnl
filetype plugin loading (see below); - all requests are logged to
stdpath("cache")/fennel-shim.log
, and the logfile is flushed async, every 1s; - caching so that the fennel compile price is only paid once.
You can see it in action here, where it loads all my ~700LOC config files, as well as my four plugins and one colorscheme.
Support for ftplugin is disabled by default as it is costly. You can enable it
by setting vim.g.fennel_shim_ftplugin
to either true or any valid pattern
for autocmd
(see :he {aupat}
).
The :colorscheme
command is hardwired to look for colors/<colorscheme>.{vim,lua}
which obviously excludes .fnl files. There is also no event similar to SourceCmd
to hook up to. That means one line of lua code is required, to load the rest of the
fennel color scheme. See froggy for an example.
It is only 1.1 times slower than Hotpot (which is what I've been previously using).
Benchmark was done by running nvim --startuptime x +q
10 times for each.
I got a 196ms avg. startup time with Hotpot and 224ms with this shim.
At the same time it is only ~100LOC, not counting blank lines, vs. +6.3KLOC for Hotpot.