|
8 | 8 | *
|
9 | 9 | * ```typescript
|
10 | 10 | * import { Denops } from "./mod.ts";
|
| 11 | + * import * as batch from "./batch/mod.ts"; |
11 | 12 | * import * as fn from "./function/mod.ts";
|
12 | 13 | * import * as vars from "./variable/mod.ts";
|
13 | 14 | * import * as helper from "./helper/mod.ts";
|
|
16 | 17 | *
|
17 | 18 | * export async function main(denops: Denops): Promise<void> {
|
18 | 19 | * denops.dispatcher = {
|
| 20 | + * async init(): Promise<void> { |
| 21 | + * // This is just an example. Developers usually should define commands directly in Vim script. |
| 22 | + * await batch.batch(denops, async (denops) => { |
| 23 | + * await denops.cmd(`command! HelloWorld call denops#notify("${denops.name}", "say", ["World"])`); |
| 24 | + * await denops.cmd(`command! HelloDenops call denops#notify("${denops.name}", "say", ["Denops"])`); |
| 25 | + * }); |
| 26 | + * }, |
19 | 27 | * async say(where: unknown): Promise<void> {
|
20 | 28 | * assert(where, is.String);
|
21 |
| - * |
22 |
| - * const name = await fn.input(denops, "Your name: "); |
23 |
| - * const progname = await vars.v.get(denops, "progname"); |
| 29 | + * const [name, progname] = await batch.collect(denops, (denops) => [ |
| 30 | + * fn.input(denops, "Your name: "), |
| 31 | + * vars.v.get(denops, "progname"), |
| 32 | + * ]); |
24 | 33 | * const messages = [
|
25 | 34 | * `Hello ${where}.`,
|
26 | 35 | * `Your name is ${name}.`,
|
|
29 | 38 | * await helper.echo(denops, messages.join("\n"));
|
30 | 39 | * },
|
31 | 40 | * };
|
32 |
| - * |
33 |
| - * await helper.execute( |
34 |
| - * denops, |
35 |
| - * ` |
36 |
| - * command! HelloWorld call denops#notify("${denops.name}", "say", ["World"]) |
37 |
| - * command! HelloDenops call denops#notify("${denops.name}", "say", ["Denops"]) |
38 |
| - * `, |
39 |
| - * ); |
40 | 41 | * }
|
41 | 42 | * ```
|
42 | 43 | *
|
| 44 | + * Note that developers should avoid calling initialization code within the `main` function. |
| 45 | + * If necessary, add an `init` API or a similar approach like above and call it from `plugin/<your_plugin>.vim`. |
| 46 | + * |
43 | 47 | * See [Denops Documentation](https://vim-denops.github.io/denops-documentation/)
|
44 | 48 | * or [denops-helloworld.vim](https://github.com/vim-denops/denops-helloworld.vim)
|
45 | 49 | * for more details.
|
|
0 commit comments