Extending Calva with a REPL function

Hi.

Background (you can skip reading this part)

In the last few weeks, a few of us started using Notespace for literate programming.
In Emacs+Cider, it is easy to interact with Notespace, as we can comfortably bind keys to Notespace API function calls, and even provide these calls with the important information of what line the cursor is in.
We want to create a more complete Notespace story for Calva as well. This brings us to the following question.

The question

  • We want to create a Calva keybinding that saves the file and then runs (f) in the REPL, for a pre-configured function f.
  • We want to create a Calva keybinding that saves the file and then runs (f nsp line) in the REPL, for a pre-configured function f, where nsp and line are external parameters passed by Calva, with the information of the current namespace and the current line where the cursor lies in the file.

How would it be?
Do we need to compile edit Calva’s code and rebuild it, for this kind of extension?

3 Likes

@PEZ I hope it is ok I am asking here. Since this might become a long-term topic, I preferred to avoid Slack. Since this is not exactly a Calva issue, I wasn’t sure about using the Github Issues. Please tell me if it is better to ask elsewhere.

1 Like

This probably needs updating Calva’s code snippet functionality. (Or something separate from that, but it is what comes to mind. I would welcome a feature request on the repo. And of course also PRs.

I have this feeling we could leverage sci quite a bit and come much closer to Emacs configurability. But that’s maybe a separate issue. =)

1 Like

Many thanks @PEZ.

Feature request:

1 Like

You might want to take a look at Clover and talk to Mauricio if you haven’t already. I switched from Atom to VS Code once he had Clover working the same way as Chlorine with the full customization via user-space ClojureScript code (running via sci). All of my REBL/tap> (Reveal) integration is done that way.

3 Likes

Thanks @seancorfield!

Yes, we are interested in Notespace integration for Atom Chlorine and VSCode Clover as well.
Indeed the customization flexibility there seems promising.

Would it be possible to use a separate nrepl connection? Instead of updating existing plugins, write a plugin that connects to the same repl and does what you want? It looks like Notespace displays to a browser, so you might be able to create a web view for it.

Not a solution to the original requirement but an alternative aproach to consider:
use external file watcher that would connect to the repl and eval an expression

  • there are different watchers with configurable file filters
  • there are different ways to connect to a repl (socket repl, nrepl)
  • does not depend on a specific editor

I’ve used this approach to run unit test when file is saved: https://gist.github.com/nbardiuk/cdc78162b0de0d684ed0f3272a152b36

@Richard_Heller thanks, I’m not sure if I understood your plan. Maybe this is my ignorance about Calva. Could you explain how the additional REPL helps?

@nbardiuk wonderful, thank you. Indeed we use this approach in Notespace to provide an editor-agnostic mode of usage (a bit underdocumented at the moment). But editor integration seems to provide finer control on the users’s side in a more direct fashion, so we want to gradually bring this support to various editors.

Not an additional REPL, an additional connection to the same REPL. I believe Calva says what port the REPL it’s using is on, so you should be able to grab that port and connect to it.

1 Like

Oh I see, thanks @Richard_Heller.

Thanks to @Carsten_Behring we’ll soon be shipping a change to Calva’s custom command snippets making the current line (and some other editor info) available to the snippets. As far as I understand things this should make the workflow you need there possible. Minus the autosave.

The PR: https://github.com/BetterThanTomorrow/calva/pull/877

1 Like

Thanks for the quick help, @Carsten_Behring and @PEZ!

VS code has a “autosave” function, which works fine for the notespace case.

1 Like

Almost forgot to update. This is now released. Please let us know if there is something more that Calva should do to support interactive workflows.

1 Like

Many thanks again @PEZ!

Update to inform that we now have improved on the Custom REPL commands quite a bit.

It should benefit the workflow requested in this post, I think.

1 Like