Blame SOURCES/7.4.073

22c937
To: vim_dev@googlegroups.com
22c937
Subject: Patch 7.4.073
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.073
22c937
Problem:    Setting undolevels for one buffer changes undo in another.
22c937
Solution:   Make 'undolevels' a global-local option. (Christian Brabandt)
22c937
Files:      runtime/doc/options.txt, src/buffer.c, src/option.c, src/option.h
22c937
            src/structs.h, src/undo.c
22c937
22c937
22c937
*** ../vim-7.4.072/runtime/doc/options.txt	2013-08-10 13:24:57.000000000 +0200
22c937
--- runtime/doc/options.txt	2013-11-06 04:18:43.000000000 +0100
22c937
***************
22c937
*** 7594,7600 ****
22c937
  						*'undolevels'* *'ul'*
22c937
  'undolevels' 'ul'	number	(default 100, 1000 for Unix, VMS,
22c937
  						Win32 and OS/2)
22c937
! 			global
22c937
  			{not in Vi}
22c937
  	Maximum number of changes that can be undone.  Since undo information
22c937
  	is kept in memory, higher numbers will cause more memory to be used
22c937
--- 7594,7600 ----
22c937
  						*'undolevels'* *'ul'*
22c937
  'undolevels' 'ul'	number	(default 100, 1000 for Unix, VMS,
22c937
  						Win32 and OS/2)
22c937
! 			global or local to buffer |global-local|
22c937
  			{not in Vi}
22c937
  	Maximum number of changes that can be undone.  Since undo information
22c937
  	is kept in memory, higher numbers will cause more memory to be used
22c937
***************
22c937
*** 7605,7612 ****
22c937
  <	But you can also get Vi compatibility by including the 'u' flag in
22c937
  	'cpoptions', and still be able to use CTRL-R to repeat undo.
22c937
  	Also see |undo-two-ways|.
22c937
! 	Set to a negative number for no undo at all: >
22c937
! 		set ul=-1
22c937
  <	This helps when you run out of memory for a single change.
22c937
  	Also see |clear-undo|.
22c937
  
22c937
--- 7605,7613 ----
22c937
  <	But you can also get Vi compatibility by including the 'u' flag in
22c937
  	'cpoptions', and still be able to use CTRL-R to repeat undo.
22c937
  	Also see |undo-two-ways|.
22c937
! 	Set to -1 for no undo at all.  You might want to do this only for the
22c937
! 	current buffer: >
22c937
! 		setlocal ul=-1
22c937
  <	This helps when you run out of memory for a single change.
22c937
  	Also see |clear-undo|.
22c937
  
22c937
*** ../vim-7.4.072/src/buffer.c	2013-11-05 17:40:47.000000000 +0100
22c937
--- src/buffer.c	2013-11-06 04:25:27.000000000 +0100
22c937
***************
22c937
*** 1949,1954 ****
22c937
--- 1949,1955 ----
22c937
      clear_string_option(&buf->b_p_qe);
22c937
  #endif
22c937
      buf->b_p_ar = -1;
22c937
+     buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
22c937
  }
22c937
  
22c937
  /*
22c937
*** ../vim-7.4.072/src/option.c	2013-11-05 07:12:59.000000000 +0100
22c937
--- src/option.c	2013-11-06 04:34:23.000000000 +0100
22c937
***************
22c937
*** 234,239 ****
22c937
--- 234,240 ----
22c937
  #ifdef FEAT_STL_OPT
22c937
  # define PV_STL		OPT_BOTH(OPT_WIN(WV_STL))
22c937
  #endif
22c937
+ #define PV_UL		OPT_BOTH(OPT_BUF(BV_UL))
22c937
  #ifdef FEAT_WINDOWS
22c937
  # define PV_WFH		OPT_WIN(WV_WFH)
22c937
  #endif
22c937
***************
22c937
*** 2683,2689 ****
22c937
  #endif
22c937
  			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
22c937
      {"undolevels",  "ul",   P_NUM|P_VI_DEF,
22c937
! 			    (char_u *)&p_ul, PV_NONE,
22c937
  			    {
22c937
  #if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
22c937
  			    (char_u *)1000L,
22c937
--- 2684,2690 ----
22c937
  #endif
22c937
  			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
22c937
      {"undolevels",  "ul",   P_NUM|P_VI_DEF,
22c937
! 			    (char_u *)&p_ul, PV_UL,
22c937
  			    {
22c937
  #if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
22c937
  			    (char_u *)1000L,
22c937
***************
22c937
*** 3313,3318 ****
22c937
--- 3314,3320 ----
22c937
  
22c937
      curbuf->b_p_initialized = TRUE;
22c937
      curbuf->b_p_ar = -1;	/* no local 'autoread' value */
22c937
+     curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
22c937
      check_buf_options(curbuf);
22c937
      check_win_options(curwin);
22c937
      check_options();
22c937
***************
22c937
*** 4512,4519 ****
22c937
  						((flags & P_VI_DEF) || cp_val)
22c937
  						 ?  VI_DEFAULT : VIM_DEFAULT];
22c937
  			else if (nextchar == '<')
22c937
! 			    value = *(long *)get_varp_scope(&(options[opt_idx]),
22c937
! 								  OPT_GLOBAL);
22c937
  			else if (((long *)varp == &p_wc
22c937
  				    || (long *)varp == &p_wcm)
22c937
  				&& (*arg == '<'
22c937
--- 4514,4529 ----
22c937
  						((flags & P_VI_DEF) || cp_val)
22c937
  						 ?  VI_DEFAULT : VIM_DEFAULT];
22c937
  			else if (nextchar == '<')
22c937
! 			{
22c937
! 			    /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
22c937
! 			     * use the global value. */
22c937
! 			    if ((long *)varp == &curbuf->b_p_ul
22c937
! 						    && opt_flags == OPT_LOCAL)
22c937
! 				value = NO_LOCAL_UNDOLEVEL;
22c937
! 			    else
22c937
! 				value = *(long *)get_varp_scope(
22c937
! 					     &(options[opt_idx]), OPT_GLOBAL);
22c937
! 			}
22c937
  			else if (((long *)varp == &p_wc
22c937
  				    || (long *)varp == &p_wcm)
22c937
  				&& (*arg == '<'
22c937
***************
22c937
*** 8487,8492 ****
22c937
--- 8497,8509 ----
22c937
  	u_sync(TRUE);
22c937
  	p_ul = value;
22c937
      }
22c937
+     else if (pp == &curbuf->b_p_ul)
22c937
+     {
22c937
+ 	/* use the old value, otherwise u_sync() may not work properly */
22c937
+ 	curbuf->b_p_ul = old_value;
22c937
+ 	u_sync(TRUE);
22c937
+ 	curbuf->b_p_ul = value;
22c937
+     }
22c937
  
22c937
  #ifdef FEAT_LINEBREAK
22c937
      /* 'numberwidth' must be positive */
22c937
***************
22c937
*** 9720,9726 ****
22c937
  /*
22c937
   * Unset local option value, similar to ":set opt<".
22c937
   */
22c937
- 
22c937
      void
22c937
  unset_global_local_option(name, from)
22c937
      char_u	*name;
22c937
--- 9737,9742 ----
22c937
***************
22c937
*** 9793,9798 ****
22c937
--- 9809,9817 ----
22c937
  	    clear_string_option(&((win_T *)from)->w_p_stl);
22c937
  	    break;
22c937
  #endif
22c937
+ 	case PV_UL:
22c937
+ 	    buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
22c937
+ 	    break;
22c937
      }
22c937
  }
22c937
  
22c937
***************
22c937
*** 9841,9846 ****
22c937
--- 9860,9866 ----
22c937
  #ifdef FEAT_STL_OPT
22c937
  	    case PV_STL:  return (char_u *)&(curwin->w_p_stl);
22c937
  #endif
22c937
+ 	    case PV_UL:   return (char_u *)&(curbuf->b_p_ul);
22c937
  	}
22c937
  	return NULL; /* "cannot happen" */
22c937
      }
22c937
***************
22c937
*** 9905,9910 ****
22c937
--- 9925,9932 ----
22c937
  	case PV_STL:	return *curwin->w_p_stl != NUL
22c937
  				    ? (char_u *)&(curwin->w_p_stl) : p->var;
22c937
  #endif
22c937
+ 	case PV_UL:	return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
22c937
+ 				    ? (char_u *)&(curbuf->b_p_ul) : p->var;
22c937
  
22c937
  #ifdef FEAT_ARABIC
22c937
  	case PV_ARAB:	return (char_u *)&(curwin->w_p_arab);
22c937
***************
22c937
*** 10445,10450 ****
22c937
--- 10467,10473 ----
22c937
  	    /* options that are normally global but also have a local value
22c937
  	     * are not copied, start using the global value */
22c937
  	    buf->b_p_ar = -1;
22c937
+ 	    buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
22c937
  #ifdef FEAT_QUICKFIX
22c937
  	    buf->b_p_gp = empty_option;
22c937
  	    buf->b_p_mp = empty_option;
22c937
*** ../vim-7.4.072/src/option.h	2013-06-26 18:41:39.000000000 +0200
22c937
--- src/option.h	2013-11-06 04:17:40.000000000 +0100
22c937
***************
22c937
*** 1031,1036 ****
22c937
--- 1031,1037 ----
22c937
      , BV_TW
22c937
      , BV_TX
22c937
      , BV_UDF
22c937
+     , BV_UL
22c937
      , BV_WM
22c937
      , BV_COUNT	    /* must be the last one */
22c937
  };
22c937
***************
22c937
*** 1109,1111 ****
22c937
--- 1110,1115 ----
22c937
      , WV_WRAP
22c937
      , WV_COUNT	    /* must be the last one */
22c937
  };
22c937
+ 
22c937
+ /* Value for b_p_ul indicating the global value must be used. */
22c937
+ #define NO_LOCAL_UNDOLEVEL -123456
22c937
*** ../vim-7.4.072/src/structs.h	2013-11-05 07:12:59.000000000 +0100
22c937
--- src/structs.h	2013-11-06 04:26:17.000000000 +0100
22c937
***************
22c937
*** 1627,1632 ****
22c937
--- 1627,1633 ----
22c937
      char_u	*b_p_dict;	/* 'dictionary' local value */
22c937
      char_u	*b_p_tsr;	/* 'thesaurus' local value */
22c937
  #endif
22c937
+     long	b_p_ul;		/* 'undolevels' local value */
22c937
  #ifdef FEAT_PERSISTENT_UNDO
22c937
      int		b_p_udf;	/* 'undofile' */
22c937
  #endif
22c937
*** ../vim-7.4.072/src/undo.c	2013-09-08 15:40:45.000000000 +0200
22c937
--- src/undo.c	2013-11-06 04:33:12.000000000 +0100
22c937
***************
22c937
*** 83,88 ****
22c937
--- 83,89 ----
22c937
  
22c937
  #include "vim.h"
22c937
  
22c937
+ static long get_undolevel __ARGS((void));
22c937
  static void u_unch_branch __ARGS((u_header_T *uhp));
22c937
  static u_entry_T *u_get_headentry __ARGS((void));
22c937
  static void u_getbot __ARGS((void));
22c937
***************
22c937
*** 336,341 ****
22c937
--- 337,353 ----
22c937
  }
22c937
  
22c937
  /*
22c937
+  * Get the undolevle value for the current buffer.
22c937
+  */
22c937
+     static long
22c937
+ get_undolevel()
22c937
+ {
22c937
+     if (curbuf->b_p_ul == NO_LOCAL_UNDOLEVEL)
22c937
+ 	return p_ul;
22c937
+     return curbuf->b_p_ul;
22c937
+ }
22c937
+ 
22c937
+ /*
22c937
   * Common code for various ways to save text before a change.
22c937
   * "top" is the line above the first changed line.
22c937
   * "bot" is the line below the last changed line.
22c937
***************
22c937
*** 419,425 ****
22c937
  	curbuf->b_new_change = TRUE;
22c937
  #endif
22c937
  
22c937
! 	if (p_ul >= 0)
22c937
  	{
22c937
  	    /*
22c937
  	     * Make a new header entry.  Do this first so that we don't mess
22c937
--- 431,437 ----
22c937
  	curbuf->b_new_change = TRUE;
22c937
  #endif
22c937
  
22c937
! 	if (get_undolevel() >= 0)
22c937
  	{
22c937
  	    /*
22c937
  	     * Make a new header entry.  Do this first so that we don't mess
22c937
***************
22c937
*** 449,455 ****
22c937
  	/*
22c937
  	 * free headers to keep the size right
22c937
  	 */
22c937
! 	while (curbuf->b_u_numhead > p_ul && curbuf->b_u_oldhead != NULL)
22c937
  	{
22c937
  	    u_header_T	    *uhfree = curbuf->b_u_oldhead;
22c937
  
22c937
--- 461,468 ----
22c937
  	/*
22c937
  	 * free headers to keep the size right
22c937
  	 */
22c937
! 	while (curbuf->b_u_numhead > get_undolevel()
22c937
! 					       && curbuf->b_u_oldhead != NULL)
22c937
  	{
22c937
  	    u_header_T	    *uhfree = curbuf->b_u_oldhead;
22c937
  
22c937
***************
22c937
*** 530,536 ****
22c937
      }
22c937
      else
22c937
      {
22c937
! 	if (p_ul < 0)		/* no undo at all */
22c937
  	    return OK;
22c937
  
22c937
  	/*
22c937
--- 543,549 ----
22c937
      }
22c937
      else
22c937
      {
22c937
! 	if (get_undolevel() < 0)	/* no undo at all */
22c937
  	    return OK;
22c937
  
22c937
  	/*
22c937
***************
22c937
*** 1972,1978 ****
22c937
  	{
22c937
  	    if (curbuf->b_u_curhead == NULL)		/* first undo */
22c937
  		curbuf->b_u_curhead = curbuf->b_u_newhead;
22c937
! 	    else if (p_ul > 0)				/* multi level undo */
22c937
  		/* get next undo */
22c937
  		curbuf->b_u_curhead = curbuf->b_u_curhead->uh_next.ptr;
22c937
  	    /* nothing to undo */
22c937
--- 1985,1991 ----
22c937
  	{
22c937
  	    if (curbuf->b_u_curhead == NULL)		/* first undo */
22c937
  		curbuf->b_u_curhead = curbuf->b_u_newhead;
22c937
! 	    else if (get_undolevel() > 0)		/* multi level undo */
22c937
  		/* get next undo */
22c937
  		curbuf->b_u_curhead = curbuf->b_u_curhead->uh_next.ptr;
22c937
  	    /* nothing to undo */
22c937
***************
22c937
*** 1993,1999 ****
22c937
  	}
22c937
  	else
22c937
  	{
22c937
! 	    if (curbuf->b_u_curhead == NULL || p_ul <= 0)
22c937
  	    {
22c937
  		beep_flush();	/* nothing to redo */
22c937
  		if (count == startcount - 1)
22c937
--- 2006,2012 ----
22c937
  	}
22c937
  	else
22c937
  	{
22c937
! 	    if (curbuf->b_u_curhead == NULL || get_undolevel() <= 0)
22c937
  	    {
22c937
  		beep_flush();	/* nothing to redo */
22c937
  		if (count == startcount - 1)
22c937
***************
22c937
*** 2751,2757 ****
22c937
      if (im_is_preediting())
22c937
  	return;		    /* XIM is busy, don't break an undo sequence */
22c937
  #endif
22c937
!     if (p_ul < 0)
22c937
  	curbuf->b_u_synced = TRUE;  /* no entries, nothing to do */
22c937
      else
22c937
      {
22c937
--- 2764,2770 ----
22c937
      if (im_is_preediting())
22c937
  	return;		    /* XIM is busy, don't break an undo sequence */
22c937
  #endif
22c937
!     if (get_undolevel() < 0)
22c937
  	curbuf->b_u_synced = TRUE;  /* no entries, nothing to do */
22c937
      else
22c937
      {
22c937
***************
22c937
*** 2911,2917 ****
22c937
      }
22c937
      if (!curbuf->b_u_synced)
22c937
  	return;		    /* already unsynced */
22c937
!     if (p_ul < 0)
22c937
  	return;		    /* no entries, nothing to do */
22c937
      else
22c937
      {
22c937
--- 2924,2930 ----
22c937
      }
22c937
      if (!curbuf->b_u_synced)
22c937
  	return;		    /* already unsynced */
22c937
!     if (get_undolevel() < 0)
22c937
  	return;		    /* no entries, nothing to do */
22c937
      else
22c937
      {
22c937
*** ../vim-7.4.072/src/version.c	2013-11-06 04:04:29.000000000 +0100
22c937
--- src/version.c	2013-11-06 05:21:43.000000000 +0100
22c937
***************
22c937
*** 740,741 ****
22c937
--- 740,743 ----
22c937
  {   /* Add new patch number below this line */
22c937
+ /**/
22c937
+     73,
22c937
  /**/
22c937
22c937
-- 
22c937
Living on Earth includes an annual free trip around the Sun.
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    ///