Skip to content

Commit 4649885

Browse files
authored
Merge pull request #41 from vim-denops/to-beta
Minor updates for beta release
2 parents 246a989 + 124d9f5 commit 4649885

40 files changed

+576
-155
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ help:
99

1010
tools: FORCE ## Install development tools
1111
@mkdir -p ${TOOLS}
12-
@deno install -f --allow-write --allow-read --allow-net --root ${TOOLS} https://deno.land/x/dlink/dlink.ts
12+
@deno install -A -f -n udd --root ${TOOLS} https://deno.land/x/udd@0.4.0/main.ts
1313

1414
fmt: FORCE ## Format code
1515
@deno fmt
@@ -27,11 +27,11 @@ test: FORCE ## Test
2727
@deno test --unstable -A
2828

2929
gen: FORCE ## Generate codes
30-
@deno run -A ./scripts/gen-function/gen-function.ts
30+
@deno run --unstable -A ./scripts/gen-function/gen-function.ts
3131
@make fmt
3232

33-
dlink: FORCE ## Update dlink
34-
(cd denops_std; ${TOOLS}/bin/dlink)
33+
update: FORCE ## Update dependencies
34+
@${TOOLS}/bin/udd $$(find ./denops_std -name '*.ts')
3535
@make fmt
3636

3737
FORCE:

README.md

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,8 @@
88
used in denops plugin and the code is assumed to be called in a worker thread
99
for a plugin.
1010

