Skip to content

Commit 964f449

Browse files
committed
Add 'start' function and 'Vim' class which is main entrypoint
1 parent 9a46095 commit 964f449

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

mod.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from "./autocmd.ts";
22
export * from "./execute.ts";
33
export * from "./variable.ts";
4+
export * from "./vim.ts";

vim.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { Context, Denops, Dispatcher } from "./deps.ts";
2+
import { execute } from "./execute.ts";
3+
import { autocmd, AutocmdHelper } from "./autocmd.ts";
4+
import { VariableHelper } from "./variable.ts";
5+
6+
export class Vim {
7+
#denops: Denops;
8+
9+
readonly g: VariableHelper;
10+
readonly b: VariableHelper;
11+
readonly w: VariableHelper;
12+
readonly t: VariableHelper;
13+
readonly v: VariableHelper;
14+
readonly env: VariableHelper;
15+
16+
constructor(denops: Denops) {
17+
this.#denops = denops;
18+
this.g = new VariableHelper(denops, "g");
19+
this.b = new VariableHelper(denops, "b");
20+
this.w = new VariableHelper(denops, "w");
21+
this.t = new VariableHelper(denops, "t");
22+
this.v = new VariableHelper(denops, "v");
23+
this.env = new VariableHelper(denops, "env");
24+
}
25+
26+
get name(): string {
27+
return this.#denops.name;
28+
}
29+
30+
async call(func: string, ...args: unknown[]): Promise<unknown> {
31+
return await this.#denops.call(func, ...args);
32+
}
33+
34+
async cmd(cmd: string, context: Context = {}): Promise<void> {
35+
await this.#denops.cmd(cmd, context);
36+
}
37+
38+
async eval(expr: string, context: Context = {}): Promise<void> {
39+
await this.#denops.eval(expr, context);
40+
}
41+
42+
async execute(command: string | string[]): Promise<void> {
43+
await execute(this.#denops, command);
44+
}
45+
46+
async autocmd(
47+
group: string,
48+
main: (helper: AutocmdHelper) => void,
49+
): Promise<void> {
50+
await autocmd(this.#denops, group, main);
51+
}
52+
53+
register(dispatcher: Dispatcher): void {
54+
this.#denops.extendDispatcher(dispatcher);
55+
}
56+
}
57+
58+
export function start(main: (vim: Vim) => Promise<void>) {
59+
Denops.start(async (denops) => {
60+
const vim = new Vim(denops);
61+
await main(vim);
62+
});
63+
}

0 commit comments

Comments
 (0)