Skip to content

Commit 3092dd7

Browse files
committed
📝 Update README.md
1 parent 9344551 commit 3092dd7

File tree

2 files changed

+69
-18
lines changed

2 files changed

+69
-18
lines changed

README.md

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,61 @@
88
[![Documentation](https://img.shields.io/badge/denops-Documentation-yellow.svg)](https://vim-denops.github.io/denops-documentation/)
99
[![deno land](http://img.shields.io/badge/available%20on-deno.land/x/denops__std-lightgrey.svg?logo=deno)](https://deno.land/x/denops_std)
1010

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].
1412

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.
1962

20-
[deno]: https://deno.land/
2163
[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
2266

2367
## License
2468

mod.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
2-
* Standard module for [denops.vim](https://github.com/vim-denops/denops.vim).
2+
* Standard module for [denops.vim].
33
*
4-
* This module is assumed to be used for developing denops plugins. The code
5-
* is assumed to be called in a dedicated worker thread of each plugins.
4+
* This module is assumed to be used for developing denops plugins. The code is
5+
* assumed to be called in a dedicated worker thread.
66
*
77
* By using this module, developers can write Vim/Neovim denops plugins like:
88
*
@@ -20,8 +20,12 @@
2020
* async init(): Promise<void> {
2121
* // This is just an example. Developers usually should define commands directly in Vim script.
2222
* 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"])`);
23+
* await denops.cmd(
24+
* `command! HelloWorld call denops#notify("${denops.name}", "say", ["World"])`,
25+
* );
26+
* await denops.cmd(
27+
* `command! HelloDenops call denops#notify("${denops.name}", "say", ["Denops"])`,
28+
* );
2529
* });
2630
* },
2731
* async say(where: unknown): Promise<void> {
@@ -41,12 +45,15 @@
4145
* }
4246
* ```
4347
*
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`.
48+
* **Note that developers should avoid calling initialization code within the
49+
* `main` function**. If necessary, add an `init` API or a similar approach like
50+
* above and call it from `plugin/<your_plugin>.vim`.
4651
*
47-
* See [Denops Documentation](https://vim-denops.github.io/denops-documentation/)
48-
* or [denops-helloworld.vim](https://github.com/vim-denops/denops-helloworld.vim)
49-
* for more details.
52+
* See [Denops Documentation] or [denops-helloworld.vim] for more details.
53+
*
54+
* [denops.vim]: https://github.com/vim-denops/denops.vim
55+
* [Denops Documentation]: https://vim-denops.github.io/denops-documentation
56+
* [denops-helloworld.vim]: https://github.com/vim-denops/denops-helloworld.vim
5057
*
5158
* @module
5259
*/

0 commit comments

Comments
 (0)