whitphx / vscode-emacs-mcx

Awesome Emacs Keymap - VSCode emacs keybinding with multi cursor support
https://marketplace.visualstudio.com/items?itemName=tuttieee.emacs-mcx
Other
371 stars 64 forks source link

Add commands for block up and block down #114

Closed joeshaw closed 5 years ago

joeshaw commented 5 years ago

VSCode has block-travel.jumpUp and block-travel.selectUp and down variants. I can't quite get them to do what I want with mark mode, however.

I have keybindings:

    {
        "key": "ctrl+up",
        "command": "block-travel.jumpUp",
        "when": "editorTextFocus && !editorHasSelection"
    },
    {
        "key": "ctrl+up",
        "command": "block-travel.selectUp",
        "when": "editorTextFocus && editorHasSelection"   
    }

And this mostly works, except when I haven't started selecting anything yet.

I think what we might need are dedicated BlockUp and BlockDown commands in emacs-mcx.

Untested code:

export class BlockUpCommand extends EmacsCommand {
    public readonly id = "blockUpCommand";

    public execute(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined) {
        const repeat = prefixArgument === undefined ? 1 : prefixArgument;
        return createParallel(repeat, () =>
            vscode.commands.executeCommand(isInMarkMode ? "block-travel.selectUp" : "block-travel.jumpUp"));
    }
}

export class BlockDownCommand extends EmacsCommand {
    public readonly id = "blockDownCommand";

    public execute(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined) {
        const repeat = prefixArgument === undefined ? 1 : prefixArgument;
        return createParallel(repeat, () =>
            vscode.commands.executeCommand(isInMarkMode ? "block-travel.selectDown" : "block-travel.jumpDown"));
    }
}

I think these would be applied to C-Up and M-Up, and C-Down and M-Down in the default keybindings, respectively.

joeshaw commented 5 years ago

Alternately, is it possible to expose when mark mode is enabled for the when field of keybindings? I haven't seen any examples of that in the default keybindings, but if that were the case I'd be able to switch editorHasSelection in my keybindings above to isInMarkMode or similar.

whitphx commented 5 years ago

Hello,

is it possible to expose when mark mode is enabled for the when field of keybindings?

Yes, it's possible. Please see here: https://github.com/tuttieee/vscode-emacs-mcx#when-clause-context (sorry, it's not salient)

And this may also help you as I implemented the when context exposure for this issue and an example usage is written in the comment.

joeshaw commented 5 years ago

Thanks, I didn't realize that block-travel was an extension I must have installed. I'll try it the other way and submit a patch for the keybindings if that works. Cheers.

whitphx commented 5 years ago

I'll try it the other way and submit a patch for the keybindings if that works

Thank you! and it's more preferable to write/update the tip or manual about the usage of when context in README if it works, rather than to create a patch to make a dependency to anther extension even if it's in package.json. I appreciate your contribution!