1
1
import type { Denops } from "https://deno.land/x/denops_core@v4.0.0/mod.ts" ;
2
2
3
3
/**
4
- * Add a buffer to the buffer list with {name}.
4
+ * Add a buffer to the buffer list with name {name} (must be a
5
+ * String).
5
6
* If a buffer for file {name} already exists, return that buffer
6
7
* number. Otherwise return the buffer number of the newly
7
8
* created buffer. When {name} is an empty string then a new
8
9
* buffer is always created.
9
- * The buffer will not have' 'buflisted' set.
10
+ * The buffer will not have 'buflisted' set and not be loaded
11
+ * yet. To add some text to the buffer use this:
12
+ * let bufnr = bufadd('someName')
13
+ * call bufload(bufnr)
14
+ * call setbufline(bufnr, 1, ['some', 'text'])
15
+ * Returns 0 on error.
16
+ * Can also be used as a |method|:
17
+ * let bufnr = 'somename'->bufadd()
10
18
*/
11
19
export async function bufadd (
12
20
denops : Denops ,
@@ -18,11 +26,11 @@ export async function bufadd(
18
26
19
27
/**
20
28
* The result is a Number, which is |TRUE| if a buffer called
21
- * {expr} exists.
22
- * If the {expr} argument is a number, buffer numbers are used.
23
- * Number zero is the alternate buffer for the current window.
29
+ * {buf} exists.
30
+ * If the {buf} argument is a number, buffer numbers are used.
24
31
*
25
- * If the {expr} argument is a string it must match a buffer name
32
+ * Number zero is the alternate buffer for the current window.
33
+ * If the {buf} argument is a string it must match a buffer name
26
34
* exactly. The name can be:
27
35
* - Relative to the current directory.
28
36
* - A full path.
@@ -37,64 +45,80 @@ export async function bufadd(
37
45
* for MS-Windows 8.3 names in the form "c:\DOCUME~1"
38
46
* Use "bufexists(0)" to test for the existence of an alternate
39
47
* file name.
48
+ *
49
+ * Can also be used as a |method|:
50
+ * let exists = 'somename'->bufexists()
51
+ *
52
+ * Obsolete name: buffer_exists().
40
53
*/
41
54
export async function bufexists (
42
55
denops : Denops ,
43
- expr : string | number ,
56
+ buf : string | number ,
44
57
) : Promise < boolean > {
45
- const result = await denops . call ( "bufexists" , expr ) as number ;
58
+ const result = await denops . call ( "bufexists" , buf ) as number ;
46
59
return ! ! result ;
47
60
}
48
61
49
62
/**
50
63
* The result is a Number, which is |TRUE| if a buffer called
51
- * {expr} exists and is listed (has the 'buflisted' option set).
52
- * The {expr} argument is used like with |bufexists()|.
64
+ * {buf} exists and is listed (has the 'buflisted' option set).
65
+ * The {buf} argument is used like with |bufexists()|.
66
+ *
67
+ * Can also be used as a |method|:
68
+ * let listed = 'somename'->buflisted()
53
69
*/
54
70
export async function buflisted (
55
71
denops : Denops ,
56
- expr : string | number ,
72
+ buf : string | number ,
57
73
) : Promise < boolean > {
58
- const result = await denops . call ( "buflisted" , expr ) as number ;
74
+ const result = await denops . call ( "buflisted" , buf ) as number ;
59
75
return ! ! result ;
60
76
}
61
77
62
78
/**
63
- * Ensure the buffer {expr } is loaded. When the buffer name
79
+ * Ensure the buffer {buf } is loaded. When the buffer name
64
80
* refers to an existing file then the file is read. Otherwise
65
81
* the buffer will be empty. If the buffer was already loaded
66
- * then there is no change.
82
+ * then there is no change. If the buffer is not related to a
83
+ * file the no file is read (e.g., when 'buftype' is "nofile").
67
84
* If there is an existing swap file for the file of the buffer,
68
85
* there will be no dialog, the buffer will be loaded anyway.
69
- * The {expr} argument is used like with |bufexists()|.
86
+ * The {buf} argument is used like with |bufexists()|.
87
+ *
88
+ * Can also be used as a |method|:
89
+ * eval 'somename'->bufload()
70
90
*/
71
91
export async function bufload (
72
92
denops : Denops ,
73
- expr : string | number ,
93
+ buf : string | number ,
74
94
) : Promise < void > {
75
- await denops . call ( "bufload" , expr ) ;
95
+ await denops . call ( "bufload" , buf ) ;
76
96
}
77
97
78
98
/**
79
99
* The result is a Number, which is |TRUE| if a buffer called
80
- * {expr} exists and is loaded (shown in a window or hidden).
81
- * The {expr} argument is used like with |bufexists()|.
100
+ * {buf} exists and is loaded (shown in a window or hidden).
101
+ * The {buf} argument is used like with |bufexists()|.
102
+ *
103
+ * Can also be used as a |method|:
104
+ * let loaded = 'somename'->bufloaded()
82
105
*/
83
106
export async function bufloaded (
84
107
denops : Denops ,
85
- expr : string | number ,
108
+ buf : string | number ,
86
109
) : Promise < boolean > {
87
- const result = await denops . call ( "bufloaded" , expr ) as number ;
110
+ const result = await denops . call ( "bufloaded" , buf ) as number ;
88
111
return ! ! result ;
89
112
}
90
113
91
114
/**
92
- * The result is the name of a buffer, as it is displayed by the
93
- * ":ls" command.
94
- * If {expr} is omitted the current buffer is used.
95
- * If {expr} is a Number, that buffer number's name is given.
115
+ * The result is the name of a buffer. Mostly as it is displayed
116
+ * by the `:ls` command, but not using special names such as
117
+ * "[No Name]".
118
+ * If {buf} is omitted the current buffer is used.
119
+ * If {buf} is a Number, that buffer number's name is given.
96
120
* Number zero is the alternate buffer for the current window.
97
- * If {expr } is a String, it is used as a |file-pattern| to match
121
+ * If {buf } is a String, it is used as a |file-pattern| to match
98
122
* with the buffer names. This is always done like 'magic' is
99
123
* set and 'cpoptions' is empty. When there is more than one
100
124
* match an empty string is returned.
@@ -107,87 +131,106 @@ export async function bufloaded(
107
131
* Listed buffers are found first. If there is a single match
108
132
* with a listed buffer, that one is returned. Next unlisted
109
133
* buffers are searched for.
110
- * If the {expr} is a String, but you want to use it as a buffer
111
- * number, force it to be a Number by adding zero to it: >
112
- * :echo bufname("3" + 0)
134
+ * If the {buf} is a String, but you want to use it as a buffer
135
+ * number, force it to be a Number by adding zero to it:
136
+ * :echo bufname("3" + 0)
137
+ * Can also be used as a |method|:
138
+ * echo bufnr->bufname()
139
+ *
113
140
* If the buffer doesn't exist, or doesn't have a name, an empty
114
141
* string is returned.
115
- * bufname("#") alternate buffer name
116
- * bufname(3) name of buffer 3
117
- * bufname("%") name of current buffer
118
- * bufname("file2") name of buffer where "file2" matches.
142
+ * bufname("#") alternate buffer name
143
+ * bufname(3) name of buffer 3
144
+ * bufname("%") name of current buffer
145
+ * bufname("file2") name of buffer where "file2" matches.
146
+ *
147
+ * Obsolete name: buffer_name().
119
148
*/
120
149
export async function bufname (
121
150
denops : Denops ,
122
- expr ?: string | number ,
151
+ buf ?: string | number ,
123
152
) : Promise < string > {
124
- return await denops . call ( "bufname" , expr ) as string ;
153
+ return await denops . call ( "bufname" , buf ) as string ;
125
154
}
126
155
127
156
/**
128
157
* The result is the number of a buffer, as it is displayed by
129
- * the " :ls" command. For the use of {expr }, see |bufname()|
158
+ * the ` :ls` command. For the use of {buf }, see |bufname()|
130
159
* above.
131
160
* If the buffer doesn't exist, -1 is returned. Or, if the
132
- * {create} argument is present and not zero, a new, unlisted,
133
- * buffer is created and its number is returned.
161
+ * {create} argument is present and TRUE, a new, unlisted,
162
+ * buffer is created and its number is returned. Example:
163
+ * let newbuf = bufnr('Scratch001', 1)
164
+ * Using an empty name uses the current buffer. To create a new
165
+ * buffer with an empty name use |bufadd()|.
134
166
* bufnr("$") is the last buffer:
135
167
* :let last_buffer = bufnr("$")
136
168
* The result is a Number, which is the highest buffer number
137
169
* of existing buffers. Note that not all buffers with a smaller
138
170
* number necessarily exist, because ":bwipeout" may have removed
139
171
* them. Use bufexists() to test for the existence of a buffer.
172
+ *
173
+ * Can also be used as a |method|:
174
+ * echo bufref->bufnr()
175
+ *
176
+ * Obsolete name: buffer_number().
177
+ * Obsolete name for bufnr("$"): last_buffer_nr().
140
178
*/
141
179
export async function bufnr (
142
180
denops : Denops ,
143
- expr ?: string | number ,
181
+ buf ?: string | number ,
144
182
create ?: boolean ,
145
183
) : Promise < number > {
146
- return await denops . call ( "bufnr" , expr , create ) as number ;
184
+ return await denops . call ( "bufnr" , buf , create ) as number ;
147
185
}
148
186
149
187
/**
150
188
* The result is a Number, which is the |window-ID| of the first
151
- * window associated with buffer {expr }. For the use of {expr },
152
- * see |bufname()| above. If buffer {expr } doesn't exist or
153
- * there is no such window, -1 is returned. Example: >
189
+ * window associated with buffer {buf }. For the use of {buf },
190
+ * see |bufname()| above. If buffer {buf } doesn't exist or
191
+ * there is no such window, -1 is returned. Example:
154
192
*
155
- * echo "A window containing buffer 1 is " . (bufwinid(1))
193
+ * echo "A window containing buffer 1 is " . . (bufwinid(1))
156
194
*
157
195
* Only deals with the current tab page.
196
+ *
197
+ * Can also be used as a |method|:
198
+ * FindBuffer()->bufwinid()
158
199
*/
159
200
export async function bufwinid (
160
201
denops : Denops ,
161
- expr : string | number ,
202
+ buf : string | number ,
162
203
) : Promise < number > {
163
- return await denops . call ( "bufwinid" , expr ) as number ;
204
+ return await denops . call ( "bufwinid" , buf ) as number ;
164
205
}
165
206
166
207
/**
167
- * The result is a Number, which is the number of the first
168
- * window associated with buffer {expr}. For the use of {expr},
169
- * see |bufname()| above. If buffer {expr } doesn't exist or
170
- * there is no such window, -1 is returned. Example: >
208
+ * Like |bufwinid()| but return the window number instead of the
209
+ * | window-ID|.
210
+ * If buffer {buf } doesn't exist or there is no such window, -1
211
+ * is returned. Example:
171
212
*
172
- * echo "A window containing buffer 1 is " . (bufwinnr(1))
213
+ * echo "A window containing buffer 1 is " . . (bufwinnr(1))
173
214
*
174
215
* The number can be used with |CTRL-W_w| and ":wincmd w"
175
216
* |:wincmd|.
176
- * Only deals with the current tab page.
217
+ *
218
+ * Can also be used as a |method|:
219
+ * FindBuffer()->bufwinnr()
177
220
*/
178
221
export async function bufwinnr (
179
222
denops : Denops ,
180
- expr : string | number ,
223
+ buf : string | number ,
181
224
) : Promise < number > {
182
- return await denops . call ( "bufwinnr" , expr ) as number ;
225
+ return await denops . call ( "bufwinnr" , buf ) as number ;
183
226
}
184
227
185
228
/**
186
229
* Return a |List| with the lines starting from {lnum} to {end}
187
- * (inclusive) in the buffer {expr }. If {end} is omitted, a
230
+ * (inclusive) in the buffer {buf }. If {end} is omitted, a
188
231
* |List| with only the line {lnum} is returned.
189
232
*
190
- * For the use of {expr }, see |bufname()| above.
233
+ * For the use of {buf }, see |bufname()| above.
191
234
*
192
235
* For {lnum} and {end} "$" can be used for the last line of the
193
236
* buffer. Otherwise a number must be used.
@@ -203,37 +246,56 @@ export async function bufwinnr(
203
246
* This function works only for loaded buffers. For unloaded and
204
247
* non-existing buffers, an empty |List| is returned.
205
248
*
206
- * Example: >
249
+ * Example:
207
250
* :let lines = getbufline(bufnr("myfile"), 1, "$")
251
+ *
252
+ * Can also be used as a |method|:
253
+ * GetBufnr()->getbufline(lnum)
208
254
*/
209
255
export async function getbufline (
210
256
denops : Denops ,
211
- expr : string | number ,
257
+ buf : string | number ,
212
258
lnum : string | number ,
213
259
end ?: string | number ,
214
260
) : Promise < string [ ] > {
215
- return await denops . call ( "getbufline" , expr , lnum , end ) as string [ ] ;
261
+ return await denops . call ( "getbufline" , buf , lnum , end ) as string [ ] ;
216
262
}
217
263
218
264
/**
219
- * Set line {lnum} to {text} in buffer {expr}. To insert
220
- * lines use |append()|.
265
+ * Set line {lnum} to {text} in buffer {buf}. This works like
266
+ * |setline()| for the specified buffer.
267
+ *
268
+ * This function works only for loaded buffers. First call
269
+ * |bufload()| if needed.
221
270
*
222
- * For the use of {expr}, see |bufname()| above.
271
+ * To insert lines use |appendbufline()|.
272
+ * Any text properties in {lnum} are cleared.
273
+ * {text} can be a string to set one line, or a list of strings
274
+ * to set multiple lines. If the list extends below the last
275
+ * line then those lines are added.
276
+ *
277
+ * For the use of {buf}, see |bufname()| above.
223
278
*
224
279
* {lnum} is used like with |setline()|.
225
- * This works like |setline()| for the specified buffer.
226
- * On success 0 is returned, on failure 1 is returned.
280
+ * Use "$" to refer to the last line in buffer {buf}.
281
+ * When {lnum} is just below the last line the {text} will be
282
+ * added below the last line.
283
+ *
284
+ * When {buf} is not a valid buffer, the buffer is not loaded or
285
+ * {lnum} is not valid then 1 is returned. In |Vim9| script an
286
+ * error is given.
287
+ * On success 0 is returned.
227
288
*
228
- * If {expr} is not a valid buffer or {lnum} is not valid, an
229
- * error message is given.
289
+ * Can also be used as a |method|, the base is passed as the
290
+ * third argument:
291
+ * GetText()->setbufline(buf, lnum)
230
292
*/
231
293
export async function setbufline (
232
294
denops : Denops ,
233
- expr : string | number ,
295
+ buf : string | number ,
234
296
lnum : string | number ,
235
297
text : string | string [ ] ,
236
298
) : Promise < boolean > {
237
- const result = await denops . call ( "setbufline" , expr , lnum , text ) as number ;
299
+ const result = await denops . call ( "setbufline" , buf , lnum , text ) as number ;
238
300
return ! ! result ;
239
301
}
0 commit comments