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

Bind any keys to custom custom repl commands #1853

Closed
PEZ opened this issue Sep 5, 2022 · 2 comments
Closed

Bind any keys to custom custom repl commands #1853

PEZ opened this issue Sep 5, 2022 · 2 comments
Labels
configuration repl shortcuts Related to keyboard shortcuts

Comments

@PEZ
Copy link
Collaborator

PEZ commented Sep 5, 2022

We can provide a way to run custom repl commands bound to any shortcut if we let the user specify the command snippet definition as args to the shortcut binding.

It would allow a keybinding like this:

    {
        "key": "ctrl+alt+u alt+enter",
        "command": "calva.runCustomREPLCommand",
        "args": {
            "ns": "user",
            "snippet": "$current-form"
        }
    },

This would evaluate the current form in the user namespace.

To achieve this today you need to first define a custom repl command snippet in settings, giving it some key, then bind the shortcut providing the key:

settings.json:

    "calva.customREPLCommandSnippets": [
        {
            "name": "Eval Current Form in user NS",
            "key": "eval-current-form-in-user-ns",
            "ns": "user",
            "snippet": "$current-form"
        },

keybindings.json:

    {
        "key": "ctrl+alt+u alt+enter",
        "command": "calva.runCustomREPLCommand",
        "args": "eval-current-form-in-user-ns"
    }

Another difference between the two implementations would be that with a direct shortcut binding, you will not get the snippet added to the custom repl commands menu. But you can always define it the second way, if you like.

@PEZ PEZ added repl shortcuts Related to keyboard shortcuts configuration labels Sep 5, 2022
PEZ added a commit that referenced this issue Sep 5, 2022
@PEZ PEZ mentioned this issue Sep 5, 2022
16 tasks
@skylize
Copy link
Contributor

skylize commented Sep 5, 2022

Just a note: I think (assuming other shortcuts set to default) the keyboard shortcut used in this example would better align with $top-level-form instead of $current-form.

@PEZ
Copy link
Collaborator Author

PEZ commented Sep 5, 2022

I guess you mean the alt+enter part of the chord? Makes sense.

@bpringe bpringe closed this as completed in a643465 Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
configuration repl shortcuts Related to keyboard shortcuts
Projects
None yet
Development

No branches or pull requests

2 participants