Skip to content

Commit dd58aeb

Browse files
committed
👍 Isolate function module from vim
1 parent 1d84f31 commit dd58aeb

File tree

5 files changed

+140
-216
lines changed

5 files changed

+140
-216
lines changed

function/buffer.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { Denops } from "../deps.ts";
2+
3+
export async function bufadd(
4+
denops: Denops,
5+
name: string,
6+
): Promise<number> {
7+
const bufnr = await denops.call("bufadd", name);
8+
return bufnr as number;
9+
}
10+
11+
export async function bufexists(
12+
denops: Denops,
13+
name: string | number,
14+
): Promise<boolean> {
15+
const result = await denops.call("bufexists", name) as number;
16+
return !!result;
17+
}
18+
19+
export async function buflisted(
20+
denops: Denops,
21+
name: string | number,
22+
): Promise<boolean> {
23+
const result = await denops.call("buflisted", name) as number;
24+
return !!result;
25+
}
26+
27+
export async function bufload(
28+
denops: Denops,
29+
name: string | number,
30+
): Promise<void> {
31+
await denops.call("bufload", name);
32+
}
33+
34+
export async function bufloaded(
35+
denops: Denops,
36+
name: string | number,
37+
): Promise<boolean> {
38+
const result = await denops.call("bufloaded", name) as number;
39+
return !!result;
40+
}
41+
42+
export async function bufname(
43+
denops: Denops,
44+
name?: string | number,
45+
): Promise<string> {
46+
return await denops.call("bufname", name) as string;
47+
}
48+
49+
export async function bufnr(
50+
denops: Denops,
51+
name: string | number,
52+
): Promise<number> {
53+
return await denops.call("bufnr", name) as number;
54+
}
55+
56+
export async function bufwinid(
57+
denops: Denops,
58+
name: string | number,
59+
): Promise<number> {
60+
return await denops.call("bufwinid", name) as number;
61+
}
62+
63+
export async function bufwinnr(
64+
denops: Denops,
65+
name: string | number,
66+
): Promise<number> {
67+
return await denops.call("bufwinnr", name) as number;
68+
}
69+
70+
export async function getbufline(
71+
denops: Denops,
72+
name: string | number,
73+
lnum: string | number,
74+
end?: string | number,
75+
): Promise<string[]> {
76+
return await denops.call("getbufline", name, lnum, end) as string[];
77+
}
78+
79+
export async function setbufline(
80+
denops: Denops,
81+
name: string | number,
82+
lnum: string | number,
83+
text: string | string[],
84+
): Promise<boolean> {
85+
const result = await denops.call("setbufline", name, lnum, text) as number;
86+
return !!result;
87+
}

function/common.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { Denops } from "../deps.ts";
2+
3+
export async function exists(
4+
denops: Denops,
5+
name: string,
6+
): Promise<boolean> {
7+
const result = await denops.call("exists", name) as number;
8+
return !!result;
9+
}
10+
11+
export async function has(
12+
denops: Denops,
13+
name: string,
14+
check?: boolean,
15+
): Promise<boolean> {
16+
if (check) {
17+
const result = await denops.call("has", name, 1) as number;
18+
return !!result;
19+
}
20+
const result = await denops.call("has", name) as number;
21+
return !!result;
22+
}
23+
24+
export async function getline(
25+
denops: Denops,
26+
lnum: string | number,
27+
): Promise<string>;
28+
export async function getline(
29+
denops: Denops,
30+
lnum: string | number,
31+
end: string | number,
32+
): Promise<string[]>;
33+
export async function getline(
34+
denops: Denops,
35+
lnum: string | number,
36+
end?: string | number,
37+
): Promise<string | string[]> {
38+
if (end) {
39+
return await denops.call("getline", lnum, end) as string[];
40+
}
41+
return await denops.call("getline", lnum) as string;
42+
}
43+
44+
export async function setline(
45+
denops: Denops,
46+
lnum: string | number,
47+
text: string | string[],
48+
): Promise<boolean> {
49+
const result = await denops.call("setline", lnum, text) as number;
50+
return !!result;
51+
}

function/mod.ts

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

vim/function.ts

Lines changed: 0 additions & 212 deletions
This file was deleted.

vim/vim.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Context, Denops, Dispatcher } from "../deps.ts";
22
import { autocmd, AutocmdHelper } from "./autocmd.ts";
3-
import { FunctionHelper } from "./function.ts";
43

54
/**
65
* Vim is a facade instance visible from each denops plugins for
@@ -13,11 +12,8 @@ import { FunctionHelper } from "./function.ts";
1312
export class Vim {
1413
#denops: Denops;
1514

16-
readonly fn: FunctionHelper;
17-
1815
constructor(denops: Denops) {
1916
this.#denops = denops;
20-
this.fn = new FunctionHelper(denops);
2117
}
2218

2319
/**

0 commit comments

Comments
 (0)