-
Notifications
You must be signed in to change notification settings - Fork 15
/
common.ts
221 lines (216 loc) Β· 7.15 KB
/
common.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import type { Denops } from "https://deno.land/x/denops_core@v3.0.1/mod.ts";
/**
* The result is a Number, which is |TRUE| if {expr} is
* defined, zero otherwise.
*
* For checking for a supported feature use |has()|.
* For checking if a file exists use |filereadable()|.
*
* The {expr} argument is a string, which contains one of these:
* &option-name Vim option (only checks if it exists,
* not if it really works)
* +option-name Vim option that works.
* $ENVNAME environment variable (could also be
* done by comparing with an empty
* string)
* *funcname built-in function (see |functions|)
* or user defined function (see
* |user-functions|). Also works for a
* variable that is a Funcref.
* varname internal variable (see
* |internal-variables|). Also works
* for |curly-braces-names|, |Dictionary|
* entries, |List| items, etc. Beware
* that evaluating an index may cause an
* error message for an invalid
* expression. E.g.:
* :let l = [1, 2, 3]
* :echo exists("l[5]")
* 0
* :echo exists("l[xx]")
* E121: Undefined variable: xx
* 0
* :cmdname Ex command: built-in command, user
* command or command modifier |:command|.
* Returns:
* 1 for match with start of a command
* 2 full match with a command
* 3 matches several user commands
* To check for a supported command
* always check the return value to be 2.
* :2match The |:2match| command.
* :3match The |:3match| command.
* #event autocommand defined for this event
* #event#pattern autocommand defined for this event and
* pattern (the pattern is taken
* literally and compared to the
* autocommand patterns character by
* character)
* #group autocommand group exists
* #group#event autocommand defined for this group and
* event.
* #group#event#pattern
* autocommand defined for this group,
* event and pattern.
* ##event autocommand for this event is
* supported.
*
* Examples:
* exists("&mouse")
* exists("$HOSTNAME")
* exists("*strftime")
* exists("*s:MyFunc")
* exists("bufcount")
* exists(":Make")
* exists("#CursorHold")
* exists("#BufReadPre#*.gz")
* exists("#filetypeindent")
* exists("#filetypeindent#FileType")
* exists("#filetypeindent#FileType#*")
* exists("##ColorScheme")
* There must be no space between the symbol (&/$/* /#) and the
* name.
* There must be no extra characters after the name, although in
* a few cases this is ignored. That may become more strict in
* the future, thus don't count on it!
* Working example:
* exists(":make")
* NOT working example:
* exists(":make install")
* Note that the argument must be a string, not the name of the
* variable itself. For example:
* exists(bufcount)
* This doesn't check for existence of the "bufcount" variable,
* but gets the value of "bufcount", and checks if that exists.
*/
export async function exists(
denops: Denops,
expr: string,
): Promise<boolean> {
const result = await denops.call("exists", expr) as number;
return !!result;
}
/**
* Returns 1 if {feature} is supported, 0 otherwise. The
* {feature} argument is a feature name like "nvim-0.2.1" or
* "win32", see below. See also |exists()|.
*
* Vim's compile-time feature-names (prefixed with "+") are not
* recognized because Nvim is always compiled with all possible
* features. |feature-compile|
*
* Feature names can be:
* 1. Nvim version. For example the "nvim-0.2.1" feature means
* that Nvim is version 0.2.1 or later:
* :if has("nvim-0.2.1")
*
* 2. Runtime condition or other pseudo-feature. For example the
* "win32" feature checks if the current system is Windows:
* :if has("win32")
* *feature-list*
* List of supported pseudo-feature names:
* acl |ACL| support
* iconv Can use |iconv()| for conversion.
* +shellslash Can use backslashes in filenames (Windows)
* clipboard |clipboard| provider is available.
* nvim This is Nvim.
* python2 Legacy Vim |python2| interface. |has-python|
* python3 Legacy Vim |python3| interface. |has-python|
* pythonx Legacy Vim |python_x| interface. |has-pythonx|
* ttyin input is a terminal (tty)
* ttyout output is a terminal (tty)
* unix Unix system.
* *vim_starting* True during |startup|.
* win32 Windows system (32 or 64 bit).
* wsl WSL (Windows Subsystem for Linux) system
*
* *has-patch*
* 3. Vim patch. For example the "patch123" feature means that
* Vim patch 123 at the current |v:version| was included:
* :if v:version > 602 || v:version == 602 && has("patch148")
*
* 4. Vim version. For example the "patch-7.4.237" feature means
* that Nvim is Vim-compatible to version 7.4.237 or later.
* :if has("patch-7.4.237")
*/
export async function has(
denops: Denops,
feature: string,
check?: boolean,
): Promise<boolean> {
const result = await denops.call("has", feature, check) as number;
return !!result;
}
/**
* Without {end} the result is a String, which is line {lnum}
* from the current buffer. Example: >
* getline(1)
* When {lnum} is a String that doesn't start with a
* digit, line() is called to translate the String into a Number.
* To get the line under the cursor: >
* getline(".")
* When {lnum} is smaller than 1 or bigger than the number of
* lines in the buffer, an empty string is returned.
*
* When {end} is given the result is a |List| where each item is
* a line from the current buffer in the range {lnum} to {end},
* including line {end}.
* {end} is used in the same way as {lnum}.
* Non-existing lines are silently omitted.
* When {end} is before {lnum} an empty |List| is returned.
* Example: >
* :let start = line('.')
* :let end = search("^$") - 1
* :let lines = getline(start, end)
*
* To get lines from another buffer see |getbufline()|
*/
export async function getline(
denops: Denops,
lnum: string | number,
): Promise<string>;
export async function getline(
denops: Denops,
lnum: string | number,
end: string | number,
): Promise<string[]>;
export async function getline(
denops: Denops,
lnum: string | number,
end?: string | number,
): Promise<string | string[]> {
return await denops.call("getline", lnum, end) as string;
}
/**
* Set line {lnum} of the current buffer to {text}. To insert
* lines use |append()|. To set lines in another buffer use
* |setbufline()|.
*
* {lnum} is used like with |getline()|.
* When {lnum} is just below the last line the {text} will be
* added as a new line.
*
* If this succeeds, 0 is returned. If this fails (most likely
* because {lnum} is invalid) 1 is returned.
*
* Example:
* :call setline(5, strftime("%c"))
*
* When {text} is a |List| then line {lnum} and following lines
* will be set to the items in the list. Example:
* :call setline(5, ['aaa', 'bbb', 'ccc'])
* This is equivalent to:
* :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
* : call setline(n, l)
* :endfor
*
* Note: The '[ and '] marks are not set.
*/
export async function setline(
denops: Denops,
lnum: string | number,
text: string | string[],
): Promise<boolean> {
const result = await denops.call("setline", lnum, text) as number;
return !!result;
}