@@ -19,23 +19,24 @@ import type { Position, ScreenPos } from "./types.ts";
19
19
* out of range then col() returns zero.
20
20
* To get the line number use |line()|. To get both use
21
21
* |getpos()|.
22
- * For the screen column position use |virtcol()|.
22
+ * For the screen column position use |virtcol()|. For the
23
+ * character position use |charcol()|.
23
24
* Note that only marks in the current file can be used.
24
25
* Examples:
25
26
* col(".") column of cursor
26
27
* col("$") length of cursor line plus one
27
28
* col("'t") column of mark t
28
- * col("'" . markname) column of mark markname
29
- * The first column is 1. 0 is returned for an error .
29
+ * col("'" .. markname) column of mark markname
30
+ * The first column is 1. Returns 0 if {expr} is invalid .
30
31
* For an uppercase mark the column may actually be in another
31
32
* buffer.
32
33
* For the cursor position, when 'virtualedit' is active, the
33
34
* column is one higher if the cursor is after the end of the
34
35
* line. This can be used to obtain the column in Insert mode:
35
- * :imap <F2> <C-O>:let save_ve = &ve<CR
36
- * \<C-O>:set ve=all<CR
37
- * \<C-O>:echo col(".") . "\n" <Bar
38
- * \let &ve = save_ve<CR
36
+ * :imap <F2> <C-O>:let save_ve = &ve<CR>
37
+ * \<C-O>:set ve=all<CR>
38
+ * \<C-O>:echo col(".") .. "\n" <Bar>
39
+ * \let &ve = save_ve<CR>
39
40
* GetPos()->col()
40
41
*/
41
42
export async function col (
@@ -57,12 +58,13 @@ export async function col(
57
58
* set to 8, it returns 8. |conceal| is ignored.
58
59
* For the byte position use |col()|.
59
60
* For the use of {expr} see |col()|.
60
- * When 'virtualedit' is used {expr} can be [lnum, col, off], where
61
- * "off" is the offset in screen columns from the start of the
62
- * character. E.g., a position within a <Tab> or after the last
63
- * character. When "off" is omitted zero is used.
64
- * When Virtual editing is active in the current mode, a position
65
- * beyond the end of the line can be returned. |'virtualedit'|
61
+ * When 'virtualedit' is used {expr} can be [lnum, col, off],
62
+ * where "off" is the offset in screen columns from the start of
63
+ * the character. E.g., a position within a <Tab> or after the
64
+ * last character. When "off" is omitted zero is used. When
65
+ * Virtual editing is active in the current mode, a position
66
+ * beyond the end of the line can be returned. Also see
67
+ * |'virtualedit'|
66
68
* The accepted positions are:
67
69
* . the cursor position
68
70
* $ the end of the cursor line (the result is the
@@ -101,7 +103,8 @@ export async function virtcol(
101
103
102
104
/**
103
105
* The result is a Number, which is the line number of the file
104
- * position given with {expr}. The accepted positions are:
106
+ * position given with {expr}. The {expr} argument is a string.
107
+ * The accepted positions are:
105
108
* . the cursor position
106
109
* $ the last line in the current buffer
107
110
* 'x position of mark x (if the mark is not set, 0 is
@@ -118,17 +121,27 @@ export async function virtcol(
118
121
* then applies to another buffer.
119
122
* To get the column number use |col()|. To get both use
120
123
* |getpos()|.
124
+ * With the optional {winid} argument the values are obtained for
125
+ * that window instead of the current window.
126
+ * Returns 0 for invalid values of {expr} and {winid}.
121
127
* Examples:
122
128
* line(".") line number of the cursor
129
+ * line(".", winid) idem, in window "winid"
123
130
* line("'t") line number of mark t
124
- * line("'" . marker) line number of mark marker
131
+ * line("'" .. marker) line number of mark marker
132
+ *
125
133
* To jump to the last known position when opening a file see
126
134
* |last-position-jump|.
135
+ *
127
136
* Can also be used as a |method|:
128
137
* GetValue()->line()
129
138
*/
130
- export async function line ( denops : Denops , expr : string ) : Promise < number > {
131
- return await denops . call ( "line" , expr ) as number ;
139
+ export async function line (
140
+ denops : Denops ,
141
+ expr : string ,
142
+ winid ?: number | string ,
143
+ ) : Promise < number > {
144
+ return await denops . call ( "line" , expr , winid ) as number ;
132
145
}
133
146
134
147
/**
@@ -154,14 +167,20 @@ export async function winline(denops: Denops): Promise<number> {
154
167
/**
155
168
* Positions the cursor at the column (byte count) {col} in the
156
169
* line {lnum}. The first column is one.
170
+ *
157
171
* When there is one argument {list} this is used as a |List|
158
172
* with two, three or four item:
159
173
* [{lnum}, {col}]
160
174
* [{lnum}, {col}, {off}]
161
175
* [{lnum}, {col}, {off}, {curswant}]
162
176
* This is like the return value of |getpos()| or |getcurpos()|,
163
177
* but without the first item.
178
+ *
179
+ * To position the cursor using the character count, use
180
+ * |setcursorcharpos()|.
181
+ *
164
182
* Does not change the jumplist.
183
+ * {lnum} is used like with |getline()|.
165
184
* If {lnum} is greater than the number of lines in the buffer,
166
185
* the cursor will be positioned at the last line in the buffer.
167
186
* If {lnum} is zero, the cursor will stay in the current line.
@@ -171,10 +190,12 @@ export async function winline(denops: Denops): Promise<number> {
171
190
* If {col} is zero, the cursor will stay in the current column.
172
191
* If {curswant} is given it is used to set the preferred column
173
192
* for vertical movement. Otherwise {col} is used.
193
+ *
174
194
* When 'virtualedit' is used {off} specifies the offset in
175
195
* screen columns from the start of the character. E.g., a
176
196
* position within a <Tab> or after the last character.
177
197
* Returns 0 when the position could be set, -1 otherwise.
198
+ *
178
199
* Can also be used as a |method|:
179
200
* GetCursorPos()->cursor()
180
201
*/
@@ -218,6 +239,14 @@ export async function cursor(
218
239
* The "curscol" value is where the cursor would be placed. For
219
240
* a Tab it would be the same as "endcol", while for a double
220
241
* width character it would be the same as "col".
242
+ * The |conceal| feature is ignored here, the column numbers are
243
+ * as if 'conceallevel' is zero. You can set the cursor to the
244
+ * right position and use |screencol()| to get the value with
245
+ * |conceal| taken into account.
246
+ * If the position is in a closed fold the screen position of the
247
+ * first character is returned, {col} is not used.
248
+ * Returns an empty Dict if {winid} is invalid.
249
+ *
221
250
* Can also be used as a |method|:
222
251
* GetWinid()->screenpos(lnum, col)
223
252
*/
@@ -232,26 +261,42 @@ export async function screenpos(
232
261
233
262
/**
234
263
* Get the position of the cursor. This is like getpos('.'), but
235
- * includes an extra item in the list:
236
- * [bufnum , lnum, col, off, curswant] ~
264
+ * includes an extra "curswant" item in the list:
265
+ * [0 , lnum, col, off, curswant] ~
237
266
* The "curswant" number is the preferred column when moving the
238
- * cursor vertically. Also see |getpos()|.
267
+ * cursor vertically. After |$| command it will be a very large
268
+ * number equal to |v:maxcol|. Also see |getcursorcharpos()| and
269
+ * |getpos()|.
270
+ * The first "bufnum" item is always zero. The byte position of
271
+ * the cursor is returned in 'col'. To get the character
272
+ * position, use |getcursorcharpos()|.
273
+ *
274
+ * The optional {winid} argument can specify the window. It can
275
+ * be the window number or the |window-ID|. The last known
276
+ * cursor position is returned, this may be invalid for the
277
+ * current value of the buffer if it is not the current window.
278
+ * If {winid} is invalid a list with zeroes is returned.
279
+ *
239
280
* This can be used to save and restore the cursor position:
240
281
* let save_cursor = getcurpos()
241
282
* MoveTheCursorAround
242
283
* call setpos('.', save_cursor)
243
284
* Note that this only works within the window. See
244
285
* |winrestview()| for restoring more state.
286
+ *
287
+ * Can also be used as a |method|:
288
+ * GetWinid()->getcurpos()
245
289
*/
246
290
export async function getcurpos (
247
291
denops : Denops ,
292
+ winid ?: number | string ,
248
293
) : Promise < Position > {
249
- return await denops . call ( "getcurpos" ) as Position ;
294
+ return await denops . call ( "getcurpos" , winid ) as Position ;
250
295
}
251
296
252
297
/**
253
- * Get the position for {expr}. For possible values of {expr}
254
- * see |line()|. For getting the cursor position see
298
+ * Get the position for String {expr}. For possible values of
299
+ * {expr} see |line()|. For getting the cursor position see
255
300
* |getcurpos()|.
256
301
* The result is a |List| with four numbers:
257
302
* [bufnum, lnum, col, off]
@@ -265,12 +310,19 @@ export async function getcurpos(
265
310
* character.
266
311
* Note that for '< and '> Visual mode matters: when it is "V"
267
312
* (visual line mode) the column of '< is zero and the column of
268
- * '> is a large number.
313
+ * '> is a large number equal to |v:maxcol|.
314
+ * The column number in the returned List is the byte position
315
+ * within the line. To get the character position in the line,
316
+ * use |getcharpos()|.
317
+ * A very large column number equal to |v:maxcol| can be returned,
318
+ * in which case it means "after the end of the line".
319
+ * If {expr} is invalid, returns a list with all zeros.
269
320
* This can be used to save and restore the position of a mark:
270
321
* let save_a_mark = getpos("'a")
271
322
* ...
272
323
* call setpos("'a", save_a_mark)
273
- * Also see |getcurpos()| and |setpos()|.
324
+ * Also see |getcharpos()|, |getcurpos()| and |setpos()|.
325
+ *
274
326
* Can also be used as a |method|:
275
327
* GetMark()->getpos()
276
328
*/
@@ -279,12 +331,13 @@ export async function getpos(denops: Denops, expr: string): Promise<Position> {
279
331
}
280
332
281
333
/**
282
- * Set the position for {expr}. Possible values:
334
+ * Set the position for String {expr}. Possible values:
283
335
* . the cursor
284
336
* 'x mark x
285
337
* {list} must be a |List| with four or five numbers:
286
338
* [bufnum, lnum, col, off]
287
339
* [bufnum, lnum, col, off, curswant]
340
+ *
288
341
* "bufnum" is the buffer number. Zero can be used for the
289
342
* current buffer. When setting an uppercase mark "bufnum" is
290
343
* used for the mark position. For other marks it specifies the
@@ -293,29 +346,38 @@ export async function getpos(denops: Denops, expr: string): Promise<Position> {
293
346
* For setting the cursor and the ' mark "bufnum" is ignored,
294
347
* since these are associated with a window, not a buffer.
295
348
* Does not change the jumplist.
349
+ *
296
350
* "lnum" and "col" are the position in the buffer. The first
297
351
* column is 1. Use a zero "lnum" to delete a mark. If "col" is
298
- * smaller than 1 then 1 is used.
352
+ * smaller than 1 then 1 is used. To use the character count
353
+ * instead of the byte count, use |setcharpos()|.
354
+ *
299
355
* The "off" number is only used when 'virtualedit' is set. Then
300
356
* it is the offset in screen columns from the start of the
301
357
* character. E.g., a position within a <Tab> or after the last
302
358
* character.
359
+ *
303
360
* The "curswant" number is only used when setting the cursor
304
361
* position. It sets the preferred column for when moving the
305
362
* cursor vertically. When the "curswant" number is missing the
306
363
* preferred column is not set. When it is present and setting a
307
364
* mark position it is not used.
365
+ *
308
366
* Note that for '< and '> changing the line number may result in
309
367
* the marks to be effectively be swapped, so that '< is always
310
368
* before '>.
369
+ *
311
370
* Returns 0 when the position could be set, -1 otherwise.
312
371
* An error message is given if {expr} is invalid.
313
- * Also see |getpos()| and |getcurpos()|.
372
+ *
373
+ * Also see |setcharpos()|, |getpos()| and |getcurpos()|.
374
+ *
314
375
* This does not restore the preferred column for moving
315
376
* vertically; if you set the cursor position with this, |j| and
316
377
* |k| motions will jump to previous columns! Use |cursor()| to
317
378
* also set the preferred column. Also see the "curswant" key in
318
379
* |winrestview()|.
380
+ *
319
381
* Can also be used as a |method|:
320
382
* GetPosition()->setpos('.')
321
383
*/
@@ -334,6 +396,9 @@ export async function setpos(
334
396
* for the current buffer. The first character has byte count
335
397
* one.
336
398
* Also see |line2byte()|, |go| and |:goto|.
399
+ *
400
+ * Returns -1 if the {byte} value is invalid.
401
+ *
337
402
* Can also be used as a |method|:
338
403
* GetOffset()->byte2line()
339
404
* {not available when compiled without the |+byte_offset|
@@ -352,10 +417,11 @@ export async function byte2line(denops: Denops, byte: number): Promise<number> {
352
417
* below the last line:
353
418
* line2byte(line("$") + 1)
354
419
* This is the buffer size plus one. If 'fileencoding' is empty
355
- * it is the file size plus one.
356
- * When {lnum} is invalid, or the |+byte_offset| feature has been
357
- * disabled at compile time, -1 is returned.
420
+ * it is the file size plus one. {lnum} is used like with
421
+ * |getline()|. When {lnum} is invalid, or the |+byte_offset|
422
+ * feature has been disabled at compile time, -1 is returned.
358
423
* Also see |byte2line()|, |go| and |:goto|.
424
+ *
359
425
* Can also be used as a |method|:
360
426
* GetLnum()->line2byte()
361
427
*/
@@ -371,6 +437,7 @@ export async function line2byte(denops: Denops, lnum: number): Promise<number> {
371
437
* {lnum} is used like with |getline()|. Thus "." is the current
372
438
* line, "'m" mark m, etc.
373
439
* Returns 0 if the current window is not in diff mode.
440
+ *
374
441
* Can also be used as a |method|:
375
442
* GetLnum()->diff_filler()
376
443
*/
0 commit comments