Skip to content

Commit cc0038f

Browse files
authored
Merge pull request #73 from vim-denops/option
👍 Add `option` module to manage options
2 parents 0a8fe8b + 74c4709 commit cc0038f

File tree

17 files changed

+13043
-0
lines changed

17 files changed

+13043
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ test: FORCE ## Test
2828

2929
gen: FORCE ## Generate codes
3030
@deno run --unstable -A ./scripts/gen-function/gen-function.ts
31+
@deno run --unstable -A ./scripts/gen-option/gen-option.ts
3132
@make fmt
3233

3334
update: FORCE ## Update dependencies

denops_std/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,5 @@ for more details.
6262
| [`function`](./function) | A module to provide functions of Vim and Neovim native functions |
6363
| [`helper`](./helper) | A module to provide helper functions |
6464
| [`mapping`](./mapping) | A module to provide helper functions to manage mappings |
65+
| [`option`](./option) | A module to provide helper functions to manage options |
6566
| [`variable`](./variable) | A module to provide helper accessor functions to variables |

denops_std/option/README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# option
2+
3+
`option`, `option/vim`, and `option/nvim` are modules to provide accessors of
4+
Vim and Neovim native options.
5+
6+
- [API documentation](https://doc.deno.land/https/deno.land/x/denops_std/option/mod.ts)
7+
- [API documentation (Vim)](https://doc.deno.land/https/deno.land/x/denops_std/option/vim/mod.ts)
8+
- [API documentation (Neovim)](https://doc.deno.land/https/deno.land/x/denops_std/option/nvim/mod.ts)
9+
10+
Most of codes are automatically generated by
11+
[`gen-option.ts`](../../scripts/gen-option/gen-option.ts) from `options.txt` in
12+
minimal supported Vim and Neovim versions.
13+
14+
## Example
15+
16+
```typescript
17+
import * as op from "https://deno.land/x/denops_std/option/mod.ts";
18+
import * as vimOp from "https://deno.land/x/denops_std/option/vim/mod.ts";
19+
import * as nvimOp from "https://deno.land/x/denops_std/option/nvim/mod.ts";
20+
21+
export async function main(denops) {
22+
// Get value of the option.
23+
// `get` is available on any options
24+
// `getGlobal` is available on only global options
25+
// `getLocal` is available on only local options
26+
console.log(await op.filetype.get(denops));
27+
console.log(await op.filetype.getGlobal(denops));
28+
console.log(await op.filetype.getLocal(denops));
29+
30+
// Set value of the option.
31+
// `set` is available on any options
32+
// `setGlobal` is available on only global options
33+
// `setLocal` is available on only local options
34+
await op.filetype.set(denops, "hello");
35+
await op.filetype.setGlobal(denops, "hello");
36+
await op.filetype.setLocal(denops, "hello");
37+
38+
// Reset the option.
39+
// `reset` is available on any options
40+
// `resetGlobal` is available on only global options
41+
// `resetLocal` is available on only local options
42+
await op.filetype.reset(denops);
43+
await op.filetype.resetGlobal(denops);
44+
await op.filetype.resetLocal(denops);
45+
46+
// vimOp has options only exist in Vim
47+
console.log(await vimOp.compatible.get(denops));
48+
49+
// nvimOp has options only exist in Neovim
50+
console.log(await nvimOp.shada.get(denops));
51+
}
52+
```
53+
54+
## How to add options manually
55+
56+
To add options manually, create or modify corresponding module under `option`,
57+
`option/vim`, or `option/nvim` module then make sure that module is listed in
58+
`_manual.ts` under corresponding module. After that, execute `make gen` on the
59+
repository top so that `gen-option.ts` automatically remove duplicated options
60+
from `_generated.ts`.

0 commit comments

Comments
 (0)