1
1
import { Denops } from "../vendor/https/deno.land/x/denops_core/mod.ts" ;
2
2
3
+ /**
4
+ * Add a buffer to the buffer list with {name}.
5
+ * If a buffer for file {name} already exists, return that buffer
6
+ * number. Otherwise return the buffer number of the newly
7
+ * created buffer. When {name} is an empty string then a new
8
+ * buffer is always created.
9
+ * The buffer will not have' 'buflisted' set.
10
+ */
3
11
export async function bufadd (
4
12
denops : Denops ,
5
13
name : string ,
@@ -8,6 +16,28 @@ export async function bufadd(
8
16
return bufnr as number ;
9
17
}
10
18
19
+ /**
20
+ * 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.
24
+ *
25
+ * If the {expr} argument is a string it must match a buffer name
26
+ * exactly. The name can be:
27
+ * - Relative to the current directory.
28
+ * - A full path.
29
+ * - The name of a buffer with 'buftype' set to "nofile".
30
+ * - A URL name.
31
+ * Unlisted buffers will be found.
32
+ * Note that help files are listed by their short name in the
33
+ * output of |:buffers|, but bufexists() requires using their
34
+ * long name to be able to find them.
35
+ * bufexists() may report a buffer exists, but to use the name
36
+ * with a |:buffer| command you may need to use |expand()|. Esp
37
+ * for MS-Windows 8.3 names in the form "c:\DOCUME~1"
38
+ * Use "bufexists(0)" to test for the existence of an alternate
39
+ * file name.
40
+ */
11
41
export async function bufexists (
12
42
denops : Denops ,
13
43
name : string | number ,
@@ -16,6 +46,11 @@ export async function bufexists(
16
46
return ! ! result ;
17
47
}
18
48
49
+ /**
50
+ * 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()|.
53
+ */
19
54
export async function buflisted (
20
55
denops : Denops ,
21
56
name : string | number ,
@@ -24,13 +59,27 @@ export async function buflisted(
24
59
return ! ! result ;
25
60
}
26
61
62
+ /**
63
+ * Ensure the buffer {expr} is loaded. When the buffer name
64
+ * refers to an existing file then the file is read. Otherwise
65
+ * the buffer will be empty. If the buffer was already loaded
66
+ * then there is no change.
67
+ * If there is an existing swap file for the file of the buffer,
68
+ * there will be no dialog, the buffer will be loaded anyway.
69
+ * The {expr} argument is used like with |bufexists()|.
70
+ */
27
71
export async function bufload (
28
72
denops : Denops ,
29
73
name : string | number ,
30
74
) : Promise < void > {
31
75
await denops . call ( "bufload" , name ) ;
32
76
}
33
77
78
+ /**
79
+ * 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()|.
82
+ */
34
83
export async function bufloaded (
35
84
denops : Denops ,
36
85
name : string | number ,
@@ -39,34 +88,123 @@ export async function bufloaded(
39
88
return ! ! result ;
40
89
}
41
90
91
+ /**
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.
96
+ * 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
98
+ * with the buffer names. This is always done like 'magic' is
99
+ * set and 'cpoptions' is empty. When there is more than one
100
+ * match an empty string is returned.
101
+ * "" or "%" can be used for the current buffer, "#" for the
102
+ * alternate buffer.
103
+ * A full match is preferred, otherwise a match at the start, end
104
+ * or middle of the buffer name is accepted. If you only want a
105
+ * full match then put "^" at the start and "$" at the end of the
106
+ * pattern.
107
+ * Listed buffers are found first. If there is a single match
108
+ * with a listed buffer, that one is returned. Next unlisted
109
+ * 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)
113
+ * If the buffer doesn't exist, or doesn't have a name, an empty
114
+ * 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.
119
+ */
42
120
export async function bufname (
43
121
denops : Denops ,
44
122
name ?: string | number ,
45
123
) : Promise < string > {
46
124
return await denops . call ( "bufname" , name ) as string ;
47
125
}
48
126
127
+ /**
128
+ * The result is the number of a buffer, as it is displayed by
129
+ * the ":ls" command. For the use of {expr}, see |bufname()|
130
+ * above.
131
+ * 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.
134
+ * bufnr("$") is the last buffer:
135
+ * :let last_buffer = bufnr("$")
136
+ * The result is a Number, which is the highest buffer number
137
+ * of existing buffers. Note that not all buffers with a smaller
138
+ * number necessarily exist, because ":bwipeout" may have removed
139
+ * them. Use bufexists() to test for the existence of a buffer.
140
+ */
49
141
export async function bufnr (
50
142
denops : Denops ,
51
143
name : string | number ,
52
144
) : Promise < number > {
53
145
return await denops . call ( "bufnr" , name ) as number ;
54
146
}
55
147
148
+ /**
149
+ * The result is a Number, which is the |window-ID| of the first
150
+ * window associated with buffer {expr}. For the use of {expr},
151
+ * see |bufname()| above. If buffer {expr} doesn't exist or
152
+ * there is no such window, -1 is returned. Example: >
153
+ *
154
+ * echo "A window containing buffer 1 is " . (bufwinid(1))
155
+ *
156
+ * Only deals with the current tab page.
157
+ */
56
158
export async function bufwinid (
57
159
denops : Denops ,
58
160
name : string | number ,
59
161
) : Promise < number > {
60
162
return await denops . call ( "bufwinid" , name ) as number ;
61
163
}
62
164
165
+ /**
166
+ * The result is a Number, which is the number of the first
167
+ * window associated with buffer {expr}. For the use of {expr},
168
+ * see |bufname()| above. If buffer {expr} doesn't exist or
169
+ * there is no such window, -1 is returned. Example: >
170
+ *
171
+ * echo "A window containing buffer 1 is " . (bufwinnr(1))
172
+ *
173
+ * The number can be used with |CTRL-W_w| and ":wincmd w"
174
+ * |:wincmd|.
175
+ * Only deals with the current tab page.
176
+ */
63
177
export async function bufwinnr (
64
178
denops : Denops ,
65
179
name : string | number ,
66
180
) : Promise < number > {
67
181
return await denops . call ( "bufwinnr" , name ) as number ;
68
182
}
69
183
184
+ /**
185
+ * Return a |List| with the lines starting from {lnum} to {end}
186
+ * (inclusive) in the buffer {expr}. If {end} is omitted, a
187
+ * |List| with only the line {lnum} is returned.
188
+ *
189
+ * For the use of {expr}, see |bufname()| above.
190
+ *
191
+ * For {lnum} and {end} "$" can be used for the last line of the
192
+ * buffer. Otherwise a number must be used.
193
+ *
194
+ * When {lnum} is smaller than 1 or bigger than the number of
195
+ * lines in the buffer, an empty |List| is returned.
196
+ *
197
+ * When {end} is greater than the number of lines in the buffer,
198
+ * it is treated as {end} is set to the number of lines in the
199
+ * buffer. When {end} is before {lnum} an empty |List| is
200
+ * returned.
201
+ *
202
+ * This function works only for loaded buffers. For unloaded and
203
+ * non-existing buffers, an empty |List| is returned.
204
+ *
205
+ * Example: >
206
+ * :let lines = getbufline(bufnr("myfile"), 1, "$")
207
+ */
70
208
export async function getbufline (
71
209
denops : Denops ,
72
210
name : string | number ,
@@ -76,6 +214,19 @@ export async function getbufline(
76
214
return await denops . call ( "getbufline" , name , lnum , end ) as string [ ] ;
77
215
}
78
216
217
+ /**
218
+ * Set line {lnum} to {text} in buffer {expr}. To insert
219
+ * lines use |append()|.
220
+ *
221
+ * For the use of {expr}, see |bufname()| above.
222
+ *
223
+ * {lnum} is used like with |setline()|.
224
+ * This works like |setline()| for the specified buffer.
225
+ * On success 0 is returned, on failure 1 is returned.
226
+ *
227
+ * If {expr} is not a valid buffer or {lnum} is not valid, an
228
+ * error message is given.
229
+ */
79
230
export async function setbufline (
80
231
denops : Denops ,
81
232
name : string | number ,
0 commit comments