Closed19

vscodeでemacsのC-sでの検索の体験を再現したい

podhmopodhmo

keyboard shortcuts

そもそもkeyboard shortcutsの設定は

  • 設定ファイル
  • 設定方法
podhmopodhmo

debug

ctrl + shift + p で Developer: Toggle Keyboard Shortcuts Troubleshooting を開くとなんか教えてくれそう

podhmopodhmo

設定ファイル

keybindings.jsonっぽい

mac: ~/Library/Application Support/Code/User/keybindings.json

// Place your key bindings in this file to override the defaults
[
    {
        "key": "ctrl+x shift+l",
        "command": "emacs-mcx.transformToLowercase",
        "when": "editorTextFocus && !editorReadonly"
    },
    {
        "key": "ctrl+x ctrl+l",
        "command": "-emacs-mcx.transformToLowercase",
        "when": "editorTextFocus && !editorReadonly"
    },
    {
        "key": "ctrl+x ctrl+l",
        "command": "workbench.action.gotoLine"
    },
    {
        "key": "ctrl+g",
        "command": "-workbench.action.gotoLine"
    },
    {
        "key": "ctrl+x shift+w",
        "command": "workbench.action.quickSwitchWindow"
    },
    {
        "key": "ctrl+oem_4 r",
        "command": "editor.action.startFindReplaceAction",
        "when": "editorFocus && !config.emacs-mcx.useMetaPrefixMacCmd"
    },
    {
        "key": "ctrl+oem_4 r",
        "command": "editor.action.startFindReplaceAction",
        "when": "editorFocus || editorIsOpen"
    },
    {
        "key": "ctrl+h",
        "command": "-editor.action.startFindReplaceAction",
        "when": "editorFocus || editorIsOpen"
    },
    {
        "key": "ctrl+oem_4 r",
        "command": "editor.action.startFindReplaceAction",
        "when": "config.emacs-mcx.useMetaPrefixMacCmd && editorFocus"
    },
    {
        "key": "ctrl+c d",
        "command": "deleteInsideWord"
    },
    {
        "key": "ctrl+c ctrl+p",
        "command": "workbench.action.previousEditor"
    },
    {
        "key": "ctrl+c ctrl+n",
        "command": "workbench.action.nextEditor"
    },
    {
        "key": "ctrl+c e",
        "command": "editor.action.insertSnippet",
        "when": "editorTextFocus",
        "args": {
            "snippet": "\"${TM_SELECTED_TEXT}\""
        }
    },
    {
        "key": "ctrl+c q",
        "command": "editor.action.commentLine",
        "when": "editorTextFocus && !editorReadonly"
    },
    {
        "key": "ctrl+oem_4 shift+oem_comma",
        "command": "cursorTop",
        "when": "textInputFocus"
    },
    {
        "key": "ctrl+oem_4 shift+oem_period",
        "command": "cursorBottom",
        "when": "textInputFocus"
    }
]
podhmopodhmo

whenってどんな種類があるんだろう?この辺?

https://code.visualstudio.com/api/references/when-clause-contexts

例えばこんな感じ

Context name True when
Editor contexts
editorFocus An editor has focus, either the text or a widget.
editorTextFocus The text in an editor has focus (cursor is blinking).
textInputFocus Any editor has focus (regular editor, debug REPL, etc.).
inputFocus Any text input area has focus (editors or text boxes).

context keyの調べ方

おそらく、Developer: Inspect Context Keys で調べられる。

https://code.visualstudio.com/api/references/when-clause-contexts#inspect-context-keys-utility

Developper: Toggle Developer Tools をする必要がある

クリックするとなんか手に入る

https://gist.github.com/podhmo/acfd54c8a29258b939ccbeddc831692a

podhmopodhmo

whenで利用できるoperator

