Skip to content

Dispatching commands with arguments #7

@savetheclocktower

Description

@savetheclocktower

Have you checked for existing feature requests?

  • Completed

Summary

In VS Code, you can pass arguments when you dispatch commands:

    {
        "key": "cmd+c",
        "command": "workbench.action.terminal.sendSequence",
        "args": {
            "text": "\u0003"
        },
        "when": "terminalFocus"
    },

In Pulsar, keymaps can associate keybindings with commands, but the commands themselves cannot take arguments:

'pulsar-terminal':
  'cmd+c': 'terminal:send-sigterm'

Ideally, terminal:send-sigterm would not have to be defined; the terminal package could instead define terminal:send-sequence and rely on the keymap to control the arguments that are passed:

'pulsar-terminal':
  'cmd+c':
    command: 'terminal:send-sequence'
    args: ['\x03']

This would be pretty straightforward to do in the code where atom-keymap interprets a keymap. It would then attach any arguments to the custom event’s detail property so that they could be read by the function that handles the dispatched command.

(It's true that we don't have a way for a command to take arguments when invoked another way, like from a context menu or the command palette. But that could be a future enhancement. As it stands, it would fall to the package author to either (a) write command handlers in such a way that they can recover when no arguments are given, or (b) exclude such commands from menu definition files and from the command palette.)

What benefits does this feature provide?

Feature parity with VS Code. Easier customization of Pulsar in scenarios that would otherwise require something more elaborate: in this case, consuming a service in init.js and defining a custom command just so it could be mapped in the user's keymap.cson.

Any alternatives?

The only alternative I can think of is the status quo: one-off commands for each possible argument. The drawbacks of this approach have already been discussed.

Other examples:

VS Code, as mentioned above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions