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