Skip to content

Commit 20fb1a9

Browse files
committed
Add buffer functions
1 parent 3b23adc commit 20fb1a9

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

vim/buffer.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Denops } from "../deps.ts";
2+
3+
export async function bufadd(denops: Denops, name: string): Promise<number> {
4+
const bufnr = await denops.eval("bufadd(name)", { name: name });
5+
return bufnr as number;
6+
}
7+
8+
export async function bufexists(
9+
denops: Denops,
10+
name: string | number,
11+
): Promise<boolean> {
12+
const result = await denops.eval("bufexists(name)", { name: name }) as number;
13+
return result ? true : false;
14+
}
15+
16+
export class BufferHelper {
17+
#denops: Denops;
18+
19+
constructor(denops: Denops) {
20+
this.#denops = denops;
21+
}
22+
23+
async bufadd(name: string): Promise<number> {
24+
return await bufadd(this.#denops, name);
25+
}
26+
27+
async bufexists(name: string | number): Promise<boolean> {
28+
return await bufexists(this.#denops, name);
29+
}
30+
}

vim/vim.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Context, Denops, Dispatcher } from "../deps.ts";
22
import { execute } from "./execute.ts";
33
import { autocmd, AutocmdHelper } from "./autocmd.ts";
44
import { VariableHelper } from "./variable.ts";
5+
import { BufferHelper } from "./buffer.ts";
56
import { load } from "./load.ts";
67

78
/**
@@ -23,13 +24,16 @@ export class Vim {
2324
readonly t: VariableHelper;
2425
readonly v: VariableHelper;
2526

27+
readonly buffer: BufferHelper;
28+
2629
constructor(denops: Denops) {
2730
this.#denops = denops;
2831
this.g = new VariableHelper(denops, "g");
2932
this.b = new VariableHelper(denops, "b");
3033
this.w = new VariableHelper(denops, "w");
3134
this.t = new VariableHelper(denops, "t");
3235
this.v = new VariableHelper(denops, "v");
36+
this.buffer = new BufferHelper(denops);
3337
}
3438

3539
/**

0 commit comments

Comments
 (0)