On Mo, 19 Aug 2013, Christian Brabandt wrote: > May be another optional parameter to the setpos() function, that > if given specifies the desired cursor position?
Like the attached patch does. regards, Christian -- Es gehört viel dazu, eine Brücke hinter sich abzureißen, wenn man auch keine vor sich hat. -- Karlheinz Deschner -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -4409,8 +4409,8 @@ *getpos()* getpos({expr}) Get the position for {expr}. For possible values of {expr} see |line()|. - The result is a |List| with four numbers: - [bufnum, lnum, col, off] + The result is a |List| with five numbers: + [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 @@ -4419,6 +4419,9 @@ 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 the prefered column for moving + vertically. + This can be used to save and restore the cursor position: > let save_cursor = getpos(".") MoveTheCursorAround @@ -5224,7 +5227,7 @@ 'x mark x {list} must be a |List| with four numbers: - [bufnum, lnum, col, off] + [bufnum, lnum, col, off[, curswant]] "bufnum" is the buffer number. Zero can be used for the current buffer. Setting the cursor is only possible for @@ -5242,14 +5245,15 @@ character. E.g., a position within a <Tab> or after the last character. + The optional argument "curswant" is the preferred column for + moving vertically (matters only when setting the cursor + position). + Returns 0 when the position could be set, -1 otherwise. An error message is given if {expr} is invalid. Also see |getpos()| - This does not restore the preferred column for moving - vertically. See |winrestview()| for that. - setqflist({list} [, {action}]) *setqflist()* Create or replace or add to the quickfix list using the items diff --git a/src/eval.c b/src/eval.c --- a/src/eval.c +++ b/src/eval.c @@ -11690,6 +11690,7 @@ (fp != NULL) ? (varnumber_T)fp->coladd : #endif (varnumber_T)0); + list_append_number(l, (varnumber_T)curwin->w_curswant + 1); } else rettv->vval.v_number = FALSE; @@ -16583,6 +16584,7 @@ pos_T pos; int fnum; char_u *name; + colnr_T curswant = curwin->w_curswant; rettv->vval.v_number = -1; name = get_tv_string_chk(argvars); @@ -16604,14 +16606,18 @@ else EMSG(_(e_invarg)); } - else if (name[0] == '\'' && name[1] != NUL && name[2] == NUL) - { - /* set mark */ - if (setmark_pos(name[1], &pos, fnum) == OK) - rettv->vval.v_number = 0; - } - else - EMSG(_(e_invarg)); + else + { + curwin->w_curswant = curswant; /* might have been reset by list2fpos */ + if (name[0] == '\'' && name[1] != NUL && name[2] == NUL) + { + /* set mark */ + if (setmark_pos(name[1], &pos, fnum) == OK) + rettv->vval.v_number = 0; + } + else + EMSG(_(e_invarg)); + } } } } @@ -19149,7 +19155,7 @@ 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) @@ -19180,6 +19186,13 @@ posp->coladd = n; #endif + n = list_find_nr(l, ++i, NULL); /* w_set_curswant */ + if (n > 0) + { + curwin->w_curswant = n-1; + curwin->w_set_curswant = FALSE; + } + return OK; }