src/evalfunc.c
static void
f_cursor(typval_T *argvars, typval_T *rettv)
{
    long	line, col;
    long	coladd = 0;
    int		set_curswant = TRUE;

    rettv->vval.v_number = -1;
    if (argvars[1].v_type == VAR_UNKNOWN)
    {
	pos_T	    pos;
	colnr_T	    curswant = -1;

	if (list2fpos(argvars, &pos, NULL, &curswant) == FAIL)
	{
	    emsg(_(e_invarg));
	    return;
	}
	line = pos.lnum;
	col = pos.col;
	coladd = pos.coladd;
	if (curswant >= 0)
	{
	    curwin->w_curswant = curswant - 1;
	    set_curswant = FALSE;
	}
    }
    else
    {
	line = tv_get_lnum(argvars);
	col = (long)tv_get_number_chk(&argvars[1], NULL);
	if (argvars[2].v_type != VAR_UNKNOWN)
	    coladd = (long)tv_get_number_chk(&argvars[2], NULL);
    }
    if (line < 0 || col < 0 || coladd < 0)
	return;		// type error; errmsg already given
    if (line > 0)
	curwin->w_cursor.lnum = line;
    if (col > 0)
	curwin->w_cursor.col = col - 1;
    curwin->w_cursor.coladd = coladd;

    // Make sure the cursor is in a valid position.
    check_cursor();
    // Correct cursor for multi-byte character.
    if (has_mbyte)
	mb_adjust_cursor();

    curwin->w_set_curswant = set_curswant;
    rettv->vval.v_number = 0;
}
/*
 * "cursor(lnum, col)" function, or
 * "cursor(list)"
 *
 * Moves the cursor to the specified line and column.
 * Returns 0 when the position could be set, -1 otherwise.
 */


Moves the cursor to the specified line and column.
Returns 0 when the position could be set, -1 otherwise.
Moves the cursor to the specified line and column . Returns 0 when the position could be set - 1 otherwise .
static void
f_cursor(typval_T *argvars, typval_T *rettv)
{
    long	line, col;
    long	coladd = 0;
    int		set_curswant = TRUE;
    rettv->vval.v_number = -1;
    if (argvars[1].v_type == VAR_UNKNOWN)
    {
	pos_T	    pos;
	colnr_T	    curswant = -1;
	if (list2fpos(argvars, &pos, NULL, &curswant) == FAIL)
	{
	    emsg(_(e_invarg));
	    return;
	}
	line = pos.lnum;
	col = pos.col;
	coladd = pos.coladd;
	if (curswant >= 0)
	{
	    curwin->w_curswant = curswant - 1;
	    set_curswant = FALSE;
	}
    }
    else
    {
	line = tv_get_lnum(argvars);
	col = (long)tv_get_number_chk(&argvars[1], NULL);
	if (argvars[2].v_type != VAR_UNKNOWN)
	    coladd = (long)tv_get_number_chk(&argvars[2], NULL);
    }
    if (line < 0 || col < 0 || coladd < 0)
	return;		
    if (line > 0)
	curwin->w_cursor.lnum = line;
    if (col > 0)
	curwin->w_cursor.col = col - 1;
    curwin->w_cursor.coladd = coladd;
    check_cursor();
    if (has_mbyte)
	mb_adjust_cursor();
    curwin->w_set_curswant = set_curswant;
    rettv->vval.v_number = 0;
}
static void f_cursor ( typval_T * argvars , typval_T * rettv ) { long line , col ; long coladd = 0 ; int set_curswant = TRUE ; rettv -> vval . v_number = -1 ; if ( argvars [ 1 ] . v_type == VAR_UNKNOWN ) { pos_T pos ; colnr_T curswant = -1 ; if ( list2fpos ( argvars , & pos , NULL , & curswant ) == FAIL ) { emsg ( _ ( e_invarg ) ) ; return ; } line = pos . lnum ; col = pos . col ; coladd = pos . coladd ; if ( curswant >= 0 ) { curwin -> w_curswant = curswant - 1 ; set_curswant = FALSE ; } } else { line = tv_get_lnum ( argvars ) ; col = ( long ) tv_get_number_chk ( & argvars [ 1 ] , NULL ) ; if ( argvars [ 2 ] . v_type != VAR_UNKNOWN ) coladd = ( long ) tv_get_number_chk ( & argvars [ 2 ] , NULL ) ; } if ( line < 0 || col < 0 || coladd < 0 ) return ; if ( line > 0 ) curwin -> w_cursor . lnum = line ; if ( col > 0 ) curwin -> w_cursor . col = col - 1 ; curwin -> w_cursor . coladd = coladd ; check_cursor ( ) ; if ( has_mbyte ) mb_adjust_cursor ( ) ; curwin -> w_set_curswant = set_curswant ; rettv -> vval . v_number = 0 ; }
"cursor(lnum, col)" function, or
 "cursor(list)"
" cursor ( lnum col ) " function or " cursor ( list ) "
// type error; errmsg already given // Make sure the cursor is in a valid position. // Correct cursor for multi-byte character.