3ef2ca
To: vim_dev@googlegroups.com
3ef2ca
Subject: Patch 7.4.313
3ef2ca
Fcc: outbox
3ef2ca
From: Bram Moolenaar <Bram@moolenaar.net>
3ef2ca
Mime-Version: 1.0
3ef2ca
Content-Type: text/plain; charset=UTF-8
3ef2ca
Content-Transfer-Encoding: 8bit
3ef2ca
------------
3ef2ca
3ef2ca
Patch 7.4.313 (after 7.4.310)
3ef2ca
Problem:    Changing the return value of getpos() causes an error. (Jie Zhu)
3ef2ca
Solution:   Revert getpos() and add getcurpos().
3ef2ca
Files:	    src/eval.c, src/testdir/test_eval.in, src/testdir/test_eval.ok,
3ef2ca
	    runtime/doc/eval.txt
3ef2ca
3ef2ca
3ef2ca
*** ../vim-7.4.312/src/eval.c	2014-05-28 18:22:37.876225054 +0200
3ef2ca
--- src/eval.c	2014-05-28 20:11:55.364282457 +0200
3ef2ca
***************
3ef2ca
*** 560,565 ****
3ef2ca
--- 560,566 ----
3ef2ca
  static void f_getline __ARGS((typval_T *argvars, typval_T *rettv));
3ef2ca
  static void f_getmatches __ARGS((typval_T *argvars, typval_T *rettv));
3ef2ca
  static void f_getpid __ARGS((typval_T *argvars, typval_T *rettv));
3ef2ca
+ static void f_getcurpos __ARGS((typval_T *argvars, typval_T *rettv));
3ef2ca
  static void f_getpos __ARGS((typval_T *argvars, typval_T *rettv));
3ef2ca
  static void f_getqflist __ARGS((typval_T *argvars, typval_T *rettv));
3ef2ca
  static void f_getreg __ARGS((typval_T *argvars, typval_T *rettv));
3ef2ca
***************
3ef2ca
*** 7967,7972 ****
3ef2ca
--- 7968,7974 ----
3ef2ca
      {"getcmdline",	0, 0, f_getcmdline},
3ef2ca
      {"getcmdpos",	0, 0, f_getcmdpos},
3ef2ca
      {"getcmdtype",	0, 0, f_getcmdtype},
3ef2ca
+     {"getcurpos",	0, 0, f_getcurpos},
3ef2ca
      {"getcwd",		0, 0, f_getcwd},
3ef2ca
      {"getfontname",	0, 1, f_getfontname},
3ef2ca
      {"getfperm",	1, 1, f_getfperm},
3ef2ca
***************
3ef2ca
*** 11780,11785 ****
3ef2ca
--- 11782,11800 ----
3ef2ca
      rettv->vval.v_number = mch_get_pid();
3ef2ca
  }
3ef2ca
  
3ef2ca
+ static void getpos_both __ARGS((typval_T *argvars, typval_T *rettv, int getcurpos));
3ef2ca
+ 
3ef2ca
+ /*
3ef2ca
+  * "getcurpos()" function
3ef2ca
+  */
3ef2ca
+     static void
3ef2ca
+ f_getcurpos(argvars, rettv)
3ef2ca
+     typval_T	*argvars;
3ef2ca
+     typval_T	*rettv;
3ef2ca
+ {
3ef2ca
+     getpos_both(argvars, rettv, TRUE);
3ef2ca
+ }
3ef2ca
+ 
3ef2ca
  /*
3ef2ca
   * "getpos(string)" function
3ef2ca
   */
3ef2ca
***************
3ef2ca
*** 11788,11793 ****
3ef2ca
--- 11803,11817 ----
3ef2ca
      typval_T	*argvars;
3ef2ca
      typval_T	*rettv;
