mirror of
https://github.com/vim/vim.git
synced 2025-09-27 04:14:06 -04:00
updated for version 7.4.310
Problem: getpos()/setpos() don't include curswant. Solution: Add a fifth number when getting/setting the cursor.
This commit is contained in:
@@ -2587,9 +2587,14 @@ cursor({lnum}, {col} [, {off}]) *cursor()*
|
|||||||
cursor({list})
|
cursor({list})
|
||||||
Positions the cursor at the column (byte count) {col} in the
|
Positions the cursor at the column (byte count) {col} in the
|
||||||
line {lnum}. The first column is one.
|
line {lnum}. The first column is one.
|
||||||
|
|
||||||
When there is one argument {list} this is used as a |List|
|
When there is one argument {list} this is used as a |List|
|
||||||
with two or three items {lnum}, {col} and {off}. This is like
|
with two, three or four item:
|
||||||
the return value of |getpos()|, but without the first item.
|
[{lnum}, {col}, {off}]
|
||||||
|
[{lnum}, {col}, {off}, {curswant}]
|
||||||
|
This is like the return value of |getpos()|, but without the
|
||||||
|
first item.
|
||||||
|
|
||||||
Does not change the jumplist.
|
Does not change the jumplist.
|
||||||
If {lnum} is greater than the number of lines in the buffer,
|
If {lnum} is greater than the number of lines in the buffer,
|
||||||
the cursor will be positioned at the last line in the buffer.
|
the cursor will be positioned at the last line in the buffer.
|
||||||
@@ -4481,8 +4486,9 @@ getpid() Return a Number which is the process ID of the Vim process.
|
|||||||
*getpos()*
|
*getpos()*
|
||||||
getpos({expr}) Get the position for {expr}. For possible values of {expr}
|
getpos({expr}) Get the position for {expr}. For possible values of {expr}
|
||||||
see |line()|.
|
see |line()|.
|
||||||
The result is a |List| with four numbers:
|
The result is a |List| with four or five numbers:
|
||||||
[bufnum, lnum, col, off]
|
[bufnum, lnum, col, off]
|
||||||
|
[bufnum, lnum, col, off, curswant]
|
||||||
"bufnum" is zero, unless a mark like '0 or 'A is used, then it
|
"bufnum" is zero, unless a mark like '0 or 'A is used, then it
|
||||||
is the buffer number of the mark.
|
is the buffer number of the mark.
|
||||||
"lnum" and "col" are the position in the buffer. The first
|
"lnum" and "col" are the position in the buffer. The first
|
||||||
@@ -4491,6 +4497,8 @@ getpos({expr}) Get the position for {expr}. For possible values of {expr}
|
|||||||
it is the offset in screen columns from the start of the
|
it is the offset in screen columns from the start of the
|
||||||
character. E.g., a position within a <Tab> or after the last
|
character. E.g., a position within a <Tab> or after the last
|
||||||
character.
|
character.
|
||||||
|
The "curswant" number is only added for getpos('.'), it is the
|
||||||
|
preferred column when moving the cursor vertically.
|
||||||
Note that for '< and '> Visual mode matters: when it is "V"
|
Note that for '< and '> Visual mode matters: when it is "V"
|
||||||
(visual line mode) the column of '< is zero and the column of
|
(visual line mode) the column of '< is zero and the column of
|
||||||
'> is a large number.
|
'> is a large number.
|
||||||
@@ -5298,8 +5306,9 @@ setpos({expr}, {list})
|
|||||||
. the cursor
|
. the cursor
|
||||||
'x mark x
|
'x mark x
|
||||||
|
|
||||||
{list} must be a |List| with four numbers:
|
{list} must be a |List| with four or five numbers:
|
||||||
[bufnum, lnum, col, off]
|
[bufnum, lnum, col, off]
|
||||||
|
[bufnum, lnum, col, off, curswant]
|
||||||
|
|
||||||
"bufnum" is the buffer number. Zero can be used for the
|
"bufnum" is the buffer number. Zero can be used for the
|
||||||
current buffer. Setting the cursor is only possible for
|
current buffer. Setting the cursor is only possible for
|
||||||
@@ -5317,6 +5326,12 @@ setpos({expr}, {list})
|
|||||||
character. E.g., a position within a <Tab> or after the last
|
character. E.g., a position within a <Tab> or after the last
|
||||||
character.
|
character.
|
||||||
|
|
||||||
|
The "curswant" number is only used when setting the cursor
|
||||||
|
position. It sets the preferred column for when moving the
|
||||||
|
cursor vertically. When the "curswant" number is missing the
|
||||||
|
preferred column is not set. When it is present and setting a
|
||||||
|
mark position it is not used.
|
||||||
|
|
||||||
Note that for '< and '> changing the line number may result in
|
Note that for '< and '> changing the line number may result in
|
||||||
the marks to be effectively be swapped, so that '< is always
|
the marks to be effectively be swapped, so that '< is always
|
||||||
before '>.
|
before '>.
|
||||||
@@ -5327,7 +5342,10 @@ setpos({expr}, {list})
|
|||||||
Also see |getpos()|
|
Also see |getpos()|
|
||||||
|
|
||||||
This does not restore the preferred column for moving
|
This does not restore the preferred column for moving
|
||||||
vertically. See |winrestview()| for that.
|
vertically; if you set the cursor position with this, |j| and
|
||||||
|
|k| motions will jump to previous columns! Use |cursor()| to
|
||||||
|
also set the preferred column. Also see the "curswant" key in
|
||||||
|
|winrestview()|.
|
||||||
|
|
||||||
|
|
||||||
setqflist({list} [, {action}]) *setqflist()*
|
setqflist({list} [, {action}]) *setqflist()*
|
||||||
|
28
src/eval.c
28
src/eval.c
@@ -764,7 +764,7 @@ static void f_winwidth __ARGS((typval_T *argvars, typval_T *rettv));
|
|||||||
static void f_writefile __ARGS((typval_T *argvars, typval_T *rettv));
|
static void f_writefile __ARGS((typval_T *argvars, typval_T *rettv));
|
||||||
static void f_xor __ARGS((typval_T *argvars, typval_T *rettv));
|
static void f_xor __ARGS((typval_T *argvars, typval_T *rettv));
|
||||||
|
|
||||||
static int list2fpos __ARGS((typval_T *arg, pos_T *posp, int *fnump));
|
static int list2fpos __ARGS((typval_T *arg, pos_T *posp, int *fnump, colnr_T *curswantp));
|
||||||
static pos_T *var2fpos __ARGS((typval_T *varp, int dollar_lnum, int *fnum));
|
static pos_T *var2fpos __ARGS((typval_T *varp, int dollar_lnum, int *fnum));
|
||||||
static int get_env_len __ARGS((char_u **arg));
|
static int get_env_len __ARGS((char_u **arg));
|
||||||
static int get_id_len __ARGS((char_u **arg));
|
static int get_id_len __ARGS((char_u **arg));
|
||||||
@@ -9799,14 +9799,17 @@ f_cursor(argvars, rettv)
|
|||||||
if (argvars[1].v_type == VAR_UNKNOWN)
|
if (argvars[1].v_type == VAR_UNKNOWN)
|
||||||
{
|
{
|
||||||
pos_T pos;
|
pos_T pos;
|
||||||
|
colnr_T curswant = -1;
|
||||||
|
|
||||||
if (list2fpos(argvars, &pos, NULL) == FAIL)
|
if (list2fpos(argvars, &pos, NULL, &curswant) == FAIL)
|
||||||
return;
|
return;
|
||||||
line = pos.lnum;
|
line = pos.lnum;
|
||||||
col = pos.col;
|
col = pos.col;
|
||||||
#ifdef FEAT_VIRTUALEDIT
|
#ifdef FEAT_VIRTUALEDIT
|
||||||
coladd = pos.coladd;
|
coladd = pos.coladd;
|
||||||
#endif
|
#endif
|
||||||
|
if (curswant >= 0)
|
||||||
|
curwin->w_curswant = curswant - 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -11770,6 +11773,8 @@ f_getpos(argvars, rettv)
|
|||||||
(fp != NULL) ? (varnumber_T)fp->coladd :
|
(fp != NULL) ? (varnumber_T)fp->coladd :
|
||||||
#endif
|
#endif
|
||||||
(varnumber_T)0);
|
(varnumber_T)0);
|
||||||
|
if (fp == &curwin->w_cursor)
|
||||||
|
list_append_number(l, (varnumber_T)curwin->w_curswant + 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
rettv->vval.v_number = FALSE;
|
rettv->vval.v_number = FALSE;
|
||||||
@@ -16751,12 +16756,13 @@ f_setpos(argvars, rettv)
|
|||||||
pos_T pos;
|
pos_T pos;
|
||||||
int fnum;
|
int fnum;
|
||||||
char_u *name;
|
char_u *name;
|
||||||
|
colnr_T curswant = -1;
|
||||||
|
|
||||||
rettv->vval.v_number = -1;
|
rettv->vval.v_number = -1;
|
||||||
name = get_tv_string_chk(argvars);
|
name = get_tv_string_chk(argvars);
|
||||||
if (name != NULL)
|
if (name != NULL)
|
||||||
{
|
{
|
||||||
if (list2fpos(&argvars[1], &pos, &fnum) == OK)
|
if (list2fpos(&argvars[1], &pos, &fnum, &curswant) == OK)
|
||||||
{
|
{
|
||||||
if (--pos.col < 0)
|
if (--pos.col < 0)
|
||||||
pos.col = 0;
|
pos.col = 0;
|
||||||
@@ -16766,6 +16772,8 @@ f_setpos(argvars, rettv)
|
|||||||
if (fnum == curbuf->b_fnum)
|
if (fnum == curbuf->b_fnum)
|
||||||
{
|
{
|
||||||
curwin->w_cursor = pos;
|
curwin->w_cursor = pos;
|
||||||
|
if (curswant >= 0)
|
||||||
|
curwin->w_curswant = curswant - 1;
|
||||||
check_cursor();
|
check_cursor();
|
||||||
rettv->vval.v_number = 0;
|
rettv->vval.v_number = 0;
|
||||||
}
|
}
|
||||||
@@ -19532,21 +19540,22 @@ var2fpos(varp, dollar_lnum, fnum)
|
|||||||
* validity.
|
* validity.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
list2fpos(arg, posp, fnump)
|
list2fpos(arg, posp, fnump, curswantp)
|
||||||
typval_T *arg;
|
typval_T *arg;
|
||||||
pos_T *posp;
|
pos_T *posp;
|
||||||
int *fnump;
|
int *fnump;
|
||||||
|
colnr_T *curswantp;
|
||||||
{
|
{
|
||||||
list_T *l = arg->vval.v_list;
|
list_T *l = arg->vval.v_list;
|
||||||
long i = 0;
|
long i = 0;
|
||||||
long n;
|
long n;
|
||||||
|
|
||||||
/* List must be: [fnum, lnum, col, coladd], where "fnum" is only there
|
/* List must be: [fnum, lnum, col, coladd, curswant], where "fnum" is only
|
||||||
* when "fnump" isn't NULL and "coladd" is optional. */
|
* there when "fnump" isn't NULL; "coladd" and "curswant" are optional. */
|
||||||
if (arg->v_type != VAR_LIST
|
if (arg->v_type != VAR_LIST
|
||||||
|| l == NULL
|
|| l == NULL
|
||||||
|| l->lv_len < (fnump == NULL ? 2 : 3)
|
|| l->lv_len < (fnump == NULL ? 2 : 3)
|
||||||
|| l->lv_len > (fnump == NULL ? 3 : 4))
|
|| l->lv_len > (fnump == NULL ? 4 : 5))
|
||||||
return FAIL;
|
return FAIL;
|
||||||
|
|
||||||
if (fnump != NULL)
|
if (fnump != NULL)
|
||||||
@@ -19570,13 +19579,16 @@ list2fpos(arg, posp, fnump)
|
|||||||
posp->col = n;
|
posp->col = n;
|
||||||
|
|
||||||
#ifdef FEAT_VIRTUALEDIT
|
#ifdef FEAT_VIRTUALEDIT
|
||||||
n = list_find_nr(l, i, NULL);
|
n = list_find_nr(l, i, NULL); /* off */
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
posp->coladd = 0;
|
posp->coladd = 0;
|
||||||
else
|
else
|
||||||
posp->coladd = n;
|
posp->coladd = n;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (curswantp != NULL)
|
||||||
|
*curswantp = list_find_nr(l, i + 1, NULL); /* curswant */
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -190,9 +190,18 @@ endfun
|
|||||||
:$put =v:exception
|
:$put =v:exception
|
||||||
:endtry
|
:endtry
|
||||||
:"
|
:"
|
||||||
|
:$put ='{{{1 setpos/getpos'
|
||||||
|
/^012345678
|
||||||
|
6l:let sp = getpos('.')
|
||||||
|
0:call setpos('.', sp)
|
||||||
|
jyl:$put
|
||||||
|
:"
|
||||||
:/^start:/+1,$wq! test.out
|
:/^start:/+1,$wq! test.out
|
||||||
:" vim: et ts=4 isk-=\: fmr=???,???
|
:" vim: et ts=4 isk-=\: fmr=???,???
|
||||||
:call getchar()
|
:call getchar()
|
||||||
ENDTEST
|
ENDTEST
|
||||||
|
|
||||||
|
012345678
|
||||||
|
012345678
|
||||||
|
|
||||||
start:
|
start:
|
||||||
|
Binary file not shown.
@@ -734,6 +734,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
310,
|
||||||
/**/
|
/**/
|
||||||
309,
|
309,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user