11import { Denops } from "../vendor/https/deno.land/x/denops_core/mod.ts" ;
22
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+ */
311export async function bufadd (
412 denops : Denops ,
513 name : string ,
@@ -8,6 +16,28 @@ export async function bufadd(
816 return bufnr as number ;
917}
1018
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+ */
1141export async function bufexists (
1242 denops : Denops ,
1343 name : string | number ,
@@ -16,6 +46,11 @@ export async function bufexists(
1646 return ! ! result ;
1747}
1848
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+ */
1954export async function buflisted (
2055 denops : Denops ,
2156 name : string | number ,
@@ -24,13 +59,27 @@ export async function buflisted(
2459 return ! ! result ;
2560}
2661
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+ */
2771export async function bufload (
2872 denops : Denops ,
2973 name : string | number ,
3074) : Promise < void > {
3175 await denops . call ( "bufload" , name ) ;
3276}
3377
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+ */
3483export async function bufloaded (
3584 denops : Denops ,
3685 name : string | number ,
@@ -39,34 +88,123 @@ export async function bufloaded(
3988 return ! ! result ;
4089}
4190
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+ */
42120export async function bufname (
43121 denops : Denops ,
44122 name ?: string | number ,
45123) : Promise < string > {
46124 return await denops . call ( "bufname" , name ) as string ;
47125}
48126
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+ */
49141export async function bufnr (
50142 denops : Denops ,
51143 name : string | number ,
52144) : Promise < number > {
53145 return await denops . call ( "bufnr" , name ) as number ;
54146}
55147
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+ */
56158export async function bufwinid (
57159 denops : Denops ,
58160 name : string | number ,
59161) : Promise < number > {
60162 return await denops . call ( "bufwinid" , name ) as number ;
61163}
62164
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+ */
63177export async function bufwinnr (
64178 denops : Denops ,
65179 name : string | number ,
66180) : Promise < number > {
67181 return await denops . call ( "bufwinnr" , name ) as number ;
68182}
69183
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+ */
70208export async function getbufline (
71209 denops : Denops ,
72210 name : string | number ,
@@ -76,6 +214,19 @@ export async function getbufline(
76214 return await denops . call ( "getbufline" , name , lnum , end ) as string [ ] ;
77215}
78216
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+ */
79230export async function setbufline (
80231 denops : Denops ,
81232 name : string | number ,
0 commit comments