|
| 1 | +# denops_std |
| 2 | + |
| 3 | +[](https://deno.land/x/denops_std) |
| 4 | +[](https://doc.deno.land/https/deno.land/x/denops_std/mod.ts) |
| 5 | +[](https://github.com/vim-denops/deno-denops-std/actions/workflows/test.yml) |
| 6 | + |
| 7 | +[Deno][deno] module for [denops.vim][denops.vim]. This module is assumed to be |
| 8 | +used in denops plugin and the code is assumed to be called in a worker thread |
| 9 | +for a plugin. |
| 10 | + |
| 11 | +By using this module, developers can write Vim/Neovim denops plugins like: |
| 12 | + |
| 13 | +```typescript |
| 14 | +import { Denops } from "https://deno.land/x/denops_std/mod.ts"; |
| 15 | +import { execute } from "https://deno.land/x/denops_std/helper/mod.ts"; |
| 16 | +import { ensureString } from "https://deno.land/x/unknownutil/mod.ts"; |
| 17 | + |
| 18 | +export async function main(denops: Denops): Promise<void> { |
| 19 | + denops.dispatcher = { |
| 20 | + async say(where: unknown): Promise<void> { |
| 21 | + // Ensure that `where` is `string` here |
| 22 | + ensureString(where); |
| 23 | + // Use `call` to call Vim's function |
| 24 | + const name = await denops.call("input", "Your name: "); |
| 25 | + // Use `eval` to evaluate Vim's expression |
| 26 | + const progname = await denops.eval("v:progname"); |
| 27 | + // Construct messages |
| 28 | + const messages = [ |
| 29 | + `Hello ${where}`, |
| 30 | + `Your name is ${name}`, |
| 31 | + `This is ${progname}`, |
| 32 | + ]; |
| 33 | + // Use `cmd` to execute Vim's command |
| 34 | + await denops.cmd(`redraw | echomsg message`, { |
| 35 | + message: messages.join(". "), |
| 36 | + }); |
| 37 | + }, |
| 38 | + }; |
| 39 | + |
| 40 | + // Use 'execute()' to execute multiline Vim script |
| 41 | + await execute( |
| 42 | + denops, |
| 43 | + ` |
| 44 | + command! HelloWorld call denops#notify("${denops.name}", "say", ["World"]) |
| 45 | + command! HelloDenops call denops#notify("${denops.name}", "say", ["Denops"]) |
| 46 | + `, |
| 47 | + ); |
| 48 | +} |
| 49 | +``` |
| 50 | + |
| 51 | +See [denops-helloworld.vim](https://github.com/vim-denops/denops-helloworld.vim) |
| 52 | +for more details. |
| 53 | + |
| 54 | +[deno]: https://deno.land/ |
| 55 | +[denops.vim]: https://github.com/vim-denops/denops.vim |
0 commit comments