|
8 | 8 | [](https://vim-denops.github.io/denops-documentation/)
|
9 | 9 | [](https://deno.land/x/denops_std)
|
10 | 10 |
|
11 |
| -[Deno][deno] module for [denops.vim][denops.vim]. This module is assumed to be |
12 |
| -used in denops plugin and the code is assumed to be called in a worker thread |
13 |
| -for a plugin. |
| 11 | +Standard module for [denops.vim]. |
14 | 12 |
|
15 |
| -See [deno doc](https://doc.deno.land/https/deno.land/x/denops_std/mod.ts) for |
16 |
| -quick usage and API documentations and see |
17 |
| -[Denops Documentation](https://vim-denops.github.io/denops-documentation/) for |
18 |
| -learning how to write Vim/Neovim plugins. |
| 13 | +This module is assumed to be used for developing denops plugins. The code is |
| 14 | +assumed to be called in a dedicated worker thread. |
| 15 | + |
| 16 | +By using this module, developers can write Vim/Neovim denops plugins like: |
| 17 | + |
| 18 | +```typescript |
| 19 | +import type { Denops } from "https://deno.land/x/denops_std@$MODULE_VERSION/mod.ts"; |
| 20 | +import * as batch from "https://deno.land/x/denops_std@$MODULE_VERSION/batch/mod.ts"; |
| 21 | +import * as fn from "https://deno.land/x/denops_std@$MODULE_VERSION/function/mod.ts"; |
| 22 | +import * as vars from "https://deno.land/x/denops_std@$MODULE_VERSION/variable/mod.ts"; |
| 23 | +import * as helper from "https://deno.land/x/denops_std@$MODULE_VERSION/helper/mod.ts"; |
| 24 | + |
| 25 | +import { assert, is } from "https://deno.land/x/unknownutil@v3.11.0/mod.ts"; |
| 26 | + |
| 27 | +export async function main(denops: Denops): Promise<void> { |
| 28 | + denops.dispatcher = { |
| 29 | + async init(): Promise<void> { |
| 30 | + // This is just an example. Developers usually should define commands directly in Vim script. |
| 31 | + await batch.batch(denops, async (denops) => { |
| 32 | + await denops.cmd( |
| 33 | + `command! HelloWorld call denops#notify("${denops.name}", "say", ["World"])`, |
| 34 | + ); |
| 35 | + await denops.cmd( |
| 36 | + `command! HelloDenops call denops#notify("${denops.name}", "say", ["Denops"])`, |
| 37 | + ); |
| 38 | + }); |
| 39 | + }, |
| 40 | + async say(where: unknown): Promise<void> { |
| 41 | + assert(where, is.String); |
| 42 | + const [name, progname] = await batch.collect(denops, (denops) => [ |
| 43 | + fn.input(denops, "Your name: "), |
| 44 | + vars.v.get(denops, "progname"), |
| 45 | + ]); |
| 46 | + const messages = [ |
| 47 | + `Hello ${where}.`, |
| 48 | + `Your name is ${name}.`, |
| 49 | + `This is ${progname}.`, |
| 50 | + ]; |
| 51 | + await helper.echo(denops, messages.join("\n")); |
| 52 | + }, |
| 53 | + }; |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +**Note that developers should avoid calling initialization code within the |
| 58 | +`main` function**. If necessary, add an `init` API or a similar approach like |
| 59 | +above and call it from `plugin/<your_plugin>.vim`. |
| 60 | + |
| 61 | +See [Denops Documentation] or [denops-helloworld.vim] for more details. |
19 | 62 |
|
20 |
| -[deno]: https://deno.land/ |
21 | 63 | [denops.vim]: https://github.com/vim-denops/denops.vim
|
| 64 | +[Denops Documentation]: https://vim-denops.github.io/denops-documentation |
| 65 | +[denops-helloworld.vim]: https://github.com/vim-denops/denops-helloworld.vim |
22 | 66 |
|
23 | 67 | ## License
|
24 | 68 |
|
|
0 commit comments