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