lkundrak / rpms / vim

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