11-
**UNDER DEVELOPMENT**
12-
13-
By using this module, developers can write Vim/Neovim denops plugins like:
14-
15-
```typescript
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";
19-
20-
export async function main(denops: Denops): Promise<void> {
21-
denops.dispatcher = {
22-
async say(where: unknown): Promise<void> {
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
30-
const messages = [
31-
`Hello ${where}`,
32-
`Your name is ${name}`,
33-
`This is ${progname}`,
34-
];
35-
// Use `cmd` to execute Vim's command
36-
await denops.cmd(`redraw | echomsg message`, {
37-
message: messages.join(". "),
38-
});
39-
},
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-
}
51-
```
52-
53-
See [denops-helloworld.vim](https://github.com/vim-denops/denops-helloworld.vim)
54-
for more details.
11+
See [Module README](./denops_std/README.md) for quick usage and API
12+
documentations.
5513

5614
[deno]: https://deno.land/
5715
[denops.vim]: https://github.com/vim-denops/denops.vim

denops_std/README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ By using this module, developers can write Vim/Neovim denops plugins like:
1212

1313
```typescript
1414
import { Denops } from "https://deno.land/x/denops_std/mod.ts";
15+
import * as fn from "https://deno.land/x/denops_std/function/mod.ts";
16+
import * as vars from "https://deno.land/x/denops_std/variable/mod.ts";
1517
import { execute } from "https://deno.land/x/denops_std/helper/mod.ts";
1618
import { ensureString } from "https://deno.land/x/unknownutil/mod.ts";
1719

@@ -21,9 +23,9 @@ export async function main(denops: Denops): Promise<void> {
2123
// Ensure that `where` is `string` here
2224
ensureString(where);
2325
// Use `call` to call Vim's function
24-
const name = await denops.call("input", "Your name: ");
26+
const name = await fn.input(denops, "Your name: ");
2527
// Use `eval` to evaluate Vim's expression
26-
const progname = await denops.eval("v:progname");
28+
const progname = await vars.v.get(denops, "progname");
2729
// Construct messages
2830
const messages = [
2931
`Hello ${where}`,
@@ -53,3 +55,13 @@ for more details.
5355

5456
[deno]: https://deno.land/
5557
[denops.vim]: https://github.com/vim-denops/denops.vim
58+
59+
## Index
60+
61+
| Name | Description |
62+
| -------------------------- | ---------------------------------------------------------------- |
63+
| [`anonymous`](./anonymous) | A module to provide anonymous function |
64+
| [`autocmd`](./autocmd) | A module to provide helper functions to manage `autocmd` |
65+
| [`function`](./function) | A module to provide functions of Vim and Neovim native functions |
66+
| [`helper`](./helper) | A module to provide helper functions |
67+
| [`variable`](./variable) | A module to provide helper accessor functions to variables |

denops_std/anonymous/README.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# anonymous
2+
3+
`anonymous` is a module to provide anonymous function which is callable from
4+
outside of the plugin (Vim or other plugins.)
5+
6+
- [API documentation](https://doc.deno.land/https/deno.land/x/denops_std/anonymous/mod.ts)
7+
8+
## Usage
9+
10+
### add
11+
12+
Use `add()` to add new anonymous functions and use return value as unique IDs to
13+
call added functions later like:
14+
15+
```typescript
16+
import { Denops } from "https://deno.land/x/denops_std/mod.ts";
17+
import * as anonymous from "https://deno.land/x/denops_std/anonymous/mod.ts";
18+
19+
export async function main(denops: Denops): Promise<void> {
20+
// Add anonymous functions
21+
const ids = anonymous.add(
22+
denops,
23+
() => {
24+
// Do what ever you want.
25+
},
26+
() => {
27+
// Do what ever you want.
28+
},
29+
// You can add as many callbacks as you want...
30+
);
31+
32+
// Use ids to dispatch added functions from Deno
33+
await denops.dispatch(denops.name, ids[0]);
34+
await denops.dispatch(denops.name, ids[1]);
35+
36+
// Or from Vim
37+
await denops.cmd("call denops#notify(name, id, [])", {
38+
name: denops.name,
39+
id: ids[1],
40+
});
41+
}
42+
```
43+
44+
### once
45+
46+
If you need one-time anonymous function, use `once()` instead like:
47+
48+
```typescript
49+
import { Denops } from "https://deno.land/x/denops_std/mod.ts";
50+
import * as anonymous from "https://deno.land/x/denops_std/anonymous/mod.ts";
51+
52+
export async function main(denops: Denops): Promise<void> {
53+
// Add anonymous functions
54+
const ids = anonymous.once(
55+
denops,
56+
() => {
57+
// Do what ever you want.
58+
},
59+
() => {
60+
// Do what ever you want.
61+
},
62+
// You can add as many callbacks as you want...
63+
);
64+
65+
// First calls complete normally
66+
await denops.dispatch(denops.name, ids[0]);
67+
await denops.dispatch(denops.name, ids[1]);
68+
69+
// But second call would throw errors
70+
await denops.dispatch(denops.name, ids[0]);
71+
}
72+
```
73+
74+
### remove
75+
76+
When you need to remove callback, use `remove()` like:
77+
78+
```typescript
79+
import { Denops } from "https://deno.land/x/denops_std/mod.ts";
80+
import * as anonymous from "https://deno.land/x/denops_std/anonymous/mod.ts";
81+
82+
export async function main(denops: Denops): Promise<void> {
83+
// Add anonymous functions
84+
const ids = anonymous.add(
85+
denops,
86+
() => {
87+
// Do what ever you want.
88+
},
89+
() => {
90+
// Do what ever you want.
91+
},
92+
// You can add as many callbacks as you want...
93+
);
94+
95+
// Remove ids[1]
96+
anonymous.remove(denops, ids[1]);
97+
98+
// Call of ids[0] complete normally
99+
await denops.dispatch(denops.name, ids[0]);
100+
101+
// But ids[1] is already removed
102+
await denops.dispatch(denops.name, ids[1]);
103+
}
104+
```

denops_std/anonymous/mod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Denops } from "../vendor/https/deno.land/x/denops_core/mod.ts";
1+
import { Denops } from "../deps.ts";
22

33
// https://github.com/microsoft/TypeScript/issues/26223#issuecomment-674500430
44
export type TupleOf<T, N extends number> = N extends N

denops_std/anonymous/mod_test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import {
2-
assertEquals,
3-
assertThrowsAsync,
4-
} from "../vendor/https/deno.land/std/testing/asserts.ts";
5-
import { test } from "../vendor/https/deno.land/x/denops_core/test/mod.ts";
1+
import { assertEquals, assertThrowsAsync } from "../deps_test.ts";
2+
import { test } from "../deps_test.ts";
63
import * as anonymous from "./mod.ts";
74

85
test({

0 commit comments

Comments
 (0)