073263
To: vim_dev@googlegroups.com
073263
Subject: Patch 7.4.310
073263
Fcc: outbox
073263
From: Bram Moolenaar <Bram@moolenaar.net>
073263
Mime-Version: 1.0
073263
Content-Type: text/plain; charset=UTF-8
073263
Content-Transfer-Encoding: 8bit
073263
------------
073263
073263
Patch 7.4.310
073263
Problem:    getpos()/setpos() don't include curswant.
073263
Solution:   Add a fifth number when getting/setting the cursor.
073263
Files:	    src/eval.c, src/testdir/test_eval.in, src/testdir/test_eval.ok,
073263
	    runtime/doc/eval.txt
073263
073263
073263
*** ../vim-7.4.309/src/eval.c	2014-05-22 18:59:54.506169240 +0200
073263
--- src/eval.c	2014-05-28 14:23:37.608099523 +0200
073263
***************
073263
*** 764,770 ****
073263
  static void f_writefile __ARGS((typval_T *argvars, typval_T *rettv));
073263
  static void f_xor __ARGS((typval_T *argvars, typval_T *rettv));
073263
  
073263
! static int list2fpos __ARGS((typval_T *arg, pos_T *posp, int *fnump));
073263
  static pos_T *var2fpos __ARGS((typval_T *varp, int dollar_lnum, int *fnum));
073263
  static int get_env_len __ARGS((char_u **arg));
073263
  static int get_id_len __ARGS((char_u **arg));
073263
--- 764,770 ----
073263
  static void f_writefile __ARGS((typval_T *argvars, typval_T *rettv));
073263
  static void f_xor __ARGS((typval_T *argvars, typval_T *rettv));
073263
  
073263
! static int list2fpos __ARGS((typval_T *arg, pos_T *posp, int *fnump, colnr_T *curswantp));
073263
  static pos_T *var2fpos __ARGS((typval_T *varp, int dollar_lnum, int *fnum));
073263
  static int get_env_len __ARGS((char_u **arg));
073263
  static int get_id_len __ARGS((char_u **arg));
073263
***************
073263
*** 9799,9812 ****
073263
      if (argvars[1].v_type == VAR_UNKNOWN)
073263
      {
073263
  	pos_T	    pos;
073263
  
073263
! 	if (list2fpos(argvars, &pos, NULL) == FAIL)
073263
  	    return;
073263
  	line = pos.lnum;
073263
  	col = pos.col;
073263
  #ifdef FEAT_VIRTUALEDIT
073263
  	coladd = pos.coladd;
073263
  #endif
073263
      }
073263
      else
073263
      {
073263
--- 9799,9815 ----
073263
      if (argvars[1].v_type == VAR_UNKNOWN)
073263
      {
073263
  	pos_T	    pos;
073263
+ 	colnr_T	    curswant = -1;
073263
  
073263
! 	if (list2fpos(argvars, &pos, NULL, &curswant) == FAIL)
073263
  	    return;
073263
  	line = pos.lnum;
073263
  	col = pos.col;
073263
  #ifdef FEAT_VIRTUALEDIT
073263
  	coladd = pos.coladd;
073263
  #endif
073263
+ 	if (curswant >= 0)
073263
+ 	    curwin->w_curswant = curswant - 1;
073263
      }
073263
      else
073263
      {
073263
***************
073263
*** 11770,11775 ****
073263
--- 11773,11780 ----
073263
  				(fp != NULL) ? (varnumber_T)fp->coladd :
073263
  #endif
073263
  							      (varnumber_T)0);
073263
+ 	if (fp == &curwin->w_cursor)
073263
+ 	    list_append_number(l, (varnumber_T)curwin->w_curswant + 1);
073263
      }
073263
      else
073263
  	rettv->vval.v_number = FALSE;
073263
***************
073263
*** 16751,16762 ****
073263
      pos_T	pos;
073263
      int		fnum;
073263
      char_u	*name;
073263
  
073263
      rettv->vval.v_number = -1;
