Skip to content

Commit

Permalink
Emacs text registers (#1643)
Browse files Browse the repository at this point in the history
* New methods to create "register save" and "register insert" commands that play nicely with existing Rect-related commands

* New methods to create "register save" and "register insert" commands that play nicely with existing Rect-related commands

* - Changed TextRegister class to be a simple Map<string, string>
- Changed vscode.window.showInformationMessage() to MessageManager.showMessage()
- Made RegisterSaveCommand de-select the selection after saving the selection

* Removed commented region

* Per feedback - refactoring text registers to be shared across multiple document windows (multiple EmacsEmulator objects)

* - Removed extraneous not-in-vanilla-Emacs messages
- Made startRegisterSaveCommand() private
- Made textEditor.edit((editBuilder) ...) use await in saveRegister() method
  • Loading branch information
justinhopkins authored Sep 12, 2023
1 parent 320f87c commit 42fda5b
Show file tree
Hide file tree
Showing 8 changed files with 1,735 additions and 3 deletions.
6 changes: 6 additions & 0 deletions keybinding-generator/cli.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
generateKeybindings,
generateKeybindingsForPrefixArgument,
generateKeybindingsForTypeCharInRectMarkMode,
generateKeybindingsForRegisterCommands,
} from "./generate-keybindings.mjs";

const srcFilePath = "./keybindings.json";
Expand All @@ -32,6 +33,11 @@ keybindingSrcs.forEach((keybindingSrc) => {
dstKeybindings.push(...generateKeybindingsForTypeCharInRectMarkMode());
return;
}
if (keybindingSrc.$special == "registerCommandTypes") {
console.log("Adding keybindings for register commands");
dstKeybindings.push(...generateKeybindingsForRegisterCommands());
return;
}

if (!isKeyBindingSource(keybindingSrc)) {
throw new Error(`${JSON.stringify(keybindingSrc)} is not a valid source`);
Expand Down
31 changes: 31 additions & 0 deletions keybinding-generator/generate-keybindings.mts
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,34 @@ export function generateKeybindingsForTypeCharInRectMarkMode(): KeyBinding[] {

return keybindings;
}

export function generateKeybindingsForRegisterCommands(): KeyBinding[] {
const keybindings: KeyBinding[] = [];

// Ascii all printable characters excluding delete.
// Ref: https://www.ascii-code.com/
const asciiPrintableChars: string[] = [];
// ' ' ~ '~'
for (let charCode = 0x20; charCode <= 0x7e; charCode++) {
asciiPrintableChars.push(String.fromCharCode(charCode));
}

for (const char of asciiPrintableChars) {
keybindings.push({
key: char,
when: "emacs-mcx.acceptingRectCommand && editorTextFocus && emacs-mcx.inRegisterSaveMode",
command: "emacs-mcx.RegisterSaveCommand",
args: [char],
});
}

for (const char of asciiPrintableChars) {
keybindings.push({
key: char,
when: "emacs-mcx.acceptingRectCommand && editorTextFocus && emacs-mcx.inRegisterInsertMode",
command: "emacs-mcx.RegisterInsertCommand",
args: [char],
});
}
return keybindings;
}
13 changes: 13 additions & 0 deletions keybindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,19 @@
"command": "emacs-mcx.killRectangle",
"when": "emacs-mcx.acceptingRectCommand && editorTextFocus"
},
{
"key": "s", // ctrl+x r s
"command": "emacs-mcx.StartRegisterSaveCommand",
"when": "emacs-mcx.acceptingRectCommand && editorTextFocus"
},
{
"key": "i", // ctrl+x r i
"command": "emacs-mcx.StartRegisterInsertCommand",
"when": "emacs-mcx.acceptingRectCommand && editorTextFocus"
},
{
"$special": "registerCommandTypes"
},
{
"key": "y", // ctrl+x r y
"command": "emacs-mcx.yankRectangle",
Expand Down
Loading

0 comments on commit 42fda5b

Please sign in to comment.