In Cursive, I found that "REPL Commands" is particularly useful feature. I can set a form like (refresh) (test) and ns 'user and bind a editor shortcut like CMD + R to execute it. It is very convenient , when combining with Component/Mount/Integrant.
Is it feasible to be implemented in VS Code?
Hello.
Thanks for this feedback! As mentioned in #259, this has been work in progress for quite long. Now there is a somewhat up-to-date branch here: wip/custom-commands.
I think the answer is that this is feasible, at least in some form. It will be in the form of a setting where the user can add custom code snippets and then a command to get a list of the commands to choose from. Choosing one will invoke it. The settings currently looks like this:
"calva.customCodeSnippets": [
{
"snippet": "(println \"foo\")",
"name": "Foo",
"repl": "clj",
"ns": "user"
}
],
I haven't really worked out a good way to run the command in the right namespace, even if it actually works like it is... We will need to work out the details so that it gets to be as useful as possible. If you feel like helping, please try that branch out (see How to Contribute for a guide on how to run Calva in development mode) and we can discuss from there.
I'm not sure when we would fit in work on this feature, but I think it isn't all that much work left on it and it _does_ seem to be a valuable feature. I vote for doing this soon. What say you, @kstehn ?
I mean it doesnt seem to be that complicated.
Regarding excuting the command in the right namespace i have found this small snippet
(binding [*ns* <config-ns>] <config-snippet>)
This should then execute the snippet in the correct namespace.
I don't think that binding works in ClojureScript. I think I have asked about that somewhere, but I don't remember where... But if I remember incorrectly, then that's awesome.
Here's a pre-release of Calva that supports executing custom command snippets in either the clj or the cljs REPL window:
https://github.com/BetterThanTomorrow/calva/releases/tag/v2.0.44-custom-repl-commands
Please install it and give it a try. And please provide feedback on how it works, and what you would want to work differently.
The documentation for this would look something like so:
Calva supports configuration of custom command snippets that you can execute in the REPL at will. If your workflow has you repeatedly evaluate a particular piece of code, you can use the setting calva.customREPLCommandSnippets to configure it and then use the command Run Custom REPL Command to access it. The command will give you a menu with the snippets you have configured.
The calva.customREPLCommandSnippets is an object/dictionary with the following fields:
name: The name of the snippet as it will appear in the picker menusnippet: The code that will be evaluatedns: (optional) Namespace to evaluate the command in. If omitted the command will be executed in whatever namespace the REPL window has at the moment, which probably is only useful for running code in the user namespace.replType: Which REPL window to use for the evaluation. Either "clj" or "cljs"E.g. with these settings:
"calva.customREPLCommandSnippets": [
{
"name": "Foo",
"snippet": "(println :foo)",
"ns": "acme.test.foo-test",
"repl": "cljs"
},
{
"name": "Bar",
"snippet": "(println :bar)",
"ns": "acme.test.bar-test",
"repl": "clj"
},
{
"name": "Refresh",
"snippet": "(refresh)",
"repl": "clj"
}
]
You will get this menu.

The items are numbered for you so that you can choose them in predictable way. The default keyboard shortcut for the command is ctrl+alt+c, .. Which means that to execute the Refresh command, (refresh), in the clj REPL, you could do:
ctrl+alt+c, ., 3, ENTER.
Since currently, I don't have a cljs project on hand, I am testing clj project now.
The snippet feature is awesome! I am certainly satisfied for clj part. Thanks for this new feature and Calva!
Of course, if the snippet could be binded to a normal shortcut, it would be even better! But I think it is out of scope?
Thanks for helping with testing this!
I don't think VS Code allows for the user binding each snippet to a shortcut. But with the numbering of the snippets it gets pretty close. Also, which is not mentioned in my test above, Calva remembers the choice between usages, so if you have mainly one snippet you use, you can rerun it using ctrl+alt+c, ., ENTER.