073263
      name = get_tv_string_chk(argvars);
073263
      if (name != NULL)
073263
      {
073263
! 	if (list2fpos(&argvars[1], &pos, &fnum) == OK)
073263
  	{
073263
  	    if (--pos.col < 0)
073263
  		pos.col = 0;
073263
--- 16756,16768 ----
073263
      pos_T	pos;
073263
      int		fnum;
073263
      char_u	*name;
073263
+     colnr_T	curswant = -1;
073263
  
073263
      rettv->vval.v_number = -1;
073263
      name = get_tv_string_chk(argvars);
073263
      if (name != NULL)
073263
      {
073263
! 	if (list2fpos(&argvars[1], &pos, &fnum, &curswant) == OK)
073263
  	{
073263
  	    if (--pos.col < 0)
073263
  		pos.col = 0;
073263
***************
073263
*** 16766,16771 ****
073263
--- 16772,16779 ----
073263
  		if (fnum == curbuf->b_fnum)
073263
  		{
073263
  		    curwin->w_cursor = pos;
073263
+ 		    if (curswant >= 0)
073263
+ 			curwin->w_curswant = curswant - 1;
073263
  		    check_cursor();
073263
  		    rettv->vval.v_number = 0;
073263
  		}
073263
***************
073263
*** 19532,19552 ****
073263
   * validity.
073263
   */
073263
      static int
073263
! list2fpos(arg, posp, fnump)
073263
      typval_T	*arg;
073263
      pos_T	*posp;
073263
      int		*fnump;
073263
  {
073263
      list_T	*l = arg->vval.v_list;
073263
      long	i = 0;
073263
      long	n;
073263
  
073263
!     /* List must be: [fnum, lnum, col, coladd], where "fnum" is only there
073263
!      * when "fnump" isn't NULL and "coladd" is optional. */
073263
      if (arg->v_type != VAR_LIST
073263
  	    || l == NULL
073263
  	    || l->lv_len < (fnump == NULL ? 2 : 3)
073263
! 	    || l->lv_len > (fnump == NULL ? 3 : 4))
073263
  	return FAIL;
073263
  
073263
      if (fnump != NULL)
073263
--- 19540,19561 ----
073263
   * validity.
073263
   */
073263
      static int
073263
! list2fpos(arg, posp, fnump, curswantp)
073263
      typval_T	*arg;
073263
      pos_T	*posp;
073263
      int		*fnump;
073263
+     colnr_T	*curswantp;
073263
  {
073263
      list_T	*l = arg->vval.v_list;
073263
      long	i = 0;
073263
      long	n;
073263
  
073263
!     /* List must be: [fnum, lnum, col, coladd, curswant], where "fnum" is only
073263
!      * there when "fnump" isn't NULL; "coladd" and "curswant" are optional. */
073263
      if (arg->v_type != VAR_LIST
073263
  	    || l == NULL
073263
  	    || l->lv_len < (fnump == NULL ? 2 : 3)
073263
! 	    || l->lv_len > (fnump == NULL ? 4 : 5))
073263
  	return FAIL;
073263
  
073263
      if (fnump != NULL)
073263
***************
073263
*** 19570,19582 ****
073263
      posp->col = n;
073263
  
073263
  #ifdef FEAT_VIRTUALEDIT
073263
!     n = list_find_nr(l, i, NULL);
073263
      if (n < 0)
073263
  	posp->coladd = 0;
073263
      else
073263
  	posp->coladd = n;
073263
  #endif
073263
  
073263
      return OK;
073263
  }
073263
  
073263
--- 19579,19594 ----
073263
      posp->col = n;
073263
  
073263
  #ifdef FEAT_VIRTUALEDIT
073263
!     n = list_find_nr(l, i, NULL);	/* off */
073263
      if (n < 0)
073263
  	posp->coladd = 0;
073263
      else
073263
  	posp->coladd = n;
073263
  #endif
073263
  
073263
+     if (curswantp != NULL)
073263
+ 	*curswantp = list_find_nr(l, i + 1, NULL);  /* curswant */
073263
+ 
073263
      return OK;
073263
  }
073263
  
073263
*** ../vim-7.4.309/src/testdir/test_eval.in	2014-04-29 17:41:18.351689927 +0200
073263
--- src/testdir/test_eval.in	2014-05-28 14:22:31.780098947 +0200
073263
***************
073263
*** 190,198 ****
073263
--- 190,207 ----
073263
  :$put =v:exception
073263
  :endtry
073263
  :"
073263
+ :$put ='{{{1 setpos/getpos'
073263
+ /^012345678
073263
+ 6l:let sp = getpos('.')
073263
+ 0:call setpos('.', sp)
073263
+ jyl:$put
073263
+ :"
073263
  :/^start:/+1,$wq! test.out
073263
  :" vim: et ts=4 isk-=\: fmr=???,???
073263
  :call getchar()
073263
  ENDTEST
073263
  
073263
+ 012345678
073263
+ 012345678
073263
+ 
073263
  start:
073263
*** ../vim-7.4.309/src/testdir/test_eval.ok	2014-04-29 17:41:18.351689927 +0200
073263
--- src/testdir/test_eval.ok	2014-05-28 14:19:31.836097372 +0200
073263
***************
073263
*** 346,348 ****
073263
--- 346,350 ----
073263
  Bar exists: 1
073263
  func Bar exists: 1
073263
  Vim(call):E116: Invalid arguments for function append
073263
+ {{{1 setpos/getpos
073263
+ 6
073263
*** ../vim-7.4.309/runtime/doc/eval.txt	2014-05-07 18:35:25.661216052 +0200
073263
--- runtime/doc/eval.txt	2014-05-28 14:04:40.928089573 +0200
073263
***************
073263
*** 2587,2595 ****
073263
  cursor({list})
073263
  		Positions the cursor at the column (byte count) {col} in the
073263
  		line {lnum}.  The first column is one.
073263
  		When there is one argument {list} this is used as a |List|
073263
! 		with two or three items {lnum}, {col} and {off}.  This is like
073263
! 		the return value of |getpos()|, but without the first item.
073263
  		Does not change the jumplist.
073263
  		If {lnum} is greater than the number of lines in the buffer,
073263
  		the cursor will be positioned at the last line in the buffer.
073263
--- 2587,2600 ----
073263
  cursor({list})
073263
  		Positions the cursor at the column (byte count) {col} in the
073263
  		line {lnum}.  The first column is one.
073263
+ 
073263
  		When there is one argument {list} this is used as a |List|
073263
! 		with two, three or four item:
073263
! 			[{lnum}, {col}, {off}]
073263
! 			[{lnum}, {col}, {off}, {curswant}]
073263
! 		This is like the return value of |getpos()|, but without the
073263
! 		first item.
073263
! 
073263
  		Does not change the jumplist.
073263
  		If {lnum} is greater than the number of lines in the buffer,
073263
  		the cursor will be positioned at the last line in the buffer.
073263
***************
073263
*** 4475,4482 ****
073263
  							*getpos()*
073263
  getpos({expr})	Get the position for {expr}.  For possible values of {expr}
073263
  		see |line()|.
073263
! 		The result is a |List| with four numbers:
073263
  		    [bufnum, lnum, col, off]
073263
  		"bufnum" is zero, unless a mark like '0 or 'A is used, then it
073263
  		is the buffer number of the mark.
073263
  		"lnum" and "col" are the position in the buffer.  The first
073263
--- 4490,4498 ----
073263
  							*getpos()*
073263
  getpos({expr})	Get the position for {expr}.  For possible values of {expr}
073263
  		see |line()|.
073263
! 		The result is a |List| with four or five numbers:
073263
  		    [bufnum, lnum, col, off]
073263
+ 		    [bufnum, lnum, col, off, curswant]
073263
  		"bufnum" is zero, unless a mark like '0 or 'A is used, then it
073263
  		is the buffer number of the mark.
073263
  		"lnum" and "col" are the position in the buffer.  The first
073263
***************
073263
*** 4485,4490 ****
073263
--- 4501,4511 ----
073263
  		it is the offset in screen columns from the start of the
073263
  		character.  E.g., a position within a <Tab> or after the last
073263
  		character.
073263
+ 		The "curswant" number is only added for getpos('.'), it is the
073263
+ 		preferred column when moving the cursor vertically.
073263
+ 		Note that for '< and '> Visual mode matters: when it is "V"
073263
+ 		(visual line mode) the column of '< is zero and the column of
073263
+ 		'> is a large number.
073263
  		This can be used to save and restore the cursor position: >
073263
  			let save_cursor = getpos(".")
073263
  			MoveTheCursorAround
073263
***************
073263
*** 5289,5296 ****
073263
  			.	the cursor
073263
  			'x	mark x
073263
  
073263
! 		{list} must be a |List| with four numbers:
073263
  		    [bufnum, lnum, col, off]
073263
  
073263
  		"bufnum" is the buffer number.	Zero can be used for the
073263
  		current buffer.  Setting the cursor is only possible for
073263
--- 5310,5318 ----
073263
  			.	the cursor
073263
  			'x	mark x
073263
  
073263
! 		{list} must be a |List| with four or five numbers:
073263
  		    [bufnum, lnum, col, off]
073263
+ 		    [bufnum, lnum, col, off, curswant]
073263
  
073263
  		"bufnum" is the buffer number.	Zero can be used for the
073263
  		current buffer.  Setting the cursor is only possible for
073263
***************
073263
*** 5308,5320 ****
073263
  		character.  E.g., a position within a <Tab> or after the last
073263
  		character.
073263
  
073263
  		Returns 0 when the position could be set, -1 otherwise.
073263
  		An error message is given if {expr} is invalid.
073263
  
073263
  		Also see |getpos()|
073263
  
073263
  		This does not restore the preferred column for moving
073263
! 		vertically.  See |winrestview()| for that.
073263
  
073263
  
073263
  setqflist({list} [, {action}])				*setqflist()*
073263
--- 5330,5355 ----
073263
  		character.  E.g., a position within a <Tab> or after the last
073263
  		character.
073263
  
073263
+ 		The "curswant" number is only used when setting the cursor
073263
+ 		position.  It sets the preferred column for when moving the
073263
+ 		cursor vertically.  When the "curswant" number is missing the
073263
+ 		preferred column is not set.  When it is present and setting a
073263
+ 		mark position it is not used.
073263
+ 
073263
+ 		Note that for '< and '> changing the line number may result in
073263
+ 		the marks to be effectively be swapped, so that '< is always
073263
+ 		before '>.
073263
+ 
073263
  		Returns 0 when the position could be set, -1 otherwise.
073263
  		An error message is given if {expr} is invalid.
073263
  
073263
  		Also see |getpos()|
073263
  
073263
  		This does not restore the preferred column for moving
073263
! 		vertically; if you set the cursor position with this, |j| and
073263
! 		|k| motions will jump to previous columns!  Use |cursor()| to
073263
! 		also set the preferred column.  Also see the "curswant" key in
073263
! 		|winrestview()|.
073263
  
073263
  
073263
  setqflist({list} [, {action}])				*setqflist()*
073263
*** ../vim-7.4.309/src/version.c	2014-05-28 13:42:59.884078184 +0200
073263
--- src/version.c	2014-05-28 14:27:20.132101471 +0200
073263
***************
073263
*** 736,737 ****
073263
--- 736,739 ----
073263
  {   /* Add new patch number below this line */
073263
+ /**/
073263
+     310,
073263
  /**/
073263
073263
-- 
073263
hundred-and-one symptoms of being an internet addict:
073263
218. Your spouse hands you a gift wrapped magnet with your PC's name
073263
     on it and you accuse him or her of genocide.
073263
073263
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
073263
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
073263
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
073263
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///