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

Rename EmacsCommand.execute() to .run() and remove the old abstract .run() #1746

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/commands/add-selection-to-find-match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { EmacsCommand } from ".";
export class AddSelectionToNextFindMatch extends EmacsCommand {
public readonly id = "addSelectionToNextFindMatch";

public execute(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<void> {
public run(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<void> {
this.emacsController.enterMarkMode(false);
return vscode.commands.executeCommand<void>("editor.action.addSelectionToNextFindMatch");
}
Expand All @@ -14,7 +14,7 @@ export class AddSelectionToNextFindMatch extends EmacsCommand {
export class AddSelectionToPreviousFindMatch extends EmacsCommand {
public readonly id = "addSelectionToPreviousFindMatch";

public execute(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<void> {
public run(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<void> {
this.emacsController.enterMarkMode(false);
return vscode.commands.executeCommand<void>("editor.action.addSelectionToPreviousFindMatch");
}
Expand Down
18 changes: 3 additions & 15 deletions src/commands/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ function hasNonEmptySelection(textEditor: TextEditor): boolean {
export class TransformToUppercase extends EmacsCommand {
public readonly id = "transformToUppercase";

public async execute(
textEditor: TextEditor,
isInMarkMode: boolean,
prefixArgument: number | undefined,
): Promise<void> {
public async run(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Promise<void> {
if (!hasNonEmptySelection(textEditor)) {
await this.emacsController.runCommand("forwardWord");
}
Expand All @@ -24,11 +20,7 @@ export class TransformToUppercase extends EmacsCommand {
export class TransformToLowercase extends EmacsCommand {
public readonly id = "transformToLowercase";

public async execute(
textEditor: TextEditor,
isInMarkMode: boolean,
prefixArgument: number | undefined,
): Promise<void> {
public async run(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Promise<void> {
if (!hasNonEmptySelection(textEditor)) {
await this.emacsController.runCommand("forwardWord");
}
Expand All @@ -39,11 +31,7 @@ export class TransformToLowercase extends EmacsCommand {
export class TransformToTitlecase extends EmacsCommand {
public readonly id = "transformToTitlecase";

public async execute(
textEditor: TextEditor,
isInMarkMode: boolean,
prefixArgument: number | undefined,
): Promise<void> {
public async run(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Promise<void> {
if (!hasNonEmptySelection(textEditor)) {
await this.emacsController.runCommand("forwardWord");
}
Expand Down
6 changes: 1 addition & 5 deletions src/commands/delete-blank-lines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import { EmacsCommand } from ".";
export class DeleteBlankLines extends EmacsCommand {
public readonly id = "deleteBlankLines";

public async execute(
textEditor: TextEditor,
isInMarkMode: boolean,
prefixArgument: number | undefined,
): Promise<void> {
public async run(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Promise<void> {
const document = textEditor.document;

for (let iSel = 0; iSel < textEditor.selections.length; ++iSel) {
Expand Down
10 changes: 3 additions & 7 deletions src/commands/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { delay } from "../utils";
export class DeleteBackwardChar extends EmacsCommand {
public readonly id = "deleteBackwardChar";

public execute(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<unknown> {
public run(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<unknown> {
const repeat = prefixArgument === undefined ? 1 : prefixArgument;
return makeParallel(repeat, () => vscode.commands.executeCommand("deleteLeft"));
}
Expand All @@ -16,7 +16,7 @@ export class DeleteBackwardChar extends EmacsCommand {
export class DeleteForwardChar extends EmacsCommand {
public readonly id = "deleteForwardChar";

public execute(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<void> {
public run(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<void> {
const repeat = prefixArgument === undefined ? 1 : prefixArgument;
return makeParallel(repeat, () =>
vscode.commands.executeCommand<void>("deleteRight"),
Expand All @@ -27,11 +27,7 @@ export class DeleteForwardChar extends EmacsCommand {
export class NewLine extends EmacsCommand {
public readonly id = "newLine";

public async execute(
textEditor: TextEditor,
isInMarkMode: boolean,
prefixArgument: number | undefined,
): Promise<void> {
public async run(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Promise<void> {
this.emacsController.exitMarkMode();

textEditor.selections = textEditor.selections.map((selection) => new Selection(selection.active, selection.active));
Expand Down
16 changes: 8 additions & 8 deletions src/commands/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ abstract class IsearchCommand extends EmacsCommand {
export class IsearchForward extends IsearchCommand {
public readonly id = "isearchForward";

public execute(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<void> {
public run(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<void> {
this.searchState.startSelections = textEditor.selections;

return this.openFindWidget({ isRegex: false }).then(() =>
Expand All @@ -75,7 +75,7 @@ export class IsearchForward extends IsearchCommand {
export class IsearchBackward extends IsearchCommand {
public readonly id = "isearchBackward";

public execute(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<void> {
public run(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<void> {
this.searchState.startSelections = textEditor.selections;
return this.openFindWidget({ isRegex: false }).then(() =>
vscode.commands.executeCommand<void>("editor.action.previousMatchFindAction"),
Expand All @@ -86,7 +86,7 @@ export class IsearchBackward extends IsearchCommand {
export class IsearchForwardRegexp extends IsearchCommand {
public readonly id = "isearchForwardRegexp";

public execute(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<void> {
public run(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<void> {
this.searchState.startSelections = textEditor.selections;
return this.openFindWidget({ isRegex: true }).then(() =>
vscode.commands.executeCommand<void>("editor.action.nextMatchFindAction"),
Expand All @@ -97,7 +97,7 @@ export class IsearchForwardRegexp extends IsearchCommand {
export class IsearchBackwardRegexp extends IsearchCommand {
public readonly id = "isearchBackwardRegexp";

public execute(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<void> {
public run(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<void> {
this.searchState.startSelections = textEditor.selections;
return this.openFindWidget({ isRegex: true }).then(() =>
vscode.commands.executeCommand<void>("editor.action.previousMatchFindAction"),
Expand All @@ -108,7 +108,7 @@ export class IsearchBackwardRegexp extends IsearchCommand {
export class QueryReplace extends IsearchCommand {
public readonly id = "queryReplace";

public execute(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<void> {
public run(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<void> {
this.searchState.startSelections = textEditor.selections;
// I could not find a way to open the find widget with `editor.actions.findWithArgs`
// revealing the replace input and restoring the both query and replace strings.
Expand All @@ -120,7 +120,7 @@ export class QueryReplace extends IsearchCommand {
export class QueryReplaceRegexp extends IsearchCommand {
public readonly id = "queryReplaceRegexp";

public execute(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<void> {
public run(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<void> {
this.searchState.startSelections = textEditor.selections;
// Like `queryReplace` command, I could not find a way to open the find widget with the desired state.
// In this command, setting `isRegex` is the priority and I gave up restoring the replace string by setting ´replaceString=undefined`.
Expand All @@ -134,7 +134,7 @@ export class QueryReplaceRegexp extends IsearchCommand {
export class IsearchAbort extends IsearchCommand {
public readonly id = "isearchAbort";

public execute(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<void> {
public run(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<void> {
if (this.searchState.startSelections) {
textEditor.selections = this.searchState.startSelections;
}
Expand All @@ -150,7 +150,7 @@ export class IsearchAbort extends IsearchCommand {
export class IsearchExit extends IsearchCommand {
public readonly id = "isearchExit";

public execute(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<void> {
public run(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<void> {
if (this.searchState.startSelections) {
this.emacsController.pushMark(this.searchState.startSelections.map((selection) => selection.anchor));
MessageManager.showMessage("Mark saved where search started");
Expand Down
10 changes: 1 addition & 9 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,7 @@ export abstract class EmacsCommand {
this.emacsController = markModeController;
}

public run(
textEditor: TextEditor,
isInMarkMode: boolean,
prefixArgument: number | undefined,
): Thenable<unknown> | void {
return this.execute(textEditor, isInMarkMode, prefixArgument);
}

public abstract execute(
public abstract run(
textEditor: TextEditor,
isInMarkMode: boolean,
prefixArgument: number | undefined,
Expand Down
40 changes: 8 additions & 32 deletions src/commands/kill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ function findNextKillWordRange(doc: TextDocument, position: Position, repeat = 1
export class KillWord extends KillYankCommand {
public readonly id = "killWord";

public async execute(
textEditor: TextEditor,
isInMarkMode: boolean,
prefixArgument: number | undefined,
): Promise<void> {
public async run(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Promise<void> {
const repeat = prefixArgument === undefined ? 1 : prefixArgument;
if (repeat <= 0) {
return;
Expand Down Expand Up @@ -85,11 +81,7 @@ function findPreviousKillWordRange(doc: TextDocument, position: Position, repeat
export class BackwardKillWord extends KillYankCommand {
public readonly id = "backwardKillWord";

public async execute(
textEditor: TextEditor,
isInMarkMode: boolean,
prefixArgument: number | undefined,
): Promise<void> {
public async run(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Promise<void> {
const repeat = prefixArgument === undefined ? 1 : prefixArgument;
if (repeat <= 0) {
return;
Expand All @@ -106,7 +98,7 @@ export class BackwardKillWord extends KillYankCommand {
export class KillLine extends KillYankCommand {
public readonly id = "killLine";

public execute(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<void> {
public run(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<void> {
const killWholeLine = Configuration.instance.killWholeLine;

const ranges = textEditor.selections.map((selection) => {
Expand Down Expand Up @@ -139,7 +131,7 @@ export class KillLine extends KillYankCommand {
export class KillWholeLine extends KillYankCommand {
public readonly id = "killWholeLine";

public execute(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<void> {
public run(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Thenable<void> {
const ranges = textEditor.selections.map(
(selection) =>
// From the beginning of the line to the beginning of the next line
Expand All @@ -153,11 +145,7 @@ export class KillWholeLine extends KillYankCommand {
export class KillRegion extends KillYankCommand {
public readonly id = "killRegion";

public async execute(
textEditor: TextEditor,
isInMarkMode: boolean,
prefixArgument: number | undefined,
): Promise<void> {
public async run(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Promise<void> {
const selectionsAfterRectDisabled =
this.emacsController.inRectMarkMode &&
this.emacsController.nativeSelections.map((selection) => {
Expand All @@ -182,11 +170,7 @@ export class KillRegion extends KillYankCommand {
export class CopyRegion extends KillYankCommand {
public readonly id = "copyRegion";

public async execute(
textEditor: TextEditor,
isInMarkMode: boolean,
prefixArgument: number | undefined,
): Promise<void> {
public async run(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Promise<void> {
const ranges = getNonEmptySelections(textEditor);
await this.killYanker.copy(ranges);
this.emacsController.exitMarkMode();
Expand All @@ -199,11 +183,7 @@ export class CopyRegion extends KillYankCommand {
export class Yank extends KillYankCommand {
public readonly id = "yank";

public async execute(
textEditor: TextEditor,
isInMarkMode: boolean,
prefixArgument: number | undefined,
): Promise<void> {
public async run(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Promise<void> {
this.emacsController.pushMark(textEditor.selections.map((selection) => selection.active));
await this.killYanker.yank();
this.emacsController.exitMarkMode();
Expand All @@ -214,11 +194,7 @@ export class Yank extends KillYankCommand {
export class YankPop extends KillYankCommand {
public readonly id = "yankPop";

public async execute(
textEditor: TextEditor,
isInMarkMode: boolean,
prefixArgument: number | undefined,
): Promise<void> {
public async run(textEditor: TextEditor, isInMarkMode: boolean, prefixArgument: number | undefined): Promise<void> {
await this.killYanker.yankPop();
this.emacsController.exitMarkMode();
revealPrimaryActive(textEditor);
Expand Down
Loading
Loading