Skip to content

Commit 45191c2

Browse files
committed
📝 Add documentation comments on mapping
1 parent c87079f commit 45191c2

File tree

3 files changed

+109
-127
lines changed

3 files changed

+109
-127
lines changed

denops_std/mapping/README.md

Lines changed: 0 additions & 117 deletions
This file was deleted.

denops_std/mapping/mod.ts

Lines changed: 107 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
/**
2+
* A module to provide helper functions to manage mappings
3+
*
4+
* @module
5+
*/
16
import type { Denops } from "https://deno.land/x/denops_core@v3.4.1/mod.ts";
27
import * as fn from "../function/mod.ts";
38
import * as batch from "../batch/mod.ts";
49
import { Mapping, Mode } from "./types.ts";
510
import { parse } from "./parser.ts";
611

7-
export type MapOptions = {
12+
export interface MapOptions {
813
mode?: Mode | Mode[];
914
noremap?: boolean;
1015
script?: boolean;
@@ -13,10 +18,35 @@ export type MapOptions = {
1318
nowait?: boolean;
1419
silent?: boolean;
1520
unique?: boolean;
16-
};
21+
}
1722

1823
/**
1924
* Register a mapping for `lhs` to `rhs` with given options.
25+
*
26+
* ```typescript
27+
* import { Denops } from "../mod.ts";
28+
* import * as mapping from "../mapping/mod.ts";
29+
*
30+
* export async function main(denops: Denops): Promise<void> {
31+
* await mapping.map(denops, "<Plug>(test-denops-std)", "Hello");
32+
* await mapping.map(denops, "<Plug>(test-denops-std)", "Hello", {
33+
* mode: "i",
34+
* });
35+
* }
36+
* ```
37+
*
38+
* Users can specify multiple `mode` value like:
39+
*
40+
* ```typescript
41+
* import { Denops } from "../mod.ts";
42+
* import * as mapping from "../mapping/mod.ts";
43+
*
44+
* export async function main(denops: Denops): Promise<void> {
45+
* await mapping.map(denops, "<Plug>(test-denops-std)", "Hello", {
46+
* mode: ["n", "i", "x"],
47+
* });
48+
* }
49+
* ```
2050
*/
2151
export async function map(
2252
denops: Denops,
@@ -41,13 +71,47 @@ export async function map(
4171
});
4272
}
4373

44-
export type UnmapOptions = {
74+
export interface UnmapOptions {
4575
buffer?: boolean;
4676
mode?: Mode | Mode[];
47-
};
77+
}
4878

4979
/**
5080
* Remove a mapping for `lhs`.
81+
*
82+
* ```typescript
83+
* import { Denops } from "../mod.ts";
84+
* import * as mapping from "../mapping/mod.ts";
85+
*
86+
* export async function main(denops: Denops): Promise<void> {
87+
* await mapping.map(denops, "<Plug>(test-denops-std)", "Hello");
88+
* await mapping.map(denops, "<Plug>(test-denops-std)", "Hello", {
89+
* mode: "i",
90+
* });
91+
*
92+
* await mapping.unmap(denops, "<Plug>(test-denops-std)");
93+
* await mapping.unmap(denops, "<Plug>(test-denops-std)", {
94+
* mode: "i",
95+
* });
96+
* }
97+
* ```
98+
*
99+
* Users can specify multiple `mode` value like:
100+
*
101+
* ```typescript
102+
* import { Denops } from "../mod.ts";
103+
* import * as mapping from "../mapping/mod.ts";
104+
*
105+
* export async function main(denops: Denops): Promise<void> {
106+
* await mapping.map(denops, "<Plug>(test-denops-std)", "Hello", {
107+
* mode: ["n", "i", "x"],
108+
* });
109+
*
110+
* await mapping.unmap(denops, "<Plug>(test-denops-std)", {
111+
* mode: ["n", "i", "x"],
112+
* });
113+
* }
114+
* ```
51115
*/
52116
export async function unmap(
53117
denops: Denops,
@@ -63,13 +127,30 @@ export async function unmap(
63127
});
64128
}
65129

66-
export type ReadOptions = {
130+
export interface ReadOptions {
67131
mode?: Mode;
68-
};
132+
}
69133

70134
/**
71135
* Read a mapping and return a `Mapping` instance.
72136
*
137+
* ```typescript
138+
* import { Denops } from "../mod.ts";
139+
* import * as mapping from "../mapping/mod.ts";
140+
*
141+
* export async function main(denops: Denops): Promise<void> {
142+
* await denops.cmd(`map <Plug>(test-denops-std) Hello`);
143+
*
144+
* console.log(await mapping.read(denops, "<Plug>(test-denops-std)"));
145+
* // {
146+
* // mode: "",
147+
* // lhs: "<Plug>(test-denops-std)",
148+
* // rhs: "Hello",
149+
* // // ...
150+
* // }
151+
* }
152+
* ```
153+
*
73154
* Note that prior to Vim 8.2.0491 or Neovim 0.5.0, `script` is
74155
* not detectable by `maparg` function internally used in this
75156
* function.
@@ -104,12 +185,30 @@ export async function read(
104185
};
105186
}
106187

107-
export type ListOptions = {
188+
export interface ListOptions {
108189
mode?: Mode;
109-
};
190+
}
110191

111192
/**
112193
* List mappings which starts from `lhs`.
194+
*
195+
* ```typescript
196+
* import { Denops } from "../mod.ts";
197+
* import * as mapping from "../mapping/mod.ts";
198+
*
199+
* export async function main(denops: Denops): Promise<void> {
200+
* const result = await mapping.list(denops, "<Plug>");
201+
* console.log(result);
202+
* // [
203+
* // {
204+
* // mode: "",
205+
* // lhs: "<Plug>(...)",
206+
* // // ...
207+
* // },
208+
* // // ...
209+
* // ]
210+
* }
211+
* ```
113212
*/
114213
export async function list(
115214
denops: Denops,

denops_std/mapping/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export type Mode =
2020
| "nox"
2121
| "nos";
2222

23-
export type Mapping = {
23+
export interface Mapping {
2424
// Modes for which the mapping is defined
2525
mode: Mode;
2626
// The {lhs} of the mapping
@@ -49,4 +49,4 @@ export type Mapping = {
4949
// True for a :map-silent mapping, else False
5050
// This attribute is missing if the Mapping is returned from `list()`
5151
silent?: boolean;
52-
};
52+
}

0 commit comments

Comments
 (0)