Hi Bram!
On Di, 14 Dez 2010, Bram Moolenaar wrote:
>
> Christian Brabandt wrote:
>
> > attached is a patch, that makes 'undolevels' a buffer-local option. I
> > think, this is useful if you are editing a large file you might want to
> > disable undo completely, without loosing the undo information for other
> > buffers.
>
> Yes, this makes a lot of sense.
>
> Perhaps the option should be global-local? That means that ":set" will
> work as it does now, changing the value for all buffers, except for
> buffers where ":setlocal" was used to specify a different value.
Attached is a new version, that is global-local. Please check, I am not
sure, I understand the code correctly.
> Although the change is straightforward, it would still be nice to have a
> test for this. Thus edit a file, check that undolevels works (try two
> values), split the window to edit another file, verify that setting
> undolevels here doesn't change what happens in the other buffer.
> Something like that.
I can probably make a test. But this will have to wait a couple of days.
regards,
Christian
--
Ich bin froh, daß Du da bist und nicht hier.
-- Kurt Tucholsky
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -7401,7 +7401,7 @@
*'undolevels'* *'ul'*
'undolevels' 'ul' number (default 100, 1000 for Unix, VMS,
Win32 and OS/2)
- global
+ global or local to buffer |global-local|
{not in Vi}
Maximum number of changes that can be undone. Since undo information
is kept in memory, higher numbers will cause more memory to be used
diff --git a/src/option.c b/src/option.c
--- a/src/option.c
+++ b/src/option.c
@@ -180,6 +180,7 @@
#ifdef FEAT_PERSISTENT_UNDO
# define PV_UDF OPT_BUF(BV_UDF)
#endif
+#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
#define PV_WM OPT_BUF(BV_WM)
/*
@@ -2654,7 +2655,7 @@
#endif
{(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
{"undolevels", "ul", P_NUM|P_VI_DEF,
- (char_u *)&p_ul, PV_NONE,
+ (char_u *)&p_ul, PV_UL,
{
#if (defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)) \
&& defined(FEAT_PERSISTENT_UNDO)
@@ -3286,6 +3287,7 @@
curbuf->b_p_initialized = TRUE;
curbuf->b_p_ar = -1; /* no local 'autoread' value */
+ curbuf->b_p_ul = -MAXLNUM; /* no local 'undolevels' value */
check_buf_options(curbuf);
check_win_options(curwin);
check_options();
@@ -4399,6 +4401,10 @@
if ((int *)varp == &curbuf->b_p_ar
&& opt_flags == OPT_LOCAL)
value = -1;
+ /* For 'undolevels' -MAXLNUM means to use global value. */
+ if ((long *)varp == &curbuf->b_p_ul
+ && opt_flags == OPT_LOCAL)
+ value = -MAXLNUM;
else
value = *(int *)get_varp_scope(&(options[opt_idx]),
OPT_GLOBAL);
@@ -8338,12 +8344,12 @@
#endif
/* sync undo before 'undolevels' changes */
- else if (pp == &p_ul)
+ else if (pp == &curbuf->b_p_ul)
{
/* use the old value, otherwise u_sync() may not work properly */
- p_ul = old_value;
+ curbuf->b_p_ul = old_value;
u_sync(TRUE);
- p_ul = value;
+ curbuf->b_p_ul = value;
}
@@ -9458,6 +9464,7 @@
case PV_KP: return (char_u *)&(curbuf->b_p_kp);
case PV_PATH: return (char_u *)&(curbuf->b_p_path);
case PV_AR: return (char_u *)&(curbuf->b_p_ar);
+ case PV_UL: return (char_u *)&(curbuf->b_p_ul);
case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
#ifdef FEAT_FIND_ID
case PV_DEF: return (char_u *)&(curbuf->b_p_def);
@@ -9506,8 +9513,11 @@
? (char_u *)&(curbuf->b_p_path) : p->var;
case PV_AR: return curbuf->b_p_ar >= 0
? (char_u *)&(curbuf->b_p_ar) : p->var;
+ case PV_UL: return curbuf->b_p_ul > -MAXLNUM
+ ? (char_u *)&(curbuf->b_p_ul) : p->var;
case PV_TAGS: return *curbuf->b_p_tags != NUL
? (char_u *)&(curbuf->b_p_tags) : p->var;
+
#ifdef FEAT_FIND_ID
case PV_DEF: return *curbuf->b_p_def != NUL
? (char_u *)&(curbuf->b_p_def) : p->var;
@@ -10073,6 +10083,7 @@
/* options that are normally global but also have a local value
* are not copied, start using the global value */
buf->b_p_ar = -1;
+ buf->b_p_ul = -MAXLNUM;
#ifdef FEAT_QUICKFIX
buf->b_p_gp = empty_option;
buf->b_p_mp = empty_option;
diff --git a/src/option.h b/src/option.h
--- a/src/option.h
+++ b/src/option.h
@@ -1019,6 +1019,7 @@
, BV_TW
, BV_TX
, BV_UDF
+ , BV_UL
, BV_WM
, BV_COUNT /* must be the last one */
};
diff --git a/src/structs.h b/src/structs.h
--- a/src/structs.h
+++ b/src/structs.h
@@ -1558,6 +1558,7 @@
char_u *b_p_dict; /* 'dictionary' local value */
char_u *b_p_tsr; /* 'thesaurus' local value */
#endif
+ long b_p_ul; /* 'undolevels' */
#ifdef FEAT_PERSISTENT_UNDO
int b_p_udf; /* 'undofile' */
#endif
diff --git a/src/undo.c b/src/undo.c
--- a/src/undo.c
+++ b/src/undo.c
@@ -421,7 +421,7 @@
curbuf->b_new_change = TRUE;
#endif
- if (p_ul >= 0)
+ if (curbuf->b_p_ul >= 0)
{
/*
* Make a new header entry. Do this first so that we don't mess
@@ -451,7 +451,7 @@
/*
* free headers to keep the size right
*/
- while (curbuf->b_u_numhead > p_ul && curbuf->b_u_oldhead != NULL)
+ while (curbuf->b_u_numhead > curbuf->b_p_ul && curbuf->b_u_oldhead != NULL)
{
u_header_T *uhfree = curbuf->b_u_oldhead;
@@ -532,7 +532,7 @@
}
else
{
- if (p_ul < 0) /* no undo at all */
+ if (curbuf->b_p_ul < 0) /* no undo at all */
return OK;
/*
@@ -1970,7 +1970,7 @@
{
if (curbuf->b_u_curhead == NULL) /* first undo */
curbuf->b_u_curhead = curbuf->b_u_newhead;
- else if (p_ul > 0) /* multi level undo */
+ else if (curbuf->b_p_ul > 0) /* multi level undo */
/* get next undo */
curbuf->b_u_curhead = curbuf->b_u_curhead->uh_next.ptr;
/* nothing to undo */
@@ -1991,7 +1991,7 @@
}
else
{
- if (curbuf->b_u_curhead == NULL || p_ul <= 0)
+ if (curbuf->b_u_curhead == NULL || curbuf->b_p_ul <= 0)
{
beep_flush(); /* nothing to redo */
if (count == startcount - 1)
@@ -2749,7 +2749,7 @@
if (im_is_preediting())
return; /* XIM is busy, don't break an undo sequence */
#endif
- if (p_ul < 0)
+ if (curbuf->b_p_ul < 0)
curbuf->b_u_synced = TRUE; /* no entries, nothing to do */
else
{
@@ -2912,7 +2912,7 @@
}
if (!curbuf->b_u_synced)
return; /* already unsynced */
- if (p_ul < 0)
+ if (curbuf->b_p_ul < 0)
return; /* no entries, nothing to do */
else
{