Skip to content

Commit d053ff7

Browse files
committed
Add 'execute' function which directly execute Vim script
1 parent c384e6a commit d053ff7

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

deps.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export type {
2+
Context,
3+
Dispatcher,
4+
} from "https://deno.land/x/denops@v0.7/mod.ts";
5+
export { Denops } from "https://deno.land/x/denops@v0.7/mod.ts";

execute.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Denops } from "./deps.ts";
2+
3+
/**
4+
* Execute Vim script directly
5+
*/
6+
export async function execute(
7+
denops: Denops,
8+
command: string | string[],
9+
): Promise<void> {
10+
if (Array.isArray(command)) {
11+
await denops.cmd("call execute(l:command, '')", {
12+
command: command
13+
.map((x) => x.replace(/^\s+|\s+$/g, ""))
14+
.filter((x) => !!x),
15+
});
16+
return;
17+
}
18+
command = command.replace(/\r?\n\s*\\/g, "");
19+
await execute(denops, command.split(/\r?\n/g));
20+
}

mod.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./execute.ts";

0 commit comments

Comments
 (0)