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