conjure

:neovim:+:clj: https://github.com/Olical/conjure - If you're enjoying Conjure and want to say thanks: https://github.com/users/Olical/sponsorship :smile: (alt https://conjure.fun/discord)
martinklepsch 2020-05-29T23:57:43.125700Z

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.

Olical 2020-05-30T11:15:34.129500Z

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.

Olical 2020-05-30T11:19:29.130300Z

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.

martinklepsch 2020-05-30T11:20:26.130500Z

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

Olical 2020-05-30T11:26:55.130800Z

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.

martinklepsch 2020-05-30T11:28:14.131100Z

Yeah that sounds like what I want.

Olical 2020-05-30T11:28:25.131300Z

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

Olical 2020-05-30T11:28:43.131500Z

Fennel + Aniseed is a specialisation of Fennel. It makes life easier as long as it fits your tradeoffs.

martinklepsch 2020-05-30T11:28:50.131700Z

An Aniseed question: in the README it shows syntax like module and defn — where is that coming from?

Olical 2020-05-30T11:29:04.131900Z

That's magically added via macros that are auto defined

Olical 2020-05-30T11:29:09.132100Z

You have them already ☺️

martinklepsch 2020-05-30T11:30:03.132300Z

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

martinklepsch 2020-05-30T11:30:43.132500Z

> 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

Olical 2020-05-30T11:31:08.132700Z

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

Olical 2020-05-30T11:31:27.132900Z

So the module macros translate to vanilla Lua modules

Olical 2020-05-30T11:32:10.133200Z

Defn is just fn and local with some extra stuff to ensure it's exported properly

martinklepsch 2020-05-30T11:32:36.133400Z

With hs I can get a Lua REPL into the hammerspoon env it seems

Olical 2020-05-30T11:33:02.133600Z

Ah interesting

Olical 2020-05-30T11:33:15.133800Z

So maybe compiling fennel to Lua then firing that at something else would be good

martinklepsch 2020-05-30T11:33:57.134Z

$ hs -c 'require("fennel")'
table: 0x60000185f8c0
$ hs -c 'require("fennelview")'
function: 0x600002ebf570
this works!

Olical 2020-05-30T11:34:36.134400Z

Oh nice!

martinklepsch 2020-05-30T11:35:06.134600Z

But I’m not sure how to translate that into a “connection” that I could use from conjure :thinking_face:

martinklepsch 2020-05-30T11:36:47.134800Z

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

martinklepsch 2020-05-30T11:38:40.135Z

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

Olical 2020-05-30T11:39:21.135200Z

Yeah, so the output is a common problem with things that aren't nREPL like etc

Olical 2020-05-30T11:39:35.135400Z

The Janet client has this issue but it's really not that big of a deal

Olical 2020-05-30T11:39:38.135600Z

It's still workable

Olical 2020-05-30T11:40:01.135800Z

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"

Olical 2020-05-30T11:40:07.136Z

Which could be a great option to have!

Olical 2020-05-30T11:41:29.136200Z

So a direct "run fennel in this repl" and another step you can add in for compile then run as Lua.

Olical 2020-05-30T11:42:11.136400Z

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:

Olical 2020-05-30T11:42:31.136600Z

Then you can just ignore the fennel macros if you wanna

martinklepsch 2020-05-30T11:43:27.136800Z

> 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

martinklepsch 2020-05-30T11:45:45.137200Z

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

martinklepsch 2020-05-30T11:50:49.137500Z

Maybe we can also just start something like janet’s netrepl inside hammerspoon? :thinking_face:

martinklepsch 2020-05-30T11:53:19.137700Z

I guess jeejah might be just what we need? https://gitlab.com/technomancy/jeejah

martinklepsch 2020-05-30T12:36:57.138Z

I have an nREPL server running inside hammerspoon!

Olical 2020-05-30T12:37:38.138200Z

Ooo! Interesting! For Lua? Or fennel?

Olical 2020-05-30T12:38:29.138400Z

I could abstract some of the Clojure nREPL stuff out and reuse it for fennel in that case!

martinklepsch 2020-05-30T12:39:20.138600Z

For Fennel using jeejah above

martinklepsch 2020-05-30T12:39:42.138800Z

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

Olical 2020-05-30T12:40:33.139Z

Neat! Well I could definitely implement a fennel nREPL client!

martinklepsch 2020-05-30T12:46:53.139200Z

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

martinklepsch 2020-05-30T12:48:33.139400Z

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 🙂

Olical 2020-05-30T13:11:57.139800Z

I'm afraid not, is it just an nREPL client?

Olical 2020-05-30T13:12:08.140Z

I'm currently doing a puzzle with my partner 😄

Olical 2020-05-30T13:12:33.140200Z

Alongside fennel over nREPL I'm considering a generic nREPL client as well as a generic stdio one

martinklepsch 2020-05-30T13:13:11.140400Z

Yeah that sounds reasonable. Enjoy the puzzling! 🙂