@@ -95,7 +95,95 @@ class BatchHelper implements Denops {
95
95
}
96
96
97
97
/**
98
- * Perform batch call
98
+ * Call multiple denops functions sequentially without RPC overhead
99
+ *
100
+ * ```typescript
101
+ * import { Denops } from "../mod.ts";
102
+ * import { batch } from "./batch.ts";
103
+ *
104
+ * export async function main(denops: Denops): Promise<void> {
105
+ * await batch(denops, async (denops) => {
106
+ * await denops.cmd("setlocal modifiable");
107
+ * await denops.cmd("setlocal noswap");
108
+ * await denops.cmd("setlocal nobackup");
109
+ * });
110
+ * }
111
+ * ```
112
+ *
113
+ * The function can be nested thus users can use functions which may internally use
114
+ * `batch()` like:
115
+ *
116
+ * ```typescript
117
+ * import { Denops } from "../mod.ts";
118
+ * import { batch } from "./batch.ts";
119
+ *
120
+ * async function replace(denops: Denops, content: string): Promise<void> {
121
+ * await batch(denops, async (denops) => {
122
+ * await denops.cmd("setlocal modifiable");
123
+ * await denops.cmd("setlocal foldmethod=manual");
124
+ * await denops.call("setline", 1, content.split(/\r?\n/));
125
+ * await denops.cmd("setlocal nomodifiable");
126
+ * await denops.cmd("setlocal nomodified");
127
+ * });
128
+ * }
129
+ *
130
+ * export async function main(denops: Denops): Promise<void> {
131
+ * await batch(denops, async (denops) => {
132
+ * await denops.cmd("edit Hello");
133
+ * await replace(denops, "Hello Darkness My Old Friend");
134
+ * });
135
+ * }
136
+ * ```
137
+ *
138
+ * Note that `denops.call()`, `denops.batch()`, or `denops.eval()` always return
139
+ * falsy value in `batch()`, indicating that you **cannot** write code like below:
140
+ *
141
+ * ```typescript
142
+ * import { Denops } from "../mod.ts";
143
+ * import { batch } from "./batch.ts";
144
+ *
145
+ * export async function main(denops: Denops): Promise<void> {
146
+ * await batch(denops, async (denops) => {
147
+ * // !!! DON'T DO THIS !!!
148
+ * if (await denops.eval("&verbose")) {
149
+ * await denops.cmd("echomsg 'VERBOSE'");
150
+ * }
151
+ * await denops.cmd("echomsg 'Hello world'");
152
+ * });
153
+ * }
154
+ * ```
155
+ *
156
+ * The `denops` instance passed to the `batch` block is available even outside of
157
+ * the block. It works like a real `denops` instance, mean that you can write code
158
+ * like:
159
+ *
160
+ * ```typescript
161
+ * import { Denops } from "../mod.ts";
162
+ * import { batch } from "./batch.ts";
163
+ * import * as anonymous from "../anonymous/mod.ts";
164
+ *
165
+ * export async function main(denops: Denops): Promise<void> {
166
+ * await batch(denops, async (denops) => {
167
+ * const [id] = anonymous.add(denops, async () => {
168
+ * // This code is called outside of 'batch' block
169
+ * // thus the 'denops' instance works like a real one.
170
+ * // That's why you can write code like below
171
+ * if (await denops.eval("&verbose")) {
172
+ * await denops.cmd("echomsg 'VERBOSE'");
173
+ * }
174
+ * await denops.cmd("echomsg 'Hello world'");
175
+ * });
176
+ * await denops.cmd(
177
+ * `command! Test call denops#request('${denops.name}', '${id}', [])`,
178
+ * );
179
+ * });
180
+ * }
181
+ * ```
182
+ *
183
+ * Note that `denops.redraw()` is executed only once after the batch is actually
184
+ * executed, no matter how many times it is called in the `batch()`. If the `force`
185
+ * option is specified even once, the last call will be the one with the force
186
+ * option specified.
99
187
*/
100
188
export async function batch (
101
189
denops : Denops ,
0 commit comments