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