Skip to content

Commit 077ebb0

Browse files
committed
👍 Update type definition for common-function
1 parent ab565a9 commit 077ebb0

File tree

1 file changed

+87
-42
lines changed

1 file changed

+87
-42
lines changed

denops_std/function/common.ts

Lines changed: 87 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,50 @@
11
import type { Denops } from "https://deno.land/x/denops_core@v4.0.0/mod.ts";
22

33
/**
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.
610
*
711
* For checking for a supported feature use |has()|.
812
* For checking if a file exists use |filereadable()|.
913
*
1014
* 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.
2115
* 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
2727
* expression. E.g.:
2828
* :let l = [1, 2, 3]
2929
* :echo exists("l[5]")
3030
* 0
3131
* :echo exists("l[xx]")
3232
* E121: Undefined variable: xx
3333
* 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
3448
* :cmdname Ex command: built-in command, user
3549
* command or command modifier |:command|.
3650
* Returns:
@@ -40,7 +54,9 @@ import type { Denops } from "https://deno.land/x/denops_core@v4.0.0/mod.ts";
4054
* To check for a supported command
4155
* always check the return value to be 2.
4256
* :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)
4460
* #event autocommand defined for this event
4561
* #event#pattern autocommand defined for this event and
4662
* pattern (the pattern is taken
@@ -57,10 +73,11 @@ import type { Denops } from "https://deno.land/x/denops_core@v4.0.0/mod.ts";
5773
* supported.
5874
*
5975
* Examples:
60-
* exists("&mouse")
76+
* exists("&shortname")
6177
* exists("$HOSTNAME")
6278
* exists("*strftime")
63-
* exists("*s:MyFunc")
79+
* exists("*s:MyFunc") " only for legacy script
80+
* exists("*MyFunc")
6481
* exists("bufcount")
6582
* exists(":Make")
6683
* exists("#CursorHold")
@@ -72,18 +89,21 @@ import type { Denops } from "https://deno.land/x/denops_core@v4.0.0/mod.ts";
7289
* There must be no space between the symbol (&/$/* /#) and the
7390
* name.
7491
* 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!
7794
* Working example:
7895
* exists(":make")
7996
* NOT working example:
8097
* exists(":make install")
81-
98+
*
8299
* Note that the argument must be a string, not the name of the
83100
* variable itself. For example:
84101
* exists(bufcount)
85102
* This doesn't check for existence of the "bufcount" variable,
86103
* but gets the value of "bufcount", and checks if that exists.
104+
*
105+
* Can also be used as a |method|:
106+
* Varname()->exists()
87107
*/
88108
export async function exists(
89109
denops: Denops,
@@ -98,6 +118,16 @@ export async function exists(
98118
* {feature} argument is a feature name like "nvim-0.2.1" or
99119
* "win32", see below. See also |exists()|.
100120
*
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+
*
101131
* Vim's compile-time feature-names (prefixed with "+") are not
102132
* recognized because Nvim is always compiled with all possible
103133
* features. |feature-compile|
@@ -110,24 +140,29 @@ export async function exists(
110140
* 2. Runtime condition or other pseudo-feature. For example the
111141
* "win32" feature checks if the current system is Windows:
112142
* :if has("win32")
113-
* *feature-list*
143+
* *feature-list*
114144
* 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).
118147
* 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.
119153
* nvim This is Nvim.
120-
* python2 Legacy Vim |python2| interface. |has-python|
121154
* python3 Legacy Vim |python3| interface. |has-python|
122155
* 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).
125159
* unix Unix system.
126160
* *vim_starting* True during |startup|.
127161
* 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.
129164
*
130-
* *has-patch*
165+
* *has-patch*
131166
* 3. Vim patch. For example the "patch123" feature means that
132167
* Vim patch 123 at the current |v:version| was included:
133168
* :if v:version > 602 || v:version == 602 && has("patch148")
@@ -147,26 +182,29 @@ export async function has(
147182

148183
/**
149184
* Without {end} the result is a String, which is line {lnum}
150-
* from the current buffer. Example: >
185+
* from the current buffer. Example:
151186
* getline(1)
152187
* 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:
155190
* 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.
158193
*
159194
* When {end} is given the result is a |List| where each item is
160195
* a line from the current buffer in the range {lnum} to {end},
161196
* including line {end}.
162197
* {end} is used in the same way as {lnum}.
163198
* Non-existing lines are silently omitted.
164199
* When {end} is before {lnum} an empty |List| is returned.
165-
* Example: >
200+
* Example:
166201
* :let start = line('.')
167202
* :let end = search("^$") - 1
168203
* :let lines = getline(start, end)
169204
*
205+
* Can also be used as a |method|:
206+
* ComputeLnum()->getline()
207+
*
170208
* To get lines from another buffer see |getbufline()|
171209
*/
172210
export async function getline(
@@ -189,14 +227,17 @@ export async function getline(
189227
/**
190228
* Set line {lnum} of the current buffer to {text}. To insert
191229
* lines use |append()|. To set lines in another buffer use
192-
* |setbufline()|.
230+
* |setbufline()|. Any text properties in {lnum} are cleared.
193231
*
194232
* {lnum} is used like with |getline()|.
195233
* 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.
197237
*
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.
200241
*
201242
* Example:
202243
* :call setline(5, strftime("%c"))
@@ -210,6 +251,10 @@ export async function getline(
210251
* :endfor
211252
*
212253
* 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)
213258
*/
214259
export async function setline(
215260
denops: Denops,

0 commit comments

Comments
 (0)