Blame SOURCES/7.4.242

22c937
To: vim_dev@googlegroups.com
22c937
Subject: Patch 7.4.242
22c937
Fcc: outbox
22c937
From: Bram Moolenaar <Bram@moolenaar.net>
22c937
Mime-Version: 1.0
22c937
Content-Type: text/plain; charset=UTF-8
22c937
Content-Transfer-Encoding: 8bit
22c937
------------
22c937
22c937
Patch 7.4.242
22c937
Problem:    getreg() does not distinguish between a NL used for a line break
22c937
	    and a NL used for a NUL character.
22c937
Solution:   Add another argument to return a list. (ZyX)
22c937
Files:	    runtime/doc/eval.txt, src/eval.c src/ops.c, src/proto/ops.pro,
22c937
	    src/vim.h, src/Makefile, src/testdir/test_eval.in,
22c937
	    src/testdir/test_eval.ok, src/testdir/Make_amiga.mak,
22c937
	    src/testdir/Make_dos.mak, src/testdir/Make_ming.mak,
22c937
	    src/testdir/Make_os2.mak, src/testdir/Make_vms.mms
22c937
22c937
22c937
*** ../vim-7.4.241/runtime/doc/eval.txt	2014-04-02 19:00:53.035644100 +0200
22c937
--- runtime/doc/eval.txt	2014-04-02 19:15:31.847632011 +0200
22c937
***************
22c937
*** 1818,1824 ****
22c937
  getpid()			Number	process ID of Vim
22c937
  getpos( {expr})			List	position of cursor, mark, etc.
22c937
  getqflist()			List	list of quickfix items
22c937
! getreg( [{regname} [, 1]])	String	contents of register
22c937
  getregtype( [{regname}])	String	type of register
22c937
  gettabvar( {nr}, {varname} [, {def}])
22c937
  				any	variable {varname} in tab {nr} or {def}
22c937
--- 1819,1826 ----
22c937
  getpid()			Number	process ID of Vim
22c937
  getpos( {expr})			List	position of cursor, mark, etc.
22c937
  getqflist()			List	list of quickfix items
22c937
! getreg( [{regname} [, 1 [, {list}]]])
22c937
! 				String or List   contents of register
22c937
  getregtype( [{regname}])	String	type of register
22c937
  gettabvar( {nr}, {varname} [, {def}])
22c937
  				any	variable {varname} in tab {nr} or {def}
22c937
***************
22c937
*** 3466,3472 ****
22c937
  			:endfor
22c937
  
22c937
  
22c937
! getreg([{regname} [, 1]])				*getreg()*
22c937
  		The result is a String, which is the contents of register
22c937
  		{regname}.  Example: >
22c937
  			:let cliptext = getreg('*')
22c937
--- 3468,3474 ----
22c937
  			:endfor
22c937
  
22c937
  
22c937
! getreg([{regname} [, 1 [, {list}]]])			*getreg()*
22c937
  		The result is a String, which is the contents of register
22c937
  		{regname}.  Example: >
22c937
  			:let cliptext = getreg('*')
22c937
***************
22c937
*** 3475,3480 ****
22c937
--- 3477,3487 ----
22c937
  		getreg('=', 1) returns the expression itself, so that it can
22c937
  		be restored with |setreg()|.  For other registers the extra
22c937
  		argument is ignored, thus you can always give it.
22c937
+ 		If {list} is present and non-zero result type is changed to 
22c937
+ 		|List|. Each list item is one text line. Use it if you care
22c937
+ 		about zero bytes possibly present inside register: without
22c937
+ 		third argument both NLs and zero bytes are represented as NLs
22c937
+ 		(see |NL-used-for-Nul|).
22c937
  		If {regname} is not specified, |v:register| is used.
22c937
  
22c937
  
22c937
*** ../vim-7.4.241/src/eval.c	2014-04-02 19:00:53.043644100 +0200
22c937
--- src/eval.c	2014-04-02 19:35:54.919615187 +0200
22c937
***************
22c937
*** 2458,2464 ****
22c937
  	    p = get_tv_string_chk(tv);
