I’m seeing an odd issue where I’m not sure if it’s a fennel or a Conjure thing: In vim open this in a file and run forms 1 by 1
(local bindings []) ; making this global fixes it
(tset bindings :a 1) ; ERROR: unknown global in strict mode: bindings
In a `fennel` REPL it works with local
too.I think it's because each fennel eval like this (not in a repl) gets an entirely new context, I don't think I can feed into a repl but I can have a dig! The solution I'd suggest is to use Aniseeds def macros. It's documented in Aniseeds help and Conjure's fennel + aniseed client. Basically I've implemented a clojure like module system but you have to buy in with def, defn, def-, defn-, defonce etc. I could implement fennel over a stdio repl as a separate client which would allow you to use local and fn in vanilla fennel BUT it would mean no file based namespace contexts to switch between. It's like copying and pasting forms into a repl.
I'll have a look to see if I can get a best of both worlds type thing. I just wanted to provide proper namespaces since fennel doesn't have them. If I add a plain stdio fennel client (which could be run outside of Neovim Lua) then you can use local no problem, it'll just have no context switching as you change buffers. It's all one big REPL environment then. aniseed introduces the concept of files and modules, it just doesn't work with the plain Lua locals.
I see! I’ll take a closer look at Aniseed then. I’m currently writing Fennel to drive Hammerspoon (a Mac automation app) but it tricky to get a REPL to work https://github.com/Hammerspoon/hammerspoon/issues/2377
Ah okay! So aniseed is mainly my solution to vim plugins with fennel, so the choices I made definitely help with building these sorts of apps. You would almost definitely benefit from booting up a regular fennel repl over a luajit or lua binary runtime installed on your machine. Conjure + Aniseed runs it inside Neovim which is a little less free (but so damn good for plugins) So if I implement a fennel over stdio client that lets you configure the startup command for the REPL you'd probably have a much better time. It'd work like the Janet one does in a way. So swapping files means nothing to fennel but you can just eval your whole file whenever you want. It's like a regular repl with nice vim interaction at that point.
Yeah that sounds like what I want.
Would having a regular fennel stdio process booted by a custom command be enough for you then? It's something I was planning to do at some point anyway
Fennel + Aniseed is a specialisation of Fennel. It makes life easier as long as it fits your tradeoffs.
An Aniseed question: in the README it shows syntax like module
and defn
— where is that coming from?
That's magically added via macros that are auto defined
You have them already ☺️
I see! I love that stuff but I’m also a little worried about the impact it has on portability, e.g. running this code inside a non-vim process
> Would having a regular fennel stdio process booted by a custom command be enough for you then? It’s something I was planning to do at some point anyway I’m not quite sure yet, the hammerspoon hs.ipc API is a little unclear to me still but I haven’t looked at it very much
Of course, that's a valid concern. But bear in mind aniseed isn't tied to nvim, you can compile aniseed flavoured fennel from anywhere
So the module macros translate to vanilla Lua modules
Defn is just fn and local with some extra stuff to ensure it's exported properly
With hs
I can get a Lua REPL into the hammerspoon env it seems
Ah interesting
So maybe compiling fennel to Lua then firing that at something else would be good
$ hs -c 'require("fennel")'
table: 0x60000185f8c0
$ hs -c 'require("fennelview")'
function: 0x600002ebf570
this works!Oh nice!
But I’m not sure how to translate that into a “connection” that I could use from conjure :thinking_face:
I guess it’d need to
1. take form from eval binding like eb
2. compile to lua
3. pipe into hs -c
4. print result as output
There doesn’t seem a noticeable distinction between print output and a return value:
$ hs -c 'print("abc") return "asd"'
abc
asd
This is probably fine (?)Yeah, so the output is a common problem with things that aren't nREPL like etc
The Janet client has this issue but it's really not that big of a deal
It's still workable
And you're right, you'd need an option to be like "do you send fennel directly, or do you compile it to Lua then send it"
Which could be a great option to have!
So a direct "run fennel in this repl" and another step you can add in for compile then run as Lua.
Hmmmm. Maybe the current aniseed one can do this. Is just need to swap from eval to compile and then give you an option for where the Lua should be evaluated instead of inside Neovim :thinking_face:
Then you can just ignore the fennel macros if you wanna
> So a direct “run fennel in this repl” and another step you can add in for compile then run as Lua.
With your nvim-local-fennel I guess it would even be possible to set up a little hook to compile the .lua
files when saving a buffer
I think this would be really awesome, there’s already a bunch of people that use Fennel to drive Hammerspoon, just one example being https://github.com/agzam/spacehammer
Maybe we can also just start something like janet’s netrepl inside hammerspoon? :thinking_face:
I guess jeejah might be just what we need? https://gitlab.com/technomancy/jeejah
I have an nREPL server running inside hammerspoon!
Ooo! Interesting! For Lua? Or fennel?
I could abstract some of the Clojure nREPL stuff out and reuse it for fennel in that case!
For Fennel using jeejah above
I’m now trying to get shevek to work to test this but not having much luck https://git.sr.ht/~technomancy/shevek/tree/master/README.md
Neat! Well I could definitely implement a fennel nREPL client!
That could be good, yeah! Do you by any chance have an idea how one is meant to run shevek
? https://git.sr.ht/~technomancy/shevek/tree/master/README.md
Also asked in #fennel but thought maybe you have a quick idea 😄 If you’re enjoying your Saturday doing other things than sitting in front of a computer then please don’t worry about it all 🙂
I'm afraid not, is it just an nREPL client?
I'm currently doing a puzzle with my partner 😄
Alongside fennel over nREPL I'm considering a generic nREPL client as well as a generic stdio one
Yeah that sounds reasonable. Enjoy the puzzling! 🙂