Mercurial > vim
comparison src/undo.c @ 5446:d0595545e98a v7.4.073
updated for version 7.4.073
Problem: Setting undolevels for one buffer changes undo in another.
Solution: Make 'undolevels' a global-local option. (Christian Brabandt)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Wed, 06 Nov 2013 05:26:15 +0100 |
parents | 00d61a47df66 |
children | 9818311eeca0 |
comparison
equal
deleted
inserted
replaced
5445:75c7eef1de70 | 5446:d0595545e98a |
---|---|
81 #define UH_MAGIC 0x18dade /* value for uh_magic when in use */ | 81 #define UH_MAGIC 0x18dade /* value for uh_magic when in use */ |
82 #define UE_MAGIC 0xabc123 /* value for ue_magic when in use */ | 82 #define UE_MAGIC 0xabc123 /* value for ue_magic when in use */ |
83 | 83 |
84 #include "vim.h" | 84 #include "vim.h" |
85 | 85 |
86 static long get_undolevel __ARGS((void)); | |
86 static void u_unch_branch __ARGS((u_header_T *uhp)); | 87 static void u_unch_branch __ARGS((u_header_T *uhp)); |
87 static u_entry_T *u_get_headentry __ARGS((void)); | 88 static u_entry_T *u_get_headentry __ARGS((void)); |
88 static void u_getbot __ARGS((void)); | 89 static void u_getbot __ARGS((void)); |
89 static void u_doit __ARGS((int count)); | 90 static void u_doit __ARGS((int count)); |
90 static void u_undoredo __ARGS((int undo)); | 91 static void u_undoredo __ARGS((int undo)); |
334 | 335 |
335 return TRUE; | 336 return TRUE; |
336 } | 337 } |
337 | 338 |
338 /* | 339 /* |
340 * Get the undolevle value for the current buffer. | |
341 */ | |
342 static long | |
343 get_undolevel() | |
344 { | |
345 if (curbuf->b_p_ul == NO_LOCAL_UNDOLEVEL) | |
346 return p_ul; | |
347 return curbuf->b_p_ul; | |
348 } | |
349 | |
350 /* | |
339 * Common code for various ways to save text before a change. | 351 * Common code for various ways to save text before a change. |
340 * "top" is the line above the first changed line. | 352 * "top" is the line above the first changed line. |
341 * "bot" is the line below the last changed line. | 353 * "bot" is the line below the last changed line. |
342 * "newbot" is the new bottom line. Use zero when not known. | 354 * "newbot" is the new bottom line. Use zero when not known. |
343 * "reload" is TRUE when saving for a buffer reload. | 355 * "reload" is TRUE when saving for a buffer reload. |
417 #ifdef FEAT_JUMPLIST | 429 #ifdef FEAT_JUMPLIST |
418 /* Need to create new entry in b_changelist. */ | 430 /* Need to create new entry in b_changelist. */ |
419 curbuf->b_new_change = TRUE; | 431 curbuf->b_new_change = TRUE; |
420 #endif | 432 #endif |
421 | 433 |
422 if (p_ul >= 0) | 434 if (get_undolevel() >= 0) |
423 { | 435 { |
424 /* | 436 /* |
425 * Make a new header entry. Do this first so that we don't mess | 437 * Make a new header entry. Do this first so that we don't mess |
426 * up the undo info when out of memory. | 438 * up the undo info when out of memory. |
427 */ | 439 */ |
447 } | 459 } |
448 | 460 |
449 /* | 461 /* |
450 * free headers to keep the size right | 462 * free headers to keep the size right |
451 */ | 463 */ |
452 while (curbuf->b_u_numhead > p_ul && curbuf->b_u_oldhead != NULL) | 464 while (curbuf->b_u_numhead > get_undolevel() |
465 && curbuf->b_u_oldhead != NULL) | |
453 { | 466 { |
454 u_header_T *uhfree = curbuf->b_u_oldhead; | 467 u_header_T *uhfree = curbuf->b_u_oldhead; |
455 | 468 |
456 if (uhfree == old_curhead) | 469 if (uhfree == old_curhead) |
457 /* Can't reconnect the branch, delete all of it. */ | 470 /* Can't reconnect the branch, delete all of it. */ |
528 curbuf->b_u_oldhead = uhp; | 541 curbuf->b_u_oldhead = uhp; |
529 ++curbuf->b_u_numhead; | 542 ++curbuf->b_u_numhead; |
530 } | 543 } |
531 else | 544 else |
532 { | 545 { |
533 if (p_ul < 0) /* no undo at all */ | 546 if (get_undolevel() < 0) /* no undo at all */ |
534 return OK; | 547 return OK; |
535 | 548 |
536 /* | 549 /* |
537 * When saving a single line, and it has been saved just before, it | 550 * When saving a single line, and it has been saved just before, it |
538 * doesn't make sense saving it again. Saves a lot of memory when | 551 * doesn't make sense saving it again. Saves a lot of memory when |
1970 | 1983 |
1971 if (undo_undoes) | 1984 if (undo_undoes) |
1972 { | 1985 { |
1973 if (curbuf->b_u_curhead == NULL) /* first undo */ | 1986 if (curbuf->b_u_curhead == NULL) /* first undo */ |
1974 curbuf->b_u_curhead = curbuf->b_u_newhead; | 1987 curbuf->b_u_curhead = curbuf->b_u_newhead; |
1975 else if (p_ul > 0) /* multi level undo */ | 1988 else if (get_undolevel() > 0) /* multi level undo */ |
1976 /* get next undo */ | 1989 /* get next undo */ |
1977 curbuf->b_u_curhead = curbuf->b_u_curhead->uh_next.ptr; | 1990 curbuf->b_u_curhead = curbuf->b_u_curhead->uh_next.ptr; |
1978 /* nothing to undo */ | 1991 /* nothing to undo */ |
1979 if (curbuf->b_u_numhead == 0 || curbuf->b_u_curhead == NULL) | 1992 if (curbuf->b_u_numhead == 0 || curbuf->b_u_curhead == NULL) |
1980 { | 1993 { |
1991 | 2004 |
1992 u_undoredo(TRUE); | 2005 u_undoredo(TRUE); |
1993 } | 2006 } |
1994 else | 2007 else |
1995 { | 2008 { |
1996 if (curbuf->b_u_curhead == NULL || p_ul <= 0) | 2009 if (curbuf->b_u_curhead == NULL || get_undolevel() <= 0) |
1997 { | 2010 { |
1998 beep_flush(); /* nothing to redo */ | 2011 beep_flush(); /* nothing to redo */ |
1999 if (count == startcount - 1) | 2012 if (count == startcount - 1) |
2000 { | 2013 { |
2001 MSG(_("Already at newest change")); | 2014 MSG(_("Already at newest change")); |
2749 return; | 2762 return; |
2750 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) | 2763 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
2751 if (im_is_preediting()) | 2764 if (im_is_preediting()) |
2752 return; /* XIM is busy, don't break an undo sequence */ | 2765 return; /* XIM is busy, don't break an undo sequence */ |
2753 #endif | 2766 #endif |
2754 if (p_ul < 0) | 2767 if (get_undolevel() < 0) |
2755 curbuf->b_u_synced = TRUE; /* no entries, nothing to do */ | 2768 curbuf->b_u_synced = TRUE; /* no entries, nothing to do */ |
2756 else | 2769 else |
2757 { | 2770 { |
2758 u_getbot(); /* compute ue_bot of previous u_save */ | 2771 u_getbot(); /* compute ue_bot of previous u_save */ |
2759 curbuf->b_u_curhead = NULL; | 2772 curbuf->b_u_curhead = NULL; |
2909 EMSG(_("E790: undojoin is not allowed after undo")); | 2922 EMSG(_("E790: undojoin is not allowed after undo")); |
2910 return; | 2923 return; |
2911 } | 2924 } |
2912 if (!curbuf->b_u_synced) | 2925 if (!curbuf->b_u_synced) |
2913 return; /* already unsynced */ | 2926 return; /* already unsynced */ |
2914 if (p_ul < 0) | 2927 if (get_undolevel() < 0) |
2915 return; /* no entries, nothing to do */ | 2928 return; /* no entries, nothing to do */ |
2916 else | 2929 else |
2917 { | 2930 { |
2918 /* Go back to the last entry */ | 2931 /* Go back to the last entry */ |
2919 curbuf->b_u_curhead = curbuf->b_u_newhead; | 2932 curbuf->b_u_curhead = curbuf->b_u_newhead; |