3ef2ca
  {
3ef2ca
+     getpos_both(argvars, rettv, FALSE);
3ef2ca
+ }
3ef2ca
+ 
3ef2ca
+     static void
3ef2ca
+ getpos_both(argvars, rettv, getcurpos)
3ef2ca
+     typval_T	*argvars;
3ef2ca
+     typval_T	*rettv;
3ef2ca
+     int		getcurpos;
3ef2ca
+ {
3ef2ca
      pos_T	*fp;
3ef2ca
      list_T	*l;
3ef2ca
      int		fnum = -1;
3ef2ca
***************
3ef2ca
*** 11795,11801 ****
3ef2ca
      if (rettv_list_alloc(rettv) == OK)
3ef2ca
      {
3ef2ca
  	l = rettv->vval.v_list;
3ef2ca
! 	fp = var2fpos(&argvars[0], TRUE, &fnum);
3ef2ca
  	if (fnum != -1)
3ef2ca
  	    list_append_number(l, (varnumber_T)fnum);
3ef2ca
  	else
3ef2ca
--- 11819,11828 ----
3ef2ca
      if (rettv_list_alloc(rettv) == OK)
3ef2ca
      {
3ef2ca
  	l = rettv->vval.v_list;
3ef2ca
! 	if (getcurpos)
3ef2ca
! 	    fp = &curwin->w_cursor;
3ef2ca
! 	else
3ef2ca
! 	    fp = var2fpos(&argvars[0], TRUE, &fnum);
3ef2ca
  	if (fnum != -1)
3ef2ca
  	    list_append_number(l, (varnumber_T)fnum);
3ef2ca
  	else
3ef2ca
***************
3ef2ca
*** 11810,11816 ****
3ef2ca
  				(fp != NULL) ? (varnumber_T)fp->coladd :
3ef2ca
  #endif
3ef2ca
  							      (varnumber_T)0);
3ef2ca
! 	if (fp == &curwin->w_cursor)
3ef2ca
  	    list_append_number(l, (varnumber_T)curwin->w_curswant + 1);
3ef2ca
      }
3ef2ca
      else
3ef2ca
--- 11837,11843 ----
3ef2ca
  				(fp != NULL) ? (varnumber_T)fp->coladd :
3ef2ca
  #endif
3ef2ca
  							      (varnumber_T)0);
3ef2ca
! 	if (getcurpos)
3ef2ca
  	    list_append_number(l, (varnumber_T)curwin->w_curswant + 1);
3ef2ca
      }
3ef2ca
      else
3ef2ca
*** ../vim-7.4.312/src/testdir/test_eval.in	2014-05-28 14:32:47.160104334 +0200
3ef2ca
--- src/testdir/test_eval.in	2014-05-28 20:14:27.048283785 +0200
3ef2ca
***************
3ef2ca
*** 190,198 ****
3ef2ca
  :$put =v:exception
3ef2ca
  :endtry
3ef2ca
  :"
3ef2ca
! :$put ='{{{1 setpos/getpos'
3ef2ca
  /^012345678
3ef2ca
! 6l:let sp = getpos('.')
3ef2ca
  0:call setpos('.', sp)
3ef2ca
  jyl:$put
3ef2ca
  :"
3ef2ca
--- 190,198 ----
3ef2ca
  :$put =v:exception
3ef2ca
  :endtry
3ef2ca
  :"
3ef2ca
! :$put ='{{{1 getcurpos/setpos'
3ef2ca
  /^012345678
3ef2ca
! 6l:let sp = getcurpos()
3ef2ca
  0:call setpos('.', sp)
3ef2ca
  jyl:$put
3ef2ca
  :"
3ef2ca
*** ../vim-7.4.312/src/testdir/test_eval.ok	2014-05-28 14:32:47.160104334 +0200
3ef2ca
--- src/testdir/test_eval.ok	2014-05-28 20:14:43.316283927 +0200
3ef2ca
***************
3ef2ca
*** 346,350 ****
3ef2ca
  Bar exists: 1
3ef2ca
  func Bar exists: 1
3ef2ca
  Vim(call):E116: Invalid arguments for function append
