Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Custom REPL commands with editor shortcut #281

Closed
zerg000000 opened this issue Aug 14, 2019 · 6 comments
Closed

[Feature request] Custom REPL commands with editor shortcut #281

zerg000000 opened this issue Aug 14, 2019 · 6 comments
Labels

Comments

@zerg000000
Copy link

@zerg000000 zerg000000 commented Aug 14, 2019

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?

@PEZ PEZ mentioned this issue Aug 14, 2019
@PEZ

This comment has been minimized.

Copy link
Collaborator

@PEZ PEZ commented Aug 14, 2019

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 ?

@PEZ PEZ added the enhancement label Aug 14, 2019
@kstehn

This comment has been minimized.

Copy link
Contributor

@kstehn kstehn commented Aug 14, 2019

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.

@PEZ

This comment has been minimized.

Copy link
Collaborator

@PEZ PEZ commented Aug 14, 2019

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.

@PEZ PEZ mentioned this issue Aug 15, 2019
6 of 6 tasks complete
@PEZ

This comment has been minimized.

Copy link
Collaborator

@PEZ PEZ commented Oct 4, 2019

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:

Custom REPL Commands

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 menu
  • snippet: The code that will be evaluated
  • ns: (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.

image

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.

@zerg000000

This comment has been minimized.

Copy link
Author

@zerg000000 zerg000000 commented Oct 5, 2019

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?

@PEZ

This comment has been minimized.

Copy link
Collaborator

@PEZ PEZ commented Oct 5, 2019

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.

@PEZ PEZ closed this in 31681cc Oct 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.