Mercurial > vim
changeset 5944:332a5c2b2956 v7.4.313
updated for version 7.4.313
Problem: Changing the return value of getpos() causes an error. (Jie Zhu)
Solution: Revert getpos() and add getcurpos().
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Wed, 28 May 2014 20:31:42 +0200 |
parents | 67f652389aff |
children | 5976b378f610 |
files | runtime/doc/eval.txt src/eval.c src/testdir/test_eval.in src/testdir/test_eval.ok src/version.c |
diffstat | 5 files changed, 59 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1808,10 +1808,11 @@ getcharmod( ) Number modifiers for the getcmdline() String return the current command-line getcmdpos() Number return cursor position in command-line getcmdtype() String return the current command-line type +getcurpos() List position of the cursor getcwd() String the current working directory +getfontname( [{name}]) String name of font being used getfperm( {fname}) String file permissions of file {fname} getfsize( {fname}) Number size in bytes of file {fname} -getfontname( [{name}]) String name of font being used getftime( {fname}) Number last modification time of file getftype( {fname}) String description of type of file {fname} getline( {lnum}) String line {lnum} of current buffer @@ -2606,8 +2607,8 @@ cursor({list}) with two, three or four item: [{lnum}, {col}, {off}] [{lnum}, {col}, {off}, {curswant}] - This is like the return value of |getpos()|, but without the - first item. + This is like the return value of |getpos()| or |getcurpos|, + but without the first item. Does not change the jumplist. If {lnum} is greater than the number of lines in the buffer, @@ -2617,6 +2618,8 @@ cursor({list}) the cursor will be positioned at the last character in the line. If {col} is zero, the cursor will stay in the current column. + If {curswant} is given it is used to set the preferred column + for vertical movment. Otherwise {col} is used. When 'virtualedit' is used {off} specifies the offset in screen columns from the start of the character. E.g., a position within a <Tab> or after the last character. @@ -3340,6 +3343,17 @@ getcmdtype() *getcmdtype()* Returns an empty string otherwise. Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|. + *getcurpos()* +getcurpos() Get the position of the cursor. This is like getpos('.'), but + includes an extra item in the list: + [bufnum, lnum, col, off, curswant] + The "curswant" number is the preferred column when moving the + cursor vertically. + This can be used to save and restore the cursor position: > + let save_cursor = getcurpos() + MoveTheCursorAround + call setpos('.', save_cursor) + *getcwd()* getcwd() The result is a String, which is the name of the current working directory. @@ -4499,10 +4513,10 @@ getpid() Return a Number which is the pr *getpos()* getpos({expr}) Get the position for {expr}. For possible values of {expr} - see |line()|. - The result is a |List| with four or five numbers: + see |line()|. For getting the cursor position see + |getcurpos()|. + The result is a |List| with four numbers: [bufnum, lnum, col, off] - [bufnum, lnum, col, off, curswant] "bufnum" is zero, unless a mark like '0 or 'A is used, then it is the buffer number of the mark. "lnum" and "col" are the position in the buffer. The first @@ -4511,16 +4525,14 @@ getpos({expr}) Get the position for {exp 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. - 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" (visual line mode) the column of '< is zero and the column of '> is a large number. - This can be used to save and restore the cursor position: > - let save_cursor = getpos(".") - MoveTheCursorAround - call setpos('.', save_cursor) -< Also see |setpos()|. + This can be used to save and restore the position of a mark: > + let save_a_mark = getpos("'a") + ... + call setpos(''a', save_a_mark +< Also see |getcurpos()| and |setpos()|. or({expr}, {expr}) *or()* Bitwise OR on the two arguments. The arguments are converted @@ -5353,7 +5365,7 @@ setpos({expr}, {list}) Returns 0 when the position could be set, -1 otherwise. An error message is given if {expr} is invalid. - Also see |getpos()| + Also see |getpos()| and |getcurpos()|. This does not restore the preferred column for moving vertically; if you set the cursor position with this, |j| and
--- a/src/eval.c +++ b/src/eval.c @@ -560,6 +560,7 @@ static void f_getftype __ARGS((typval_T static void f_getline __ARGS((typval_T *argvars, typval_T *rettv)); static void f_getmatches __ARGS((typval_T *argvars, typval_T *rettv)); static void f_getpid __ARGS((typval_T *argvars, typval_T *rettv)); +static void f_getcurpos __ARGS((typval_T *argvars, typval_T *rettv)); static void f_getpos __ARGS((typval_T *argvars, typval_T *rettv)); static void f_getqflist __ARGS((typval_T *argvars, typval_T *rettv)); static void f_getreg __ARGS((typval_T *argvars, typval_T *rettv)); @@ -7967,6 +7968,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}, @@ -11780,6 +11782,19 @@ f_getpid(argvars, rettv) rettv->vval.v_number = mch_get_pid(); } +static void getpos_both __ARGS((typval_T *argvars, typval_T *rettv, int getcurpos)); + +/* + * "getcurpos()" function + */ + static void +f_getcurpos(argvars, rettv) + typval_T *argvars; + typval_T *rettv; +{ + getpos_both(argvars, rettv, TRUE); +} + /* * "getpos(string)" function */ @@ -11788,6 +11803,15 @@ f_getpos(argvars, rettv) typval_T *argvars; typval_T *rettv; { + getpos_both(argvars, rettv, FALSE); +} + + static void +getpos_both(argvars, rettv, getcurpos) + typval_T *argvars; + typval_T *rettv; + int getcurpos; +{ pos_T *fp; list_T *l; int fnum = -1; @@ -11795,7 +11819,10 @@ f_getpos(argvars, rettv) if (rettv_list_alloc(rettv) == OK) { l = rettv->vval.v_list; - fp = var2fpos(&argvars[0], TRUE, &fnum); + if (getcurpos) + fp = &curwin->w_cursor; + else + fp = var2fpos(&argvars[0], TRUE, &fnum); if (fnum != -1) list_append_number(l, (varnumber_T)fnum); else @@ -11810,7 +11837,7 @@ f_getpos(argvars, rettv) (fp != NULL) ? (varnumber_T)fp->coladd : #endif (varnumber_T)0); - if (fp == &curwin->w_cursor) + if (getcurpos) list_append_number(l, (varnumber_T)curwin->w_curswant + 1); } else
--- a/src/testdir/test_eval.in +++ b/src/testdir/test_eval.in @@ -190,9 +190,9 @@ endfun :$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 :"
index 7bbce810f8273c4457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