From 27f423e734060e8bf00e62c2f95512c0b1511c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dami=C3=A1n=20Silvani?= Date: Mon, 7 Jul 2014 08:24:12 -0300 Subject: [PATCH 1/2] vim-patch:7.4.310 Problem: getpos()/setpos() don't include curswant. Solution: Add a fifth number when getting/setting the cursor. https://code.google.com/p/vim/source/detail?r=ccac0aa34eeaf46dad4b831461a532fc3fe71096 --- src/nvim/eval.c | 30 +++++++++++++++++++++++------- src/nvim/testdir/test_eval.in | 21 +++++++++++++++------ src/nvim/testdir/test_eval.ok | 2 ++ src/nvim/version.c | 2 +- 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 7793f5040c..991c43b842 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -7863,12 +7863,17 @@ static void f_cursor(typval_T *argvars, typval_T *rettv) rettv->vval.v_number = -1; if (argvars[1].v_type == VAR_UNKNOWN) { pos_T pos; + colnr_T curswant = -1; - if (list2fpos(argvars, &pos, NULL) == FAIL) + if (list2fpos(argvars, &pos, NULL, &curswant) == FAIL) { return; + } line = pos.lnum; col = pos.col; coladd = pos.coladd; + if (curswant >= 0) { + curwin->w_curswant = curswant - 1; + } } else { line = get_tv_lnum(argvars); col = get_tv_number_chk(&argvars[1], NULL); @@ -9393,6 +9398,9 @@ static void f_getpos(typval_T *argvars, typval_T *rettv) : (varnumber_T)0); list_append_number(l, (fp != NULL) ? (varnumber_T)fp->coladd : (varnumber_T)0); + if (fp == &curwin->w_cursor) { + list_append_number(l, (varnumber_T) curwin->w_curswant + 1); + } } /* @@ -13118,17 +13126,21 @@ static void f_setpos(typval_T *argvars, typval_T *rettv) pos_T pos; int fnum; char_u *name; + colnr_T curswant = -1; rettv->vval.v_number = -1; name = get_tv_string_chk(argvars); if (name != NULL) { - if (list2fpos(&argvars[1], &pos, &fnum) == OK) { + if (list2fpos(&argvars[1], &pos, &fnum, &curswant) == OK) { if (--pos.col < 0) pos.col = 0; if (name[0] == '.' && name[1] == NUL) { /* set cursor */ if (fnum == curbuf->b_fnum) { curwin->w_cursor = pos; + if (curswant >= 0) { + curwin->w_curswant = curswant - 1; + } check_cursor(); rettv->vval.v_number = 0; } else @@ -15177,18 +15189,18 @@ var2fpos ( * Return FAIL when conversion is not possible, doesn't check the position for * validity. */ -static int list2fpos(typval_T *arg, pos_T *posp, int *fnump) +static int list2fpos(typval_T *arg, pos_T *posp, int *fnump, colnr_T *curswantp) { list_T *l = arg->vval.v_list; long i = 0; long n; - /* List must be: [fnum, lnum, col, coladd], where "fnum" is only there - * when "fnump" isn't NULL and "coladd" is optional. */ + /* List must be: [fnum, lnum, col, coladd, curswant], where "fnum" is only + * there when "fnump" isn't NULL; "coladd" and "curswant" are optional. */ if (arg->v_type != VAR_LIST || l == NULL || l->lv_len < (fnump == NULL ? 2 : 3) - || l->lv_len > (fnump == NULL ? 3 : 4)) + || l->lv_len > (fnump == NULL ? 4 : 5)) return FAIL; if (fnump != NULL) { @@ -15210,12 +15222,16 @@ static int list2fpos(typval_T *arg, pos_T *posp, int *fnump) return FAIL; posp->col = n; - n = list_find_nr(l, i, NULL); + n = list_find_nr(l, i, NULL); // off if (n < 0) posp->coladd = 0; else posp->coladd = n; + if (curswantp != NULL) { + *curswantp = list_find_nr(l, i + 1, NULL); // curswant + } + return OK; } diff --git a/src/nvim/testdir/test_eval.in b/src/nvim/testdir/test_eval.in index c34f5cb50e..3e5ca8e872 100644 --- a/src/nvim/testdir/test_eval.in +++ b/src/nvim/testdir/test_eval.in @@ -1,7 +1,7 @@ STARTTEST - -:e test.out -:%d +:so small.vim +:set encoding=latin1 +:set noswapfile :" function name not starting with a capital :try @@ -49,9 +49,18 @@ STARTTEST : $put =v:exception :endtry -:1d -:w -:qa! +:$put ='{{{1 setpos/getpos' +/^012345678 +6l:let sp = getpos('.') +0:call setpos('.', sp) +jyl:$put +:/^start:/+1,$wq! test.out +:" vim: et ts=4 isk-=\: fmr=???,??? +:call getchar() ENDTEST +012345678 +012345678 + +start: diff --git a/src/nvim/testdir/test_eval.ok b/src/nvim/testdir/test_eval.ok index 162e1b12fd..7e847c1a57 100644 --- a/src/nvim/testdir/test_eval.ok +++ b/src/nvim/testdir/test_eval.ok @@ -9,3 +9,5 @@ func s:Testje exists: 1 Bar exists: 1 func Bar exists: 1 Vim(call):E116: Invalid arguments for function append +{{{1 setpos/getpos +6 diff --git a/src/nvim/version.c b/src/nvim/version.c index bf0dace6ef..7e4729aaaf 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -285,7 +285,7 @@ static int included_patches[] = { //313, 312, //311, - //310, + 310, 309, 308, //307 NA From e32d338c87957e7fddcaa1c3393268663a171617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dami=C3=A1n=20Silvani?= Date: Sun, 3 Aug 2014 10:39:56 -0300 Subject: [PATCH 2/2] vim-patch:7.4.313 Problem: Changing the return value of getpos() causes an error. (Jie Zhu) Solution: Revert getpos() and add getcurpos(). https://code.google.com/p/vim/source/detail?r=332a5c2b2956d9b18d85268a724d01deea27ec83 --- src/nvim/eval.c | 30 ++++++++++++++++++++++++------ src/nvim/testdir/test_eval.in | 4 ++-- src/nvim/testdir/test_eval.ok | 2 +- src/nvim/version.c | 2 +- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 991c43b842..e750da01f0 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6387,6 +6387,7 @@ static struct fst { {"getcmdline", 0, 0, f_getcmdline}, {"getcmdpos", 0, 0, f_getcmdpos}, {"getcmdtype", 0, 0, f_getcmdtype}, + {"getcurpos", 0, 0, f_getcurpos}, {"getcwd", 0, 0, f_getcwd}, {"getfontname", 0, 1, f_getfontname}, {"getfperm", 1, 1, f_getfperm}, @@ -9378,10 +9379,7 @@ static void f_getpid(typval_T *argvars, typval_T *rettv) rettv->vval.v_number = os_get_pid(); } -/* - * "getpos(string)" function - */ -static void f_getpos(typval_T *argvars, typval_T *rettv) +static void getpos_both(typval_T *argvars, typval_T *rettv, bool getcurpos) { pos_T *fp; list_T *l; @@ -9389,7 +9387,11 @@ static void f_getpos(typval_T *argvars, typval_T *rettv) rettv_list_alloc(rettv); l = rettv->vval.v_list; - fp = var2fpos(&argvars[0], TRUE, &fnum); + if (getcurpos) { + fp = &curwin->w_cursor; + } else { + fp = var2fpos(&argvars[0], true, &fnum); + } list_append_number(l, (fnum != -1) ? (varnumber_T)fnum : (varnumber_T)0); list_append_number(l, (fp != NULL) ? (varnumber_T)fp->lnum : (varnumber_T)0); list_append_number(l, @@ -9398,11 +9400,27 @@ static void f_getpos(typval_T *argvars, typval_T *rettv) : (varnumber_T)0); list_append_number(l, (fp != NULL) ? (varnumber_T)fp->coladd : (varnumber_T)0); - if (fp == &curwin->w_cursor) { + if (getcurpos) { list_append_number(l, (varnumber_T) curwin->w_curswant + 1); } } +/* + * "getcurpos(string)" function + */ +static void f_getcurpos(typval_T *argvars, typval_T *rettv) +{ + getpos_both(argvars, rettv, true); +} + +/* + * "getpos(string)" function + */ +static void f_getpos(typval_T *argvars, typval_T *rettv) +{ + getpos_both(argvars, rettv, false); +} + /* * "getqflist()" and "getloclist()" functions */ diff --git a/src/nvim/testdir/test_eval.in b/src/nvim/testdir/test_eval.in index 3e5ca8e872..a29fefc3b6 100644 --- a/src/nvim/testdir/test_eval.in +++ b/src/nvim/testdir/test_eval.in @@ -49,9 +49,9 @@ STARTTEST : $put =v:exception :endtry -:$put ='{{{1 setpos/getpos' +:$put ='{{{1 getcurpos/setpos' /^012345678 -6l:let sp = getpos('.') +6l:let sp = getcurpos() 0:call setpos('.', sp) jyl:$put diff --git a/src/nvim/testdir/test_eval.ok b/src/nvim/testdir/test_eval.ok index 7e847c1a57..63b9156442 100644 --- a/src/nvim/testdir/test_eval.ok +++ b/src/nvim/testdir/test_eval.ok @@ -9,5 +9,5 @@ func s:Testje exists: 1 Bar exists: 1 func Bar exists: 1 Vim(call):E116: Invalid arguments for function append -{{{1 setpos/getpos +{{{1 getcurpos/setpos 6 diff --git a/src/nvim/version.c b/src/nvim/version.c index 7e4729aaaf..1d0366f083 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -282,7 +282,7 @@ static int included_patches[] = { //316 NA 315, 314, - //313, + 313, 312, //311, 310,