1
1
import type { Denops } from "https://deno.land/x/denops_core@v4.0.0/mod.ts" ;
2
2
3
3
/**
4
- * The result is a Number, which is |TRUE| if {expr} is
5
- * defined, zero otherwise.
4
+ * The result is a Number, which is |TRUE| if {expr} is defined,
5
+ * zero otherwise.
6
+ *
7
+ * Note: In a compiled |:def| function the evaluation is done at
8
+ * runtime. Use `exists_compiled()` to evaluate the expression
9
+ * at compile time.
6
10
*
7
11
* For checking for a supported feature use |has()|.
8
12
* For checking if a file exists use |filereadable()|.
9
13
*
10
14
* The {expr} argument is a string, which contains one of these:
11
- * &option-name Vim option (only checks if it exists,
12
- * not if it really works)
13
- * +option-name Vim option that works.
14
- * $ENVNAME environment variable (could also be
15
- * done by comparing with an empty
16
- * string)
17
- * *funcname built-in function (see |functions|)
18
- * or user defined function (see
19
- * |user-functions|). Also works for a
20
- * variable that is a Funcref.
21
15
* varname internal variable (see
22
- * |internal-variables|). Also works
23
- * for |curly-braces-names|, |Dictionary|
24
- * entries, |List| items, etc. Beware
25
- * that evaluating an index may cause an
26
- * error message for an invalid
16
+ * dict.key |internal-variables|). Also works
17
+ * list[i] for |curly-braces-names|, |Dictionary|
18
+ * import.Func entries, |List| items, imported
19
+ * items, etc.
20
+ * Does not work for local variables in a
21
+ * compiled `:def` function.
22
+ * Also works for a function in |Vim9|
23
+ * script, since it can be used as a
24
+ * function reference.
25
+ * Beware that evaluating an index may
26
+ * cause an error message for an invalid
27
27
* expression. E.g.:
28
28
* :let l = [1, 2, 3]
29
29
* :echo exists("l[5]")
30
30
* 0
31
31
* :echo exists("l[xx]")
32
32
* E121: Undefined variable: xx
33
33
* 0
34
+ * &option-name Vim option (only checks if it exists,
35
+ * not if it really works)
36
+ * +option-name Vim option that works.
37
+ * $ENVNAME environment variable (could also be
38
+ * done by comparing with an empty
39
+ * string)
40
+ * *funcname built-in function (see |functions|)
41
+ * or user defined function (see
42
+ * |user-functions|) that is implemented.
43
+ * Also works for a variable that is a
44
+ * Funcref.
45
+ * ?funcname built-in function that could be
46
+ * implemented; to be used to check if
47
+ * "funcname" is valid
34
48
* :cmdname Ex command: built-in command, user
35
49
* command or command modifier |:command|.
36
50
* Returns:
@@ -40,7 +54,9 @@ import type { Denops } from "https://deno.land/x/denops_core@v4.0.0/mod.ts";
40
54
* To check for a supported command
41
55
* always check the return value to be 2.
42
56
* :2match The |:2match| command.
43
- * :3match The |:3match| command.
57
+ * :3match The |:3match| command (but you
58
+ * probably should not use it, it is
59
+ * reserved for internal usage)
44
60
* #event autocommand defined for this event
45
61
* #event#pattern autocommand defined for this event and
46
62
* pattern (the pattern is taken
@@ -57,10 +73,11 @@ import type { Denops } from "https://deno.land/x/denops_core@v4.0.0/mod.ts";
57
73
* supported.
58
74
*
59
75
* Examples:
60
- * exists("&mouse ")
76
+ * exists("&shortname ")
61
77
* exists("$HOSTNAME")
62
78
* exists("*strftime")
63
- * exists("*s:MyFunc")
79
+ * exists("*s:MyFunc") " only for legacy script
80
+ * exists("*MyFunc")
64
81
* exists("bufcount")
65
82
* exists(":Make")
66
83
* exists("#CursorHold")
@@ -72,18 +89,21 @@ import type { Denops } from "https://deno.land/x/denops_core@v4.0.0/mod.ts";
72
89
* There must be no space between the symbol (&/$/* /#) and the
73
90
* name.
74
91
* There must be no extra characters after the name, although in
75
- * a few cases this is ignored. That may become more strict in
76
- * the future, thus don't count on it!
92
+ * a few cases this is ignored. That may become stricter in the
93
+ * future, thus don't count on it!
77
94
* Working example:
78
95
* exists(":make")
79
96
* NOT working example:
80
97
* exists(":make install")
81
-
98
+ *
82
99
* Note that the argument must be a string, not the name of the
83
100
* variable itself. For example:
84
101
* exists(bufcount)
85
102
* This doesn't check for existence of the "bufcount" variable,
86
103
* but gets the value of "bufcount", and checks if that exists.
104
+ *
105
+ * Can also be used as a |method|:
106
+ * Varname()->exists()
87
107
*/
88
108
export async function exists (
89
109
denops : Denops ,
@@ -98,6 +118,16 @@ export async function exists(
98
118
* {feature} argument is a feature name like "nvim-0.2.1" or
99
119
* "win32", see below. See also |exists()|.
100
120
*
121
+ * If the code has a syntax error, then Nvim may skip the rest
122
+ * of the line and miss |:endif|.
123
+ * if has('feature') | let x = this->breaks->without->the->feature | endif
124
+ *
125
+ * Put |:if| and |:endif| on separate lines to avoid the
126
+ * syntax error.
127
+ * if has('feature')
128
+ * let x = this->breaks->without->the->feature
129
+ * endif
130
+ *
101
131
* Vim's compile-time feature-names (prefixed with "+") are not
102
132
* recognized because Nvim is always compiled with all possible
103
133
* features. |feature-compile|
@@ -110,24 +140,29 @@ export async function exists(
110
140
* 2. Runtime condition or other pseudo-feature. For example the
111
141
* "win32" feature checks if the current system is Windows:
112
142
* :if has("win32")
113
- * *feature-list*
143
+ * *feature-list*
114
144
* List of supported pseudo-feature names:
115
- * acl |ACL| support
116
- * iconv Can use |iconv()| for conversion.
117
- * +shellslash Can use backslashes in filenames (Windows)
145
+ * acl |ACL| support.
146
+ * bsd BSD system (not macOS, use "mac" for that).
118
147
* clipboard |clipboard| provider is available.
148
+ * fname_case Case in file names matters (for Darwin and MS-Windows
149
+ * this is not present).
150
+ * iconv Can use |iconv()| for conversion.
151
+ * linux Linux system.
152
+ * mac MacOS system.
119
153
* nvim This is Nvim.
120
- * python2 Legacy Vim |python2| interface. |has-python|
121
154
* python3 Legacy Vim |python3| interface. |has-python|
122
155
* pythonx Legacy Vim |python_x| interface. |has-pythonx|
123
- * ttyin input is a terminal (tty)
124
- * ttyout output is a terminal (tty)
156
+ * sun SunOS system.
157
+ * ttyin input is a terminal (tty).
158
+ * ttyout output is a terminal (tty).
125
159
* unix Unix system.
126
160
* *vim_starting* True during |startup|.
127
161
* win32 Windows system (32 or 64 bit).
128
- * wsl WSL (Windows Subsystem for Linux) system
162
+ * win64 Windows system (64 bit).
163
+ * wsl WSL (Windows Subsystem for Linux) system.
129
164
*
130
- * *has-patch*
165
+ * *has-patch*
131
166
* 3. Vim patch. For example the "patch123" feature means that
132
167
* Vim patch 123 at the current |v:version| was included:
133
168
* :if v:version > 602 || v:version == 602 && has("patch148")
@@ -147,26 +182,29 @@ export async function has(
147
182
148
183
/**
149
184
* Without {end} the result is a String, which is line {lnum}
150
- * from the current buffer. Example: >
185
+ * from the current buffer. Example:
151
186
* getline(1)
152
187
* When {lnum} is a String that doesn't start with a
153
- * digit, line() is called to translate the String into a Number.
154
- * To get the line under the cursor: >
188
+ * digit, | line()| is called to translate the String into a Number.
189
+ * To get the line under the cursor:
155
190
* getline(".")
156
- * When {lnum} is smaller than 1 or bigger than the number of
157
- * lines in the buffer, an empty string is returned.
191
+ * When {lnum} is a number smaller than 1 or bigger than the
192
+ * number of lines in the buffer, an empty string is returned.
158
193
*
159
194
* When {end} is given the result is a |List| where each item is
160
195
* a line from the current buffer in the range {lnum} to {end},
161
196
* including line {end}.
162
197
* {end} is used in the same way as {lnum}.
163
198
* Non-existing lines are silently omitted.
164
199
* When {end} is before {lnum} an empty |List| is returned.
165
- * Example: >
200
+ * Example:
166
201
* :let start = line('.')
167
202
* :let end = search("^$") - 1
168
203
* :let lines = getline(start, end)
169
204
*
205
+ * Can also be used as a |method|:
206
+ * ComputeLnum()->getline()
207
+ *
170
208
* To get lines from another buffer see |getbufline()|
171
209
*/
172
210
export async function getline (
@@ -189,14 +227,17 @@ export async function getline(
189
227
/**
190
228
* Set line {lnum} of the current buffer to {text}. To insert
191
229
* lines use |append()|. To set lines in another buffer use
192
- * |setbufline()|.
230
+ * |setbufline()|. Any text properties in {lnum} are cleared.
193
231
*
194
232
* {lnum} is used like with |getline()|.
195
233
* When {lnum} is just below the last line the {text} will be
196
- * added as a new line.
234
+ * added below the last line.
235
+ * {text} can be any type or a List of any type, each item is
236
+ * converted to a String.
197
237
*
198
- * If this succeeds, 0 is returned. If this fails (most likely
199
- * because {lnum} is invalid) 1 is returned.
238
+ * If this succeeds, FALSE is returned. If this fails (most likely
239
+ * because {lnum} is invalid) TRUE is returned.
240
+ * In |Vim9| script an error is given if {lnum} is invalid.
200
241
*
201
242
* Example:
202
243
* :call setline(5, strftime("%c"))
@@ -210,6 +251,10 @@ export async function getline(
210
251
* :endfor
211
252
*
212
253
* Note: The '[ and '] marks are not set.
254
+ *
255
+ * Can also be used as a |method|, the base is passed as the
256
+ * second argument:
257
+ * GetText()->setline(lnum)
213
258
*/
214
259
export async function setline (
215
260
denops : Denops ,
0 commit comments