Skip to content

Commit f1f93e5

Browse files
committed
Support 'context' on 'execute()'
1 parent d018c5d commit f1f93e5

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

execute.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
import { Denops } from "./deps.ts";
1+
import { Context, Denops } from "./deps.ts";
22

33
/**
44
* Execute Vim script directly
55
*/
66
export async function execute(
77
denops: Denops,
88
command: string | string[],
9+
context: Context = {},
910
): Promise<void> {
1011
if (Array.isArray(command)) {
11-
await denops.cmd("call execute(l:command, '')", {
12-
command: command
12+
context = {
13+
...context,
14+
__denops_internal_command: command
1315
.map((x) => x.replace(/^\s+|\s+$/g, ""))
1416
.filter((x) => !!x),
15-
});
17+
};
18+
await denops.cmd("call execute(l:__denops_internal_command, '')", context);
1619
return;
1720
}
1821
command = command.replace(/\r?\n\s*\\/g, "");
19-
await execute(denops, command.split(/\r?\n/g));
22+
await execute(denops, command.split(/\r?\n/g), context);
2023
}

vim.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ export class Vim {
3939
return await this.#denops.eval(expr, context);
4040
}
4141

42-
async execute(command: string | string[]): Promise<void> {
43-
await execute(this.#denops, command);
42+
async execute(
43+
command: string | string[],
44+
context: Context = {},
45+
): Promise<void> {
46+
await execute(this.#denops, command, context);
4447
}
4548

4649
async autocmd(

0 commit comments

Comments
 (0)