Operator Symbol Example
Equality == ['editorLangId == typescript']
Inequality != ['resourceExtname != .js']
Or
And && ['textInputFocus && !editorReadonly']
Matches =~ ['resourceScheme =~ /^untitled$
podhmopodhmo

remove keybindingは-<name> みたいな感じで登録されるみたい。

    {
        "key": "ctrl+h",
        "command": "-emacs-mcx.deleteBackwardChar",
        "when": "editorTextFocus && !editorReadonly"
    },
    {
        "key": "ctrl+h",
        "command": "-deleteLeft",
        "when": "textInputFocus"
    }

💭 個人的にはCtrl+hでの削除を使わないし、いっそのことコマンドパレットの起動をこれにしちゃいたい。

Hidden comment
podhmopodhmo

keybindings.json がこの辺で設定されている。コマンドは自作なのかな?

https://github.com/whitphx/vscode-emacs-mcx/blob/4cd34ca6c10e5d1204cc8478c0b58f0615216b58/keybindings.json#L297-L318

podhmopodhmo

これでCtrl + s後のctrl + sで再検索が効くようになるのかな

podhmopodhmo

実際 toggle keyboard shortcuts をtraceしてみると

2024-05-30 21:31:35.542 [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl], code: KeyS, keyCode: 83, key: s
2024-05-30 21:31:35.542 [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: KeyS, keyCode: 49 ('S')
2024-05-30 21:31:35.543 [info] [KeybindingService]: | Resolving ctrl+[KeyS]
2024-05-30 21:31:35.543 [info] [KeybindingService]: \ From 3 keybinding entries, matched emacs-mcx.isearchForward, when: !findInputFocussed, source: user extension tuttieee.emacs-mcx.
2024-05-30 21:31:35.543 [info] [KeybindingService]: + Invoking command emacs-mcx.isearchForward.
2024-05-30 21:31:35.771 [info] [KeybindingService]: + Ignoring single modifier ctrl due to it being pressed together with other keys.
2024-05-30 21:31:36.361 [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl], code: ControlRight, keyCode: 17, key: Control
2024-05-30 21:31:36.361 [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: ControlRight, keyCode: 5 ('Ctrl')
2024-05-30 21:31:36.364 [info] [KeybindingService]: \ Keyboard event cannot be dispatched in keydown phase.
2024-05-30 21:31:37.161 [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl], code: KeyS, keyCode: 83, key: s
2024-05-30 21:31:37.162 [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: KeyS, keyCode: 49 ('S')
2024-05-30 21:31:37.162 [info] [KeybindingService]: | Resolving ctrl+[KeyS]
2024-05-30 21:31:37.162 [info] [KeybindingService]: \ From 3 keybinding entries, matched editor.action.nextMatchFindAction, when: findInputFocussed, source: user extension tuttieee.emacs-mcx.
2024-05-30 21:31:37.163 [info] [KeybindingService]: + Invoking command editor.action.nextMatchFindAction.
2024-05-30 21:31:37.591 [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl], code: KeyS, keyCode: 83, key: s
2024-05-30 21:31:37.592 [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: KeyS, keyCode: 49 ('S')
2024-05-30 21:31:37.592 [info] [KeybindingService]: | Resolving ctrl+[KeyS]
2024-05-30 21:31:37.592 [info] [KeybindingService]: \ From 3 keybinding entries, matched editor.action.nextMatchFindAction, when: findInputFocussed, source: user extension tuttieee.emacs-mcx.
2024-05-30 21:31:37.593 [info] [KeybindingService]: + Invoking command editor.action.nextMatchFindAction.
2024-05-30 21:31:38.017 [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl], code: KeyS, keyCode: 83, key: s
2024-05-30 21:31:38.017 [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: KeyS, keyCode: 49 ('S')
2024-05-30 21:31:38.018 [info] [KeybindingService]: | Resolving ctrl+[KeyS]
2024-05-30 21:31:38.019 [info] [KeybindingService]: \ From 3 keybinding entries, matched editor.action.nextMatchFindAction, when: findInputFocussed, source: user extension tuttieee.emacs-mcx.
このスクラップは6ヶ月前にクローズされました