This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-02-11
Channels
I have a bunch of things like this in my keybindings.json
{ "key": "ctrl+t ctrl+t",
"command": "calva.runCustomREPLCommand",
"args": "(yamltest.core/run)" },
They only seem to do stuff when a .clj
file is the active pane.
I'd like to have them trigger from any pane and I'll keep track of what clj file they were last triggered from and apply them as if they came from there.
Is this possible?Not sure what you mean with > I’ll keep track of what clj file they were last triggered from and apply them as if they came from there But otherwise I think we could make this possible. There are a lot of code paths in Calva that check if it’s a Clojure file, but I think that most often this is not necessary.
Or, most often… Anyway, it is not always necessary. And you point at a case where we shouldn’t care if it’s a Clojure file or not, I think. It will be necessary for some of what’s going on with custom repl commands (like figuring out current ns and such). But other than that we should execute the command.
I use that binding to run the tests that apply to the clj file I'm in. But the tests are defined in a YAML file. So when I change a test I need to switch to the right clj file to run it. I can keep track of the last clj file I ran tests for and use that namespace if I'm in some other file.
I'm generally just testing a single clj file for whatever I'm working on, but I might be changing any number of other files when I want to run the tests.
ok. I need to remember if I've used joyride before...
I haven't looked at the code, but looking at the docs, there are some fields for the custom REPL commands (e.g. ns, repl) that default to values associated with the current editor. Since those aren't set in this case, that could be a stumbling block (if Calva's code is checking the non-clj editor for which repl session and ns to use). I'd guess it might also be behind the "current editor is a clojure file" wall, but if it's not, then adding those props might make some commands work.
Thanks @U013JFLRFS8, I'll try that out. (Unless @U0ETXRFEW thinks it's a deadend...)
Would be cool if the ns
value could be a function that returned a namespace. :)
With Joyride it would be something like so:
{ "key": "ctrl+t ctrl+t",
"command": "joyride.runCode",
"args": "(require '[\"$v1\" :as calva]) (calva/repl.evaluateCode \"clj\" \"(yamltest.core/run)\")" }
The require is only needed once, and may be something you do on some other shortcut, or as part of your user or workspace activation script.Also, you will probably want to host most of the code in Joyride scripts, instead of in the keybinding JSON.
@U013JFLRFS8 why so?
a bit off topic, but do you know a clean way to eval a form in a particular namespace?
something like (within-ns foo (...))
(where foo
is a namespace)
I don't recall seeing anything like that before
Figured out:
user=> (binding [*ns* (the-ns 'foo.bar)] *ns*)
#namespace[foo.bar]
That's exactly what I wanted 🙂
And with the Joyride option you can provide the ns
with the Calva API call: https://calva.io/api/#replevaluatecode