3ef2ca
! {{{1 setpos/getpos
3ef2ca
  6
3ef2ca
--- 346,350 ----
3ef2ca
  Bar exists: 1
3ef2ca
  func Bar exists: 1
3ef2ca
  Vim(call):E116: Invalid arguments for function append
3ef2ca
! {{{1 getcurpos/setpos
3ef2ca
  6
3ef2ca
*** ../vim-7.4.312/runtime/doc/eval.txt	2014-05-28 18:22:37.872225054 +0200
3ef2ca
--- runtime/doc/eval.txt	2014-05-28 20:27:57.092290876 +0200
3ef2ca
***************
3ef2ca
*** 1808,1817 ****
3ef2ca
  getcmdline()			String	return the current command-line
3ef2ca
  getcmdpos()			Number	return cursor position in command-line
3ef2ca
  getcmdtype()			String	return the current command-line type
3ef2ca
  getcwd()			String	the current working directory
3ef2ca
  getfperm( {fname})		String	file permissions of file {fname}
3ef2ca
  getfsize( {fname})		Number	size in bytes of file {fname}
3ef2ca
- getfontname( [{name}])		String	name of font being used
3ef2ca
  getftime( {fname})		Number	last modification time of file
3ef2ca
  getftype( {fname})		String	description of type of file {fname}
3ef2ca
  getline( {lnum})		String	line {lnum} of current buffer
3ef2ca
--- 1808,1818 ----
3ef2ca
  getcmdline()			String	return the current command-line
3ef2ca
  getcmdpos()			Number	return cursor position in command-line
3ef2ca
  getcmdtype()			String	return the current command-line type
3ef2ca
+ getcurpos()			List	position of the cursor
3ef2ca
  getcwd()			String	the current working directory
3ef2ca
+ getfontname( [{name}])		String	name of font being used
3ef2ca
  getfperm( {fname})		String	file permissions of file {fname}
3ef2ca
  getfsize( {fname})		Number	size in bytes of file {fname}
3ef2ca
  getftime( {fname})		Number	last modification time of file
3ef2ca
  getftype( {fname})		String	description of type of file {fname}
3ef2ca
  getline( {lnum})		String	line {lnum} of current buffer
3ef2ca
***************
3ef2ca
*** 2606,2613 ****
3ef2ca
  		with two, three or four item:
3ef2ca
  			[{lnum}, {col}, {off}]
3ef2ca
  			[{lnum}, {col}, {off}, {curswant}]
3ef2ca
! 		This is like the return value of |getpos()|, but without the
3ef2ca
! 		first item.
3ef2ca
  
3ef2ca
  		Does not change the jumplist.
3ef2ca
  		If {lnum} is greater than the number of lines in the buffer,
3ef2ca
--- 2607,2614 ----
3ef2ca
  		with two, three or four item:
3ef2ca
  			[{lnum}, {col}, {off}]
3ef2ca
  			[{lnum}, {col}, {off}, {curswant}]
3ef2ca
! 		This is like the return value of |getpos()| or |getcurpos|,
3ef2ca
! 		but without the first item.
3ef2ca
  
3ef2ca
  		Does not change the jumplist.
3ef2ca
  		If {lnum} is greater than the number of lines in the buffer,
3ef2ca
***************
3ef2ca
*** 2617,2622 ****
3ef2ca
--- 2618,2625 ----
3ef2ca
  		the cursor will be positioned at the last character in the
3ef2ca
  		line.
3ef2ca
  		If {col} is zero, the cursor will stay in the current column.
3ef2ca
+ 		If {curswant} is given it is used to set the preferred column
3ef2ca
+ 		for vertical movment.  Otherwise {col} is used.
3ef2ca
  		When 'virtualedit' is used {off} specifies the offset in
3ef2ca
  		screen columns from the start of the character.  E.g., a
3ef2ca
  		position within a <Tab> or after the last character.
3ef2ca
***************
3ef2ca
*** 3339,3344 ****
3ef2ca
--- 3347,3363 ----
3ef2ca
  		Returns an empty string otherwise.
3ef2ca
  		Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
3ef2ca
  
3ef2ca
+ 							*getcurpos()*
3ef2ca
+ getcurpos()	Get the position of the cursor.  This is like getpos('.'), but
3ef2ca
+ 		includes an extra item in the list:
3ef2ca
+ 		    [bufnum, lnum, col, off, curswant]
3ef2ca
+ 		The "curswant" number is the preferred column when moving the
3ef2ca
+ 		cursor vertically.
3ef2ca
+ 		This can be used to save and restore the cursor position: >
3ef2ca
+ 			let save_cursor = getcurpos()
3ef2ca
+ 			MoveTheCursorAround
3ef2ca
+ 			call setpos('.', save_cursor)
3ef2ca
+ 
3ef2ca
  							*getcwd()*
3ef2ca
  getcwd()	The result is a String, which is the name of the current
3ef2ca
  		working directory.
3ef2ca
***************
3ef2ca
*** 4493,4502 ****
3ef2ca
  
3ef2ca
  							*getpos()*
3ef2ca
  getpos({expr})	Get the position for {expr}.  For possible values of {expr}
3ef2ca
! 		see |line()|.
3ef2ca
! 		The result is a |List| with four or five numbers:
3ef2ca
  		    [bufnum, lnum, col, off]
3ef2ca
- 		    [bufnum, lnum, col, off, curswant]
3ef2ca
  		"bufnum" is zero, unless a mark like '0 or 'A is used, then it
3ef2ca
  		is the buffer number of the mark.
3ef2ca
  		"lnum" and "col" are the position in the buffer.  The first
3ef2ca
--- 4517,4526 ----
3ef2ca
  
3ef2ca
  							*getpos()*
3ef2ca
  getpos({expr})	Get the position for {expr}.  For possible values of {expr}
3ef2ca
! 		see |line()|.  For getting the cursor position see
3ef2ca
! 		|getcurpos()|.
3ef2ca
! 		The result is a |List| with four numbers:
3ef2ca
  		    [bufnum, lnum, col, off]
3ef2ca
  		"bufnum" is zero, unless a mark like '0 or 'A is used, then it
3ef2ca
  		is the buffer number of the mark.
3ef2ca
  		"lnum" and "col" are the position in the buffer.  The first
3ef2ca
***************
3ef2ca
*** 4505,4520 ****
3ef2ca
  		it is the offset in screen columns from the start of the
3ef2ca
  		character.  E.g., a position within a <Tab> or after the last
3ef2ca
  		character.
3ef2ca
- 		The "curswant" number is only added for getpos('.'), it is the
3ef2ca
- 		preferred column when moving the cursor vertically.
3ef2ca
  		Note that for '< and '> Visual mode matters: when it is "V"
3ef2ca
  		(visual line mode) the column of '< is zero and the column of
3ef2ca
  		'> is a large number.
3ef2ca
! 		This can be used to save and restore the cursor position: >
3ef2ca
! 			let save_cursor = getpos(".")
3ef2ca
! 			MoveTheCursorAround
3ef2ca
! 			call setpos('.', save_cursor)
3ef2ca
! <		Also see |setpos()|.
3ef2ca
  
3ef2ca
  or({expr}, {expr})					*or()*
3ef2ca
  		Bitwise OR on the two arguments.  The arguments are converted
3ef2ca
--- 4529,4542 ----
3ef2ca
  		it is the offset in screen columns from the start of the
3ef2ca
  		character.  E.g., a position within a <Tab> or after the last
3ef2ca
  		character.
3ef2ca
  		Note that for '< and '> Visual mode matters: when it is "V"
3ef2ca
  		(visual line mode) the column of '< is zero and the column of
3ef2ca
  		'> is a large number.
3ef2ca
! 		This can be used to save and restore the position of a mark: >
3ef2ca
! 			let save_a_mark = getpos("'a")
3ef2ca
! 			...
3ef2ca
! 			call setpos(''a', save_a_mark
3ef2ca
! <		Also see |getcurpos()| and |setpos()|.
3ef2ca
  
3ef2ca
  or({expr}, {expr})					*or()*
3ef2ca
  		Bitwise OR on the two arguments.  The arguments are converted
3ef2ca
***************
3ef2ca
*** 5347,5353 ****
3ef2ca
  		Returns 0 when the position could be set, -1 otherwise.
3ef2ca
  		An error message is given if {expr} is invalid.
3ef2ca
  
3ef2ca
! 		Also see |getpos()|
3ef2ca
  
3ef2ca
  		This does not restore the preferred column for moving
3ef2ca
  		vertically; if you set the cursor position with this, |j| and
3ef2ca
--- 5369,5375 ----
3ef2ca
  		Returns 0 when the position could be set, -1 otherwise.
3ef2ca
  		An error message is given if {expr} is invalid.
3ef2ca
  
3ef2ca
! 		Also see |getpos()| and |getcurpos()|.
3ef2ca
  
3ef2ca
  		This does not restore the preferred column for moving
3ef2ca
  		vertically; if you set the cursor position with this, |j| and
3ef2ca
*** ../vim-7.4.312/src/version.c	2014-05-28 18:22:37.880225054 +0200
3ef2ca
--- src/version.c	2014-05-28 20:15:52.164284530 +0200
3ef2ca
***************
3ef2ca
*** 736,737 ****
3ef2ca
--- 736,739 ----
3ef2ca
  {   /* Add new patch number below this line */
3ef2ca
+ /**/
3ef2ca
+     313,
3ef2ca
  /**/
3ef2ca
3ef2ca
-- 
3ef2ca
hundred-and-one symptoms of being an internet addict:
3ef2ca
225. You sign up for free subscriptions for all the computer magazines
3ef2ca
3ef2ca
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
3ef2ca
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
3ef2ca
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
3ef2ca
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///