Skip to content

Commit a453c2b

Browse files
authored
Merge pull request #28 from vim-denops/ref
💥 Breaking changes for next major release
2 parents d958566 + 6ec261e commit a453c2b

27 files changed

+1080
-625
lines changed

.gitmessage

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
3+
# Guide (v1.0)
4+
#
5+
# 👍 :+1: Apply changes.
6+
#
7+
# 🌿 :herb: Add or update things for tests.
8+
# ☕ :coffee: Add or update things for developments.
9+
# 📦 :package: Add or update dependencies.
10+
# 📝 :memo: Add or update documentations.
11+
#
12+
# 🐛 :bug: Bugfixes.
13+
# 💋 :kiss: Critical hotfixes.
14+
# 🚿 :shower: Remove features, codes, or files.
15+
#
16+
# 🚀 :rocket: Improve performance.
17+
# 💪 :muscle: Refactor codes.
18+
# 💥 :boom: Breaking changes.
19+
# 💩 :poop: Bad codes needs to be improved.
20+
#
21+
# How to use:
22+
# git config commit.template .gitmessage
23+
#
24+
# Reference:
25+
# https://github.com/lambdalisue/emojiprefix

README.md

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,41 @@ for a plugin.
1313
By using this module, developers can write Vim/Neovim denops plugins like:
1414

1515
```typescript
16-
import { ensureString, main } from "https://deno.land/x/denops_std/mod.ts";
16+
import { Denops } from "https://deno.land/x/denops_std/mod.ts";
17+
import { execute } from "https://deno.land/x/denops_std/helper/mod.ts";
18+
import { ensureString } from "https://deno.land/x/unknownutil/mod.ts";
1719

18-
main(async ({ vim }) => {
19-
vim.register({
20+
export async function main(denops: Denops): Promise<void> {
21+
denops.dispatcher = {
2022
async say(where: unknown): Promise<void> {
21-
ensureString(where, "where");
22-
const name = await vim.call("input", "Your name: ");
23-
const progname = await vim.eval("v:progname");
23+
// Ensure that `where` is `string` here
24+
ensureString(where);
25+
// Use `call` to call Vim's function
26+
const name = await denops.call("input", "Your name: ");
27+
// Use `eval` to evaluate Vim's expression
28+
const progname = await denops.eval("v:progname");
29+
// Construct messages
2430
const messages = [
2531
`Hello ${where}`,
2632
`Your name is ${name}`,
2733
`This is ${progname}`,
2834
];
29-
await vim.cmd(`redraw | echomsg message`, {
35+
// Use `cmd` to execute Vim's command
36+
await denops.cmd(`redraw | echomsg message`, {
3037
message: messages.join(". "),
3138
});
3239
},
33-
});
34-
35-
await vim.execute(`
36-
command! HelloWorld call denops#notify("${vim.name}", "say", ["World"])
37-
command! HelloDenops call denops#notify("${vim.name}", "say", ["Denops"])
38-
`);
39-
40-
console.log("denops plugin has loaded");
41-
});
40+
};
41+
42+
// Use 'execute()' to execute multiline Vim script
43+
await execute(
44+
denops,
45+
`
46+
command! HelloWorld call denops#notify("${denops.name}", "say", ["World"])
47+
command! HelloDenops call denops#notify("${denops.name}", "say", ["Denops"])
48+
`,
49+
);
50+
}
4251
```
4352

4453
See [denops-helloworld.vim](https://github.com/vim-denops/denops-helloworld.vim)

autocmd/common.ts

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
import { Denops } from "../deps.ts";
2+
import { AutocmdEvent } from "./types.ts";
3+
4+
type CommonOptions = {
5+
group?: string;
6+
};
7+
8+
export type DefineOptions = CommonOptions & {
9+
once?: boolean;
10+
nested?: boolean;
11+
};
12+
13+
export type RemoveOptions = CommonOptions;
14+
15+
export type ListOptions = CommonOptions;
16+
17+
export type EmitOptions = CommonOptions & {
18+
nomodeline?: boolean;
19+
};
20+
21+
export async function define(
22+
denops: Denops,
23+
event: AutocmdEvent | AutocmdEvent[],
24+
pat: string | string[],
25+
cmd: string,
26+
options: DefineOptions = {},
27+
): Promise<void> {
28+
const expr = buildDefineExpr(event, pat, cmd, options);
29+
await denops.cmd(expr);
30+
}
31+
32+
export async function remove(
33+
denops: Denops,
34+
event?: "*" | AutocmdEvent | AutocmdEvent[],
35+
pat?: string | string[],
36+
options: RemoveOptions = {},
37+
): Promise<void> {
38+
const expr = buildRemoveExpr(event, pat, options);
39+
await denops.cmd(expr);
40+
}
41+
42+
export async function list(
43+
denops: Denops,
44+
event?: "*" | AutocmdEvent | AutocmdEvent[],
45+
pat?: string | string[],
46+
options: ListOptions = {},
47+
): Promise<unknown> {
48+
const terms = ["au"];
49+
if (options.group) {
50+
terms.push(options.group);
51+
}
52+
if (event) {
53+
if (Array.isArray(event)) {
54+
terms.push(event.join(","));
55+
} else {
56+
terms.push(event);
57+
}
58+
if (pat) {
59+
if (Array.isArray(pat)) {
60+
terms.push(pat.join(","));
61+
} else {
62+
terms.push(pat);
63+
}
64+
}
65+
}
66+
const expr = terms.join(" ");
67+
return await denops.call("execute", expr);
68+
}
69+
70+
export async function emit(
71+
denops: Denops,
72+
event: AutocmdEvent | AutocmdEvent[],
73+
fname?: string,
74+
options: EmitOptions = {},
75+
): Promise<unknown> {
76+
const terms = ["do"];
77+
if (options.nomodeline) {
78+
terms.push("<nomodeline>");
79+
}
80+
if (options.group) {
81+
terms.push(options.group);
82+
}
83+
if (Array.isArray(event)) {
84+
terms.push(event.join(","));
85+
} else {
86+
terms.push(event);
87+
}
88+
if (fname) {
89+
terms.push(fname);
90+
}
91+
const expr = terms.join(" ");
92+
return await denops.cmd(expr);
93+
}
94+
95+
export async function emitAll(
96+
denops: Denops,
97+
event: AutocmdEvent | AutocmdEvent[],
98+
fname?: string,
99+
options: EmitOptions = {},
100+
): Promise<unknown> {
101+
const terms = ["doautoa"];
102+
if (options.nomodeline) {
103+
terms.push("<nomodeline>");
104+
}
105+
if (options.group) {
106+
terms.push(options.group);
107+
}
108+
if (Array.isArray(event)) {
109+
terms.push(event.join(","));
110+
} else {
111+
terms.push(event);
112+
}
113+
if (fname) {
114+
terms.push(fname);
115+
}
116+
const expr = terms.join(" ");
117+
return await denops.cmd(expr);
118+
}
119+
120+
export function buildDefineExpr(
121+
event: AutocmdEvent | AutocmdEvent[],
122+
pat: string | string[],
123+
cmd: string,
124+
options: DefineOptions = {},
125+
): string {
126+
const terms = ["au"];
127+
if (options.group) {
128+
terms.push(options.group);
129+
}
130+
if (Array.isArray(event)) {
131+
terms.push(event.join(","));
132+
} else {
133+
terms.push(event);
134+
}
135+
if (Array.isArray(pat)) {
136+
terms.push(pat.join(","));
137+
} else {
138+
terms.push(pat);
139+
}
140+
if (options.once) {
141+
terms.push("++once");
142+
}
143+
if (options.nested) {
144+
terms.push("++nested");
145+
}
146+
terms.push(cmd);
147+
return terms.join(" ");
148+
}
149+
150+
export function buildRemoveExpr(
151+
event?: "*" | AutocmdEvent | AutocmdEvent[],
152+
pat?: string | string[],
153+
options: RemoveOptions = {},
154+
): string {
155+
const terms = ["au!"];
156+
if (options.group) {
157+
terms.push(options.group);
158+
}
159+
if (event) {
160+
if (Array.isArray(event)) {
161+
terms.push(event.join(","));
162+
} else {
163+
terms.push(event);
164+
}
165+
if (pat) {
166+
if (Array.isArray(pat)) {
167+
terms.push(pat.join(","));
168+
} else {
169+
terms.push(pat);
170+
}
171+
}
172+
}
173+
return terms.join(" ");
174+
}

0 commit comments

Comments
 (0)