22c937
  	    if (p != NULL && op != NULL && *op == '.')
22c937
  	    {
22c937
! 		s = get_reg_contents(*arg == '@' ? '"' : *arg, TRUE, TRUE);
22c937
  		if (s != NULL)
22c937
  		{
22c937
  		    p = ptofree = concat_str(s, p);
22c937
--- 2458,2464 ----
22c937
  	    p = get_tv_string_chk(tv);
22c937
  	    if (p != NULL && op != NULL && *op == '.')
22c937
  	    {
22c937
! 		s = get_reg_contents(*arg == '@' ? '"' : *arg, GREG_EXPR_SRC);
22c937
  		if (s != NULL)
22c937
  		{
22c937
  		    p = ptofree = concat_str(s, p);
22c937
***************
22c937
*** 5121,5127 ****
22c937
  		if (evaluate)
22c937
  		{
22c937
  		    rettv->v_type = VAR_STRING;
22c937
! 		    rettv->vval.v_string = get_reg_contents(**arg, TRUE, TRUE);
22c937
  		}
22c937
  		if (**arg != NUL)
22c937
  		    ++*arg;
22c937
--- 5121,5128 ----
22c937
  		if (evaluate)
22c937
  		{
22c937
  		    rettv->v_type = VAR_STRING;
22c937
! 		    rettv->vval.v_string = get_reg_contents(**arg,
22c937
! 							    GREG_EXPR_SRC);
22c937
  		}
22c937
  		if (**arg != NUL)
22c937
  		    ++*arg;
22c937
***************
22c937
*** 7970,7976 ****
22c937
      {"getpid",		0, 0, f_getpid},
22c937
      {"getpos",		1, 1, f_getpos},
22c937
      {"getqflist",	0, 0, f_getqflist},
22c937
!     {"getreg",		0, 2, f_getreg},
22c937
      {"getregtype",	0, 1, f_getregtype},
22c937
      {"gettabvar",	2, 3, f_gettabvar},
22c937
      {"gettabwinvar",	3, 4, f_gettabwinvar},
22c937
--- 7971,7977 ----
22c937
      {"getpid",		0, 0, f_getpid},
22c937
      {"getpos",		1, 1, f_getpos},
22c937
      {"getqflist",	0, 0, f_getqflist},
22c937
!     {"getreg",		0, 3, f_getreg},
22c937
      {"getregtype",	0, 1, f_getregtype},
22c937
      {"gettabvar",	2, 3, f_gettabvar},
22c937
      {"gettabwinvar",	3, 4, f_gettabwinvar},
22c937
***************
22c937
*** 11799,11804 ****
22c937
--- 11800,11806 ----
22c937
      char_u	*strregname;
22c937
      int		regname;
22c937
      int		arg2 = FALSE;
22c937
+     int		return_list = FALSE;
22c937
      int		error = FALSE;
22c937
  
22c937
      if (argvars[0].v_type != VAR_UNKNOWN)
22c937
***************
22c937
*** 11806,11822 ****
22c937
  	strregname = get_tv_string_chk(&argvars[0]);
22c937
  	error = strregname == NULL;
22c937
  	if (argvars[1].v_type != VAR_UNKNOWN)
22c937
  	    arg2 = get_tv_number_chk(&argvars[1], &error);
22c937
      }
22c937
      else
22c937
  	strregname = vimvars[VV_REG].vv_str;
22c937
      regname = (strregname == NULL ? '"' : *strregname);
22c937
      if (regname == 0)
22c937
  	regname = '"';
22c937
  
22c937
!     rettv->v_type = VAR_STRING;
22c937
!     rettv->vval.v_string = error ? NULL :
22c937
! 				    get_reg_contents(regname, TRUE, arg2);
22c937
  }
22c937
  
22c937
  /*
22c937
--- 11808,11841 ----
22c937
  	strregname = get_tv_string_chk(&argvars[0]);
22c937
  	error = strregname == NULL;
22c937
  	if (argvars[1].v_type != VAR_UNKNOWN)
22c937
+ 	{
22c937
  	    arg2 = get_tv_number_chk(&argvars[1], &error);
22c937
+ 	    if (!error && argvars[2].v_type != VAR_UNKNOWN)
22c937
+ 		return_list = get_tv_number_chk(&argvars[2], &error);
22c937
+ 	}
22c937
      }
22c937
      else
22c937
  	strregname = vimvars[VV_REG].vv_str;
22c937
+ 
22c937
+     if (error)
22c937
+ 	return;
22c937
+ 
22c937
      regname = (strregname == NULL ? '"' : *strregname);
22c937
      if (regname == 0)
22c937
  	regname = '"';
22c937
  
22c937
!     if (return_list)
22c937
!     {
22c937
! 	rettv->v_type = VAR_LIST;
22c937
! 	rettv->vval.v_list = (list_T *)get_reg_contents(regname,
22c937
! 				      (arg2 ? GREG_EXPR_SRC : 0) | GREG_LIST);
22c937
!     }
22c937
!     else
22c937
!     {
22c937
! 	rettv->v_type = VAR_STRING;
22c937
! 	rettv->vval.v_string = get_reg_contents(regname,
22c937
! 						    arg2 ? GREG_EXPR_SRC : 0);
22c937
!     }
22c937
  }
22c937
  
22c937
  /*
22c937
***************
22c937
*** 17891,17899 ****
22c937
      typval_T	*rettv;
22c937
  {
22c937
      int		error = FALSE;
22c937
-     char_u	**match;
22c937
-     char_u	**s;
22c937
-     listitem_T	*li;
22c937
      int		no;
22c937
      int		retList = 0;
22c937
  
22c937
--- 17910,17915 ----
22c937
*** ../vim-7.4.241/src/ops.c	2014-03-23 15:12:29.931264336 +0100
22c937
--- src/ops.c	2014-04-02 19:36:08.831614995 +0200
22c937
***************
22c937
*** 6166,6181 ****
22c937
      return MAUTO;
22c937
  }
22c937
  
22c937
  /*
22c937
   * Return the contents of a register as a single allocated string.
22c937
   * Used for "@r" in expressions and for getreg().
22c937
   * Returns NULL for error.
22c937
   */
22c937
      char_u *
22c937
! get_reg_contents(regname, allowexpr, expr_src)
22c937
      int		regname;
22c937
!     int		allowexpr;	/* allow "=" register */
22c937
!     int		expr_src;	/* get expression for "=" register */
22c937
  {
22c937
      long	i;
22c937
      char_u	*retval;
22c937
--- 6166,6214 ----
22c937
      return MAUTO;
22c937
  }
22c937
  
22c937
+ static char_u *getreg_wrap_one_line __ARGS((char_u *s, int flags));
22c937
+ 
22c937
+ /*
22c937
+  * When "flags" has GREG_LIST return a list with text "s".
22c937
+  * Otherwise just return "s".
22c937
+  */
22c937
+     static char_u *
22c937
+ getreg_wrap_one_line(s, flags)
22c937
+     char_u	*s;
22c937
+     int		flags;
22c937
+ {
22c937
+     if (flags & GREG_LIST)
22c937
+     {
22c937
+ 	list_T *list = list_alloc();
22c937
+ 
22c937
+ 	if (list != NULL)
22c937
+ 	{
22c937
+ 	    if (list_append_string(list, NULL, -1) == FAIL)
22c937
+ 	    {
22c937
+ 		list_free(list, TRUE);
22c937
+ 		return NULL;
22c937
+ 	    }
22c937
+ 	    list->lv_first->li_tv.vval.v_string = s;
22c937
+ 	}
22c937
+ 	return (char_u *)list;
22c937
+     }
22c937
+     return s;
22c937
+ }
22c937
+ 
22c937
  /*
22c937
   * Return the contents of a register as a single allocated string.
22c937
   * Used for "@r" in expressions and for getreg().
22c937
   * Returns NULL for error.
22c937
+  * Flags:
22c937
+  *	GREG_NO_EXPR	Do not allow expression register
22c937
+  *	GREG_EXPR_SRC	For the expression register: return expression itself,
22c937
+  *			not the result of its evaluation.
22c937
+  *	GREG_LIST	Return a list of lines in place of a single string.
22c937
   */
22c937
      char_u *
22c937
! get_reg_contents(regname, flags)
22c937
      int		regname;
22c937
!     int		flags;
22c937
  {
22c937
      long	i;
22c937
      char_u	*retval;
22c937
***************
22c937
*** 6185,6197 ****
22c937
      /* Don't allow using an expression register inside an expression */
22c937
      if (regname == '=')
22c937
      {
22c937
! 	if (allowexpr)
22c937
! 	{
22c937
! 	    if (expr_src)
22c937
! 		return get_expr_line_src();
22c937
! 	    return get_expr_line();
22c937
! 	}
22c937
! 	return NULL;
22c937
      }
22c937
  
22c937
      if (regname == '@')	    /* "@@" is used for unnamed register */
22c937
--- 6218,6228 ----
22c937
      /* Don't allow using an expression register inside an expression */
22c937
      if (regname == '=')
22c937
      {
22c937
! 	if (flags & GREG_NO_EXPR)
22c937
! 	    return NULL;
22c937
! 	if (flags & GREG_EXPR_SRC)
22c937
! 	    return getreg_wrap_one_line(get_expr_line_src(), flags);
22c937
! 	return getreg_wrap_one_line(get_expr_line(), flags);
22c937
      }
22c937
  
22c937
      if (regname == '@')	    /* "@@" is used for unnamed register */
22c937
***************
22c937
*** 6209,6223 ****
22c937
      {
22c937
  	if (retval == NULL)
22c937
  	    return NULL;
22c937
! 	if (!allocated)
22c937
! 	    retval = vim_strsave(retval);
22c937
! 	return retval;
22c937
      }
22c937
  
22c937
      get_yank_register(regname, FALSE);
22c937
      if (y_current->y_array == NULL)
22c937
  	return NULL;
22c937
  
22c937
      /*
22c937
       * Compute length of resulting string.
22c937
       */
22c937
--- 6240,6272 ----
22c937
      {
22c937
  	if (retval == NULL)
22c937
  	    return NULL;
22c937
! 	if (allocated)
22c937
! 	    return getreg_wrap_one_line(retval, flags);
22c937
! 	return getreg_wrap_one_line(vim_strsave(retval), flags);
22c937
      }
22c937
  
22c937
      get_yank_register(regname, FALSE);
22c937
      if (y_current->y_array == NULL)
22c937
  	return NULL;
22c937
  
22c937
+     if (flags & GREG_LIST)
22c937
+     {
22c937
+ 	list_T	*list = list_alloc();
22c937
+ 	int	error = FALSE;
22c937
+ 
22c937
+ 	if (list == NULL)
22c937
+ 	    return NULL;
22c937
+ 	for (i = 0; i < y_current->y_size; ++i)
22c937
+ 	    if (list_append_string(list, y_current->y_array[i], -1) == FAIL)
22c937
+ 		error = TRUE;
22c937
+ 	if (error)
22c937
+ 	{
22c937
+ 	    list_free(list, TRUE);
22c937
+ 	    return NULL;
22c937
+ 	}
22c937
+ 	return (char_u *)list;
22c937
+     }
22c937
+ 
22c937
      /*
22c937
       * Compute length of resulting string.
22c937
       */
22c937
*** ../vim-7.4.241/src/proto/ops.pro	2013-08-10 13:37:22.000000000 +0200
22c937
--- src/proto/ops.pro	2014-04-02 19:17:22.407630490 +0200
22c937
***************
22c937
*** 53,59 ****
22c937
  int clip_convert_selection __ARGS((char_u **str, long_u *len, VimClipboard *cbd));
22c937
  void dnd_yank_drag_data __ARGS((char_u *str, long len));
22c937
  char_u get_reg_type __ARGS((int regname, long *reglen));
22c937
! char_u *get_reg_contents __ARGS((int regname, int allowexpr, int expr_src));
22c937
  void write_reg_contents __ARGS((int name, char_u *str, int maxlen, int must_append));
22c937
  void write_reg_contents_ex __ARGS((int name, char_u *str, int maxlen, int must_append, int yank_type, long block_len));
22c937
  void clear_oparg __ARGS((oparg_T *oap));
22c937
--- 53,59 ----
22c937
  int clip_convert_selection __ARGS((char_u **str, long_u *len, VimClipboard *cbd));
22c937
  void dnd_yank_drag_data __ARGS((char_u *str, long len));
22c937
  char_u get_reg_type __ARGS((int regname, long *reglen));
22c937
! char_u *get_reg_contents __ARGS((int regname, int flags));
22c937
  void write_reg_contents __ARGS((int name, char_u *str, int maxlen, int must_append));
22c937
  void write_reg_contents_ex __ARGS((int name, char_u *str, int maxlen, int must_append, int yank_type, long block_len));
22c937
  void clear_oparg __ARGS((oparg_T *oap));
22c937
*** ../vim-7.4.241/src/vim.h	2014-04-01 19:55:46.252787300 +0200
22c937
--- src/vim.h	2014-04-02 19:17:22.407630490 +0200
22c937
***************
22c937
*** 2259,2264 ****
22c937
--- 2259,2269 ----
22c937
  #define SREQ_WIN	1	/* Request window-local option */
22c937
  #define SREQ_BUF	2	/* Request buffer-local option */
22c937
  
22c937
+ /* Flags for get_reg_contents */
22c937
+ #define GREG_NO_EXPR	1	/* Do not allow expression register */
22c937
+ #define GREG_EXPR_SRC	2	/* Return expression itself for "=" register */
22c937
+ #define GREG_LIST	4	/* Return list */
22c937
+ 
22c937
  /* Character used as separated in autoload function/variable names. */
22c937
  #define AUTOLOAD_CHAR '#'
22c937
  
22c937
*** ../vim-7.4.241/src/Makefile	2014-04-01 14:08:14.685074130 +0200
22c937
--- src/Makefile	2014-04-02 19:42:21.931609863 +0200
22c937
***************
22c937
*** 1880,1885 ****
22c937
--- 1880,1886 ----
22c937
  
22c937
  # Run individual test, assuming that Vim was already compiled.
22c937
  test1 test2 test3 test4 test5 test6 test7 test8 test9 \
22c937
+ 	test_eval \
22c937
  	test_options \
22c937
  	test10 test11 test12 test13 test14 test15 test16 test17 test18 test19 \
22c937
  	test20 test21 test22 test23 test24 test25 test26 test27 test28 test29 \
22c937
*** ../vim-7.4.241/src/testdir/test_eval.in	2014-04-02 19:51:32.391602291 +0200
22c937
--- src/testdir/test_eval.in	2014-04-02 19:47:13.607605851 +0200
22c937
***************
22c937
*** 0 ****
22c937
--- 1,21 ----
22c937
+ Test for various eval features.
22c937
+ 
22c937
+ STARTTEST
22c937
+ :so small.vim
22c937
+ :"
22c937
+ :" test getreg()
22c937
+ /^one
22c937
+ "ay3j:$put =string(getreg('a'))
22c937
+ :$put =string(getreg('a', 1, 1))
22c937
+ :"
22c937
+ :/^result/,$w! test.out
22c937
+ :qa!
22c937
+ ENDTEST
22c937
+ 
22c937
+ one
22c937
+ two
22c937
+ three
22c937
+ four
22c937
+ five
22c937
+ 
22c937
+ result
22c937
*** ../vim-7.4.241/src/testdir/test_eval.ok	2014-04-02 19:51:32.399602291 +0200
22c937
--- src/testdir/test_eval.ok	2014-04-02 19:48:51.595604503 +0200
22c937
***************
22c937
*** 0 ****
22c937
--- 1,7 ----
22c937
+ result
22c937
+ 'one
22c937
+ two
22c937
+ three
22c937
+ four
22c937
+ '
22c937
+ ['one', 'two', 'three', 'four']
22c937
*** ../vim-7.4.241/src/testdir/Make_amiga.mak	2014-04-01 14:08:14.685074130 +0200
22c937
--- src/testdir/Make_amiga.mak	2014-04-02 19:41:24.331610655 +0200
22c937
***************
22c937
*** 36,41 ****
22c937
--- 36,42 ----
22c937
  		test94.out test95.out test96.out test97.out test98.out \
22c937
  		test99.out test100.out test101.out test102.out test103.out \
22c937
  		test104.out test105.out test106.out \
22c937
+ 		test_eval.out \
22c937
  		test_options.out
22c937
  
22c937
  .SUFFIXES: .in .out
22c937
***************
22c937
*** 159,162 ****
22c937
--- 160,164 ----
22c937
  test104.out: test104.in
22c937
  test105.out: test105.in
22c937
  test106.out: test106.in
22c937
+ test_eval.out: test_eval.in
22c937
  test_options.out: test_options.in
22c937
*** ../vim-7.4.241/src/testdir/Make_dos.mak	2014-04-01 14:08:14.685074130 +0200
22c937
--- src/testdir/Make_dos.mak	2014-04-02 19:41:34.419610516 +0200
22c937
***************
22c937
*** 35,40 ****
22c937
--- 35,41 ----
22c937
  		test94.out test95.out test96.out test98.out test99.out \
22c937
  		test100.out test101.out test102.out test103.out test104.out \
22c937
  		test105.out test106.out \
22c937
+ 		test_eval.out \
22c937
  		test_options.out
22c937
  
22c937
  SCRIPTS32 =	test50.out test70.out
22c937
*** ../vim-7.4.241/src/testdir/Make_ming.mak	2014-04-01 14:08:14.685074130 +0200
22c937
--- src/testdir/Make_ming.mak	2014-04-02 19:41:43.131610397 +0200
22c937
***************
22c937
*** 55,60 ****
22c937
--- 55,61 ----
22c937
  		test94.out test95.out test96.out test98.out test99.out \
22c937
  		test100.out test101.out test102.out test103.out test104.out \
22c937
  		test105.out test106.out \
22c937
+ 		test_eval.out \
22c937
  		test_options.out
22c937
  
22c937
  SCRIPTS32 =	test50.out test70.out
22c937
*** ../vim-7.4.241/src/testdir/Make_os2.mak	2014-04-01 14:08:14.685074130 +0200
22c937
--- src/testdir/Make_os2.mak	2014-04-02 19:41:50.659610293 +0200
22c937
***************
22c937
*** 37,42 ****
22c937
--- 37,43 ----
22c937
  		test94.out test95.out test96.out test98.out test99.out \
22c937
  		test100.out test101.out test102.out test103.out test104.out \
22c937
  		test105.out test106.out \
22c937
+ 		test_eval.out \
22c937
  		test_options.out
22c937
  
22c937
  .SUFFIXES: .in .out
22c937
*** ../vim-7.4.241/src/testdir/Make_vms.mms	2014-04-01 14:08:14.689074130 +0200
22c937
--- src/testdir/Make_vms.mms	2014-04-02 19:41:58.971610179 +0200
22c937
***************
22c937
*** 96,101 ****
22c937
--- 96,102 ----
22c937
  	 test95.out test96.out test98.out test99.out \
22c937
  	 test100.out test101.out test103.out test104.out \
22c937
  	 test105.out test106.out \
22c937
+ 	 test_eval.out \
22c937
  	 test_options.out
22c937
  
22c937
  # Known problems:
22c937
*** ../vim-7.4.241/src/version.c	2014-04-02 19:00:53.047644099 +0200
22c937
--- src/version.c	2014-04-02 19:46:41.867606287 +0200
22c937
***************
22c937
*** 736,737 ****
22c937
--- 736,739 ----
22c937
  {   /* Add new patch number below this line */
22c937
+ /**/
22c937
+     242,
22c937
  /**/
22c937
22c937
-- 
22c937
Don't Panic!
22c937
		-- The Hitchhiker's Guide to the Galaxy
22c937
22c937
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
22c937
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
22c937
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
22c937
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///