annotate src/undo.c @ 2185:0c1e413c32f1 v7.2.443

updated for version 7.2.443 Problem: Using taglist() on a tag file with duplicate fields generates an internal error. (Peter Odding) Solution: Check for duplicate field names.
author Bram Moolenaar <bram@vim.org>
date Sat, 12 Jun 2010 20:12:02 +0200
parents f838615313cd
children cb94c42c0e1a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 * undo.c: multi level undo facility
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 * The saved lines are stored in a list of lists (one for each buffer):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 * b_u_oldhead------------------------------------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 * |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 * V
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 * +--------------+ +--------------+ +--------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 * b_u_newhead--->| u_header | | u_header | | u_header |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 * | uh_next------>| uh_next------>| uh_next---->NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 * NULL<--------uh_prev |<---------uh_prev |<---------uh_prev |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 * | uh_entry | | uh_entry | | uh_entry |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 * +--------|-----+ +--------|-----+ +--------|-----+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 * | | |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 * V V V
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 * +--------------+ +--------------+ +--------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 * | u_entry | | u_entry | | u_entry |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 * | ue_next | | ue_next | | ue_next |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 * +--------|-----+ +--------|-----+ +--------|-----+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 * | | |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 * V V V
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 * +--------------+ NULL NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 * | u_entry |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 * | ue_next |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 * +--------|-----+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 * |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 * V
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 * etc.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 * Each u_entry list contains the information for one undo or redo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 * curbuf->b_u_curhead points to the header of the last undo (the next redo),
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
42 * or is NULL if nothing has been undone (end of the branch).
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 *
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
44 * For keeping alternate undo/redo branches the uh_alt field is used. Thus at
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
45 * each point in the list a branch may appear for an alternate to redo. The
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
46 * uh_seq field is numbered sequentially to be able to find a newer or older
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
47 * branch.
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
48 *
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
49 * +---------------+ +---------------+
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
50 * b_u_oldhead --->| u_header | | u_header |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
51 * | uh_alt_next ---->| uh_alt_next ----> NULL
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
52 * NULL <----- uh_alt_prev |<------ uh_alt_prev |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
53 * | uh_prev | | uh_prev |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
54 * +-----|---------+ +-----|---------+
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
55 * | |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
56 * V V
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
57 * +---------------+ +---------------+
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
58 * | u_header | | u_header |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
59 * | uh_alt_next | | uh_alt_next |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
60 * b_u_newhead --->| uh_alt_prev | | uh_alt_prev |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
61 * | uh_prev | | uh_prev |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
62 * +-----|---------+ +-----|---------+
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
63 * | |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
64 * V V
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
65 * NULL +---------------+ +---------------+
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
66 * | u_header | | u_header |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
67 * | uh_alt_next ---->| uh_alt_next |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
68 * | uh_alt_prev |<------ uh_alt_prev |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
69 * | uh_prev | | uh_prev |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
70 * +-----|---------+ +-----|---------+
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
71 * | |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
72 * etc. etc.
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
73 *
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
74 *
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
75 * All data is allocated with U_ALLOC_LINE(), it will be freed as soon as the
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
76 * buffer is unloaded.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
79 /* Uncomment the next line for including the u_check() function. This warns
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
80 * for errors in the debug information. */
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
81 /* #define U_DEBUG 1 */
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
82 #define UH_MAGIC 0x18dade /* value for uh_magic when in use */
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
83 #define UE_MAGIC 0xabc123 /* value for ue_magic when in use */
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
84
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
87 /* See below: use malloc()/free() for memory management. */
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
88 #define U_USE_MALLOC 1
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
89
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
90 static void u_unch_branch __ARGS((u_header_T *uhp));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 static u_entry_T *u_get_headentry __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 static void u_getbot __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 static int u_savecommon __ARGS((linenr_T, linenr_T, linenr_T));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 static void u_doit __ARGS((int count));
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
95 static void u_undoredo __ARGS((int undo));
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
96 static void u_undo_end __ARGS((int did_undo, int absolute));
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
97 static void u_add_time __ARGS((char_u *buf, size_t buflen, time_t tt));
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
98 static void u_freeheader __ARGS((buf_T *buf, u_header_T *uhp, u_header_T **uhpp));
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
99 static void u_freebranch __ARGS((buf_T *buf, u_header_T *uhp, u_header_T **uhpp));
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
100 static void u_freeentries __ARGS((buf_T *buf, u_header_T *uhp, u_header_T **uhpp));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 static void u_freeentry __ARGS((u_entry_T *, long));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
103 #ifdef U_USE_MALLOC
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
104 # define U_FREE_LINE(ptr) vim_free(ptr)
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
105 # define U_ALLOC_LINE(size) lalloc((long_u)((size) + 1), FALSE)
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
106 #else
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
107 static void u_free_line __ARGS((char_u *ptr, int keep));
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
108 static char_u *u_alloc_line __ARGS((unsigned size));
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
109 # define U_FREE_LINE(ptr) u_free_line((ptr), FALSE)
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
110 # define U_ALLOC_LINE(size) u_alloc_line(size)
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
111 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 static char_u *u_save_line __ARGS((linenr_T));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 static long u_newcount, u_oldcount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 * When 'u' flag included in 'cpoptions', we behave like vi. Need to remember
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 * the action that "u" should do.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 static int undo_undoes = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
122 #ifdef U_DEBUG
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
123 /*
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
124 * Check the undo structures for being valid. Print a warning when something
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
125 * looks wrong.
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
126 */
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
127 static int seen_b_u_curhead;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
128 static int seen_b_u_newhead;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
129 static int header_count;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
130
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
131 static void
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
132 u_check_tree(u_header_T *uhp,
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
133 u_header_T *exp_uh_next,
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
134 u_header_T *exp_uh_alt_prev)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
135 {
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
136 u_entry_T *uep;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
137
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
138 if (uhp == NULL)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
139 return;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
140 ++header_count;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
141 if (uhp == curbuf->b_u_curhead && ++seen_b_u_curhead > 1)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
142 {
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
143 EMSG("b_u_curhead found twice (looping?)");
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
144 return;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
145 }
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
146 if (uhp == curbuf->b_u_newhead && ++seen_b_u_newhead > 1)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
147 {
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
148 EMSG("b_u_newhead found twice (looping?)");
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
149 return;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
150 }
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
151
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
152 if (uhp->uh_magic != UH_MAGIC)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
153 EMSG("uh_magic wrong (may be using freed memory)");
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
154 else
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
155 {
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
156 /* Check pointers back are correct. */
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
157 if (uhp->uh_next != exp_uh_next)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
158 {
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
159 EMSG("uh_next wrong");
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
160 smsg((char_u *)"expected: 0x%x, actual: 0x%x",
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
161 exp_uh_next, uhp->uh_next);
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
162 }
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
163 if (uhp->uh_alt_prev != exp_uh_alt_prev)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
164 {
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
165 EMSG("uh_alt_prev wrong");
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
166 smsg((char_u *)"expected: 0x%x, actual: 0x%x",
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
167 exp_uh_alt_prev, uhp->uh_alt_prev);
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
168 }
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
169
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
170 /* Check the undo tree at this header. */
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
171 for (uep = uhp->uh_entry; uep != NULL; uep = uep->ue_next)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
172 {
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
173 if (uep->ue_magic != UE_MAGIC)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
174 {
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
175 EMSG("ue_magic wrong (may be using freed memory)");
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
176 break;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
177 }
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
178 }
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
179
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
180 /* Check the next alt tree. */
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
181 u_check_tree(uhp->uh_alt_next, uhp->uh_next, uhp);
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
182
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
183 /* Check the next header in this branch. */
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
184 u_check_tree(uhp->uh_prev, uhp, NULL);
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
185 }
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
186 }
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
187
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
188 void
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
189 u_check(int newhead_may_be_NULL)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
190 {
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
191 seen_b_u_newhead = 0;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
192 seen_b_u_curhead = 0;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
193 header_count = 0;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
194
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
195 u_check_tree(curbuf->b_u_oldhead, NULL, NULL);
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
196
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
197 if (seen_b_u_newhead == 0 && curbuf->b_u_oldhead != NULL
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
198 && !(newhead_may_be_NULL && curbuf->b_u_newhead == NULL))
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
199 EMSGN("b_u_newhead invalid: 0x%x", curbuf->b_u_newhead);
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
200 if (curbuf->b_u_curhead != NULL && seen_b_u_curhead == 0)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
201 EMSGN("b_u_curhead invalid: 0x%x", curbuf->b_u_curhead);
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
202 if (header_count != curbuf->b_u_numhead)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
203 {
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
204 EMSG("b_u_numhead invalid");
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
205 smsg((char_u *)"expected: %ld, actual: %ld",
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
206 (long)header_count, (long)curbuf->b_u_numhead);
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
207 }
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
208 }
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
209 #endif
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
210
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 /*
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 179
diff changeset
212 * Save the current line for both the "u" and "U" command.
7033303ea0c0 updated for version 7.0089
vimboss
parents: 179
diff changeset
213 * Returns OK or FAIL.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 u_save_cursor()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 return (u_save((linenr_T)(curwin->w_cursor.lnum - 1),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 (linenr_T)(curwin->w_cursor.lnum + 1)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 * Save the lines between "top" and "bot" for both the "u" and "U" command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 * "top" may be 0 and bot may be curbuf->b_ml.ml_line_count + 1.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 * Returns FAIL when lines could not be saved, OK otherwise.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 u_save(top, bot)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 linenr_T top, bot;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 if (undo_off)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 if (top > curbuf->b_ml.ml_line_count ||
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 top >= bot || bot > curbuf->b_ml.ml_line_count + 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 return FALSE; /* rely on caller to do error messages */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 if (top + 2 == bot)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 u_saveline((linenr_T)(top + 1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 return (u_savecommon(top, bot, (linenr_T)0));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 /*
2181
f838615313cd updated for version 7.2.441
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
245 * Save the line "lnum" (used by ":s" and "~" command).
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 * The line is replaced, so the new bottom line is lnum + 1.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 u_savesub(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 if (undo_off)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 return (u_savecommon(lnum - 1, lnum + 1, lnum + 1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 /*
2181
f838615313cd updated for version 7.2.441
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
259 * A new line is inserted before line "lnum" (used by :s command).
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 * The line is inserted, so the new bottom line is lnum + 1.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 u_inssub(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 if (undo_off)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 return (u_savecommon(lnum - 1, lnum, lnum + 1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 /*
2181
f838615313cd updated for version 7.2.441
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
273 * Save the lines "lnum" - "lnum" + nlines (used by delete command).
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 * The lines are deleted, so the new bottom line is lnum, unless the buffer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 * becomes empty.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 u_savedel(lnum, nlines)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 long nlines;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 if (undo_off)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 return (u_savecommon(lnum - 1, lnum + nlines,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 nlines == curbuf->b_ml.ml_line_count ? 2 : lnum));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288
632
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
289 /*
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
290 * Return TRUE when undo is allowed. Otherwise give an error message and
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
291 * return FALSE.
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
292 */
912
adf6a9dcaded updated for version 7.0-038
vimboss
parents: 839
diff changeset
293 int
632
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
294 undo_allowed()
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
295 {
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
296 /* Don't allow changes when 'modifiable' is off. */
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
297 if (!curbuf->b_p_ma)
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
298 {
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
299 EMSG(_(e_modifiable));
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
300 return FALSE;
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
301 }
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
302
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
303 #ifdef HAVE_SANDBOX
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
304 /* In the sandbox it's not allowed to change the text. */
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
305 if (sandbox != 0)
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
306 {
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
307 EMSG(_(e_sandbox));
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
308 return FALSE;
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
309 }
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
310 #endif
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
311
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
312 /* Don't allow changes in the buffer while editing the cmdline. The
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
313 * caller of getcmdline() may get confused. */
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 632
diff changeset
314 if (textlock != 0)
632
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
315 {
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
316 EMSG(_(e_secure));
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
317 return FALSE;
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
318 }
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
319
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
320 return TRUE;
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
321 }
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
322
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 u_savecommon(top, bot, newbot)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 linenr_T top, bot;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 linenr_T newbot;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 {
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
328 linenr_T lnum;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
329 long i;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
330 u_header_T *uhp;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
331 u_header_T *old_curhead;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
332 u_entry_T *uep;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
333 u_entry_T *prev_uep;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
334 long size;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335
632
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
336 /* When making changes is not allowed return FAIL. It's a crude way to
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
337 * make all change commands fail. */
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
338 if (!undo_allowed())
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
341 #ifdef U_DEBUG
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
342 u_check(FALSE);
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
343 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 #ifdef FEAT_NETBEANS_INTG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346 * Netbeans defines areas that cannot be modified. Bail out here when
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 * trying to change text in a guarded area.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 */
33
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
349 if (usingNetbeans)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 {
33
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
351 if (netbeans_is_guarded(top, bot))
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
352 {
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
353 EMSG(_(e_guarded));
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
354 return FAIL;
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
355 }
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
356 if (curbuf->b_p_ro)
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
357 {
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
358 EMSG(_(e_nbreadonly));
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
359 return FAIL;
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
360 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 #ifdef FEAT_AUTOCMD
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366 * Saving text for undo means we are going to make a change. Give a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 * warning for a read-only file before making the change, so that the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368 * FileChangedRO event can replace the buffer with a read-write version
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 * (e.g., obtained from a source control system).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 change_warning(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 size = bot - top - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 * if curbuf->b_u_synced == TRUE make a new header
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 if (curbuf->b_u_synced)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381 #ifdef FEAT_JUMPLIST
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 /* Need to create new entry in b_changelist. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 curbuf->b_new_change = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
386 if (p_ul >= 0)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
387 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
388 /*
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
389 * Make a new header entry. Do this first so that we don't mess
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
390 * up the undo info when out of memory.
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
391 */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
392 uhp = (u_header_T *)U_ALLOC_LINE((unsigned)sizeof(u_header_T));
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
393 if (uhp == NULL)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
394 goto nomem;
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
395 #ifdef U_DEBUG
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
396 uhp->uh_magic = UH_MAGIC;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
397 #endif
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
398 }
766
f0d0d3d3a1e2 updated for version 7.0225
vimboss
parents: 758
diff changeset
399 else
f0d0d3d3a1e2 updated for version 7.0225
vimboss
parents: 758
diff changeset
400 uhp = NULL;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
401
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 /*
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
403 * If we undid more than we redid, move the entry lists before and
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
404 * including curbuf->b_u_curhead to an alternate branch.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 */
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
406 old_curhead = curbuf->b_u_curhead;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
407 if (old_curhead != NULL)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
408 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
409 curbuf->b_u_newhead = old_curhead->uh_next;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
410 curbuf->b_u_curhead = NULL;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
411 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 * free headers to keep the size right
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 while (curbuf->b_u_numhead > p_ul && curbuf->b_u_oldhead != NULL)
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
417 {
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
418 u_header_T *uhfree = curbuf->b_u_oldhead;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
419
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
420 if (uhfree == old_curhead)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
421 /* Can't reconnect the branch, delete all of it. */
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
422 u_freebranch(curbuf, uhfree, &old_curhead);
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
423 else if (uhfree->uh_alt_next == NULL)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
424 /* There is no branch, only free one header. */
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
425 u_freeheader(curbuf, uhfree, &old_curhead);
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
426 else
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
427 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
428 /* Free the oldest alternate branch as a whole. */
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
429 while (uhfree->uh_alt_next != NULL)
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
430 uhfree = uhfree->uh_alt_next;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
431 u_freebranch(curbuf, uhfree, &old_curhead);
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
432 }
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
433 #ifdef U_DEBUG
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
434 u_check(TRUE);
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
435 #endif
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
436 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437
766
f0d0d3d3a1e2 updated for version 7.0225
vimboss
parents: 758
diff changeset
438 if (uhp == NULL) /* no undo at all */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439 {
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
440 if (old_curhead != NULL)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
441 u_freebranch(curbuf, old_curhead, NULL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 curbuf->b_u_synced = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446 uhp->uh_prev = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447 uhp->uh_next = curbuf->b_u_newhead;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
448 uhp->uh_alt_next = old_curhead;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
449 if (old_curhead != NULL)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
450 {
1056
e6d25347de2c updated for version 7.0-182
vimboss
parents: 944
diff changeset
451 uhp->uh_alt_prev = old_curhead->uh_alt_prev;
e6d25347de2c updated for version 7.0-182
vimboss
parents: 944
diff changeset
452 if (uhp->uh_alt_prev != NULL)
e6d25347de2c updated for version 7.0-182
vimboss
parents: 944
diff changeset
453 uhp->uh_alt_prev->uh_alt_next = uhp;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
454 old_curhead->uh_alt_prev = uhp;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
455 if (curbuf->b_u_oldhead == old_curhead)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
456 curbuf->b_u_oldhead = uhp;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
457 }
1056
e6d25347de2c updated for version 7.0-182
vimboss
parents: 944
diff changeset
458 else
e6d25347de2c updated for version 7.0-182
vimboss
parents: 944
diff changeset
459 uhp->uh_alt_prev = NULL;
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
460 if (curbuf->b_u_newhead != NULL)
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
461 curbuf->b_u_newhead->uh_prev = uhp;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
462
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
463 uhp->uh_seq = ++curbuf->b_u_seq_last;
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
464 curbuf->b_u_seq_cur = uhp->uh_seq;
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
465 uhp->uh_time = time(NULL);
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
466 curbuf->b_u_seq_time = uhp->uh_time + 1;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
467
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
468 uhp->uh_walk = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 uhp->uh_entry = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470 uhp->uh_getbot_entry = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 uhp->uh_cursor = curwin->w_cursor; /* save cursor pos. for undo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473 if (virtual_active() && curwin->w_cursor.coladd > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474 uhp->uh_cursor_vcol = getviscol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476 uhp->uh_cursor_vcol = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 /* save changed and buffer empty flag for undo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 uhp->uh_flags = (curbuf->b_changed ? UH_CHANGED : 0) +
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481 ((curbuf->b_ml.ml_flags & ML_EMPTY) ? UH_EMPTYBUF : 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
483 /* save named marks and Visual marks for undo */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484 mch_memmove(uhp->uh_namedm, curbuf->b_namedm, sizeof(pos_T) * NMARKS);
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
485 #ifdef FEAT_VISUAL
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
486 uhp->uh_visual = curbuf->b_visual;
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
487 #endif
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
488
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 curbuf->b_u_newhead = uhp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 if (curbuf->b_u_oldhead == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491 curbuf->b_u_oldhead = uhp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 ++curbuf->b_u_numhead;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496 if (p_ul < 0) /* no undo at all */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 * When saving a single line, and it has been saved just before, it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 * doesn't make sense saving it again. Saves a lot of memory when
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 * making lots of changes inside the same line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503 * This is only possible if the previous change didn't increase or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 * decrease the number of lines.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505 * Check the ten last changes. More doesn't make sense and takes too
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 * long.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
508 if (size == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
509 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 uep = u_get_headentry();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 prev_uep = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512 for (i = 0; i < 10; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514 if (uep == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
516
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517 /* If lines have been inserted/deleted we give up.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
518 * Also when the line was included in a multi-line save. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519 if ((curbuf->b_u_newhead->uh_getbot_entry != uep
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
520 ? (uep->ue_top + uep->ue_size + 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521 != (uep->ue_bot == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 ? curbuf->b_ml.ml_line_count + 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523 : uep->ue_bot))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524 : uep->ue_lcount != curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525 || (uep->ue_size > 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526 && top >= uep->ue_top
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527 && top + 2 <= uep->ue_top + uep->ue_size + 1))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
530 /* If it's the same line we can skip saving it again. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531 if (uep->ue_size == 1 && uep->ue_top == top)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 if (i > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535 /* It's not the last entry: get ue_bot for the last
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536 * entry now. Following deleted/inserted lines go to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537 * the re-used entry. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
538 u_getbot();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
539 curbuf->b_u_synced = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
541 /* Move the found entry to become the last entry. The
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
542 * order of undo/redo doesn't matter for the entries
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543 * we move it over, since they don't change the line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544 * count and don't include this line. It does matter
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
545 * for the found entry if the line count is changed by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546 * the executed command. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 prev_uep->ue_next = uep->ue_next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548 uep->ue_next = curbuf->b_u_newhead->uh_entry;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
549 curbuf->b_u_newhead->uh_entry = uep;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
550 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
551
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552 /* The executed command may change the line count. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553 if (newbot != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
554 uep->ue_bot = newbot;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
555 else if (bot > curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556 uep->ue_bot = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
557 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559 uep->ue_lcount = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560 curbuf->b_u_newhead->uh_getbot_entry = uep;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
564 prev_uep = uep;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565 uep = uep->ue_next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
567 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569 /* find line number for ue_bot for previous u_save() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570 u_getbot();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 #if !defined(UNIX) && !defined(DJGPP) && !defined(WIN32) && !defined(__EMX__)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575 * With Amiga and MSDOS 16 bit we can't handle big undo's, because
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576 * then u_alloc_line would have to allocate a block larger than 32K
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578 if (size >= 8000)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579 goto nomem;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 * add lines in front of entry list
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584 */
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
585 uep = (u_entry_T *)U_ALLOC_LINE((unsigned)sizeof(u_entry_T));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586 if (uep == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587 goto nomem;
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
588 #ifdef U_DEBUG
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
589 uep->ue_magic = UE_MAGIC;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
590 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592 uep->ue_size = size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
593 uep->ue_top = top;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594 if (newbot != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595 uep->ue_bot = newbot;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 * Use 0 for ue_bot if bot is below last line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598 * Otherwise we have to compute ue_bot later.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 else if (bot > curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601 uep->ue_bot = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604 uep->ue_lcount = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605 curbuf->b_u_newhead->uh_getbot_entry = uep;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
608 if (size > 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 {
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
610 if ((uep->ue_array = (char_u **)U_ALLOC_LINE(
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611 (unsigned)(sizeof(char_u *) * size))) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
612 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613 u_freeentry(uep, 0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
614 goto nomem;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616 for (i = 0, lnum = top + 1; i < size; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617 {
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 414
diff changeset
618 fast_breakcheck();
66080ac5dab7 updated for version 7.0130
vimboss
parents: 414
diff changeset
619 if (got_int)
66080ac5dab7 updated for version 7.0130
vimboss
parents: 414
diff changeset
620 {
66080ac5dab7 updated for version 7.0130
vimboss
parents: 414
diff changeset
621 u_freeentry(uep, i);
66080ac5dab7 updated for version 7.0130
vimboss
parents: 414
diff changeset
622 return FAIL;
66080ac5dab7 updated for version 7.0130
vimboss
parents: 414
diff changeset
623 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
624 if ((uep->ue_array[i] = u_save_line(lnum++)) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
625 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626 u_freeentry(uep, i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
627 goto nomem;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
629 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
630 }
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 356
diff changeset
631 else
6c62b9b939bd updated for version 7.0093
vimboss
parents: 356
diff changeset
632 uep->ue_array = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
633 uep->ue_next = curbuf->b_u_newhead->uh_entry;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
634 curbuf->b_u_newhead->uh_entry = uep;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635 curbuf->b_u_synced = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636 undo_undoes = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
637
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
638 #ifdef U_DEBUG
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
639 u_check(FALSE);
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
640 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
641 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
642
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
643 nomem:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
644 msg_silent = 0; /* must display the prompt */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
645 if (ask_yesno((char_u *)_("No undo possible; continue anyway"), TRUE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
646 == 'y')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
647 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
648 undo_off = TRUE; /* will be reset when character typed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
649 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
650 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
651 do_outofmem_msg((long_u)0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
652 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
653 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
654
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
655 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
656 * If 'cpoptions' contains 'u': Undo the previous undo or redo (vi compatible).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
657 * If 'cpoptions' does not contain 'u': Always undo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
658 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
659 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
660 u_undo(count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
661 int count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
662 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
663 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
664 * If we get an undo command while executing a macro, we behave like the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
665 * original vi. If this happens twice in one macro the result will not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
666 * be compatible.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
667 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
668 if (curbuf->b_u_synced == FALSE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
669 {
825
6675076019ae updated for version 7.0d
vimboss
parents: 810
diff changeset
670 u_sync(TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
671 count = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
672 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
673
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
674 if (vim_strchr(p_cpo, CPO_UNDO) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
675 undo_undoes = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
676 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
677 undo_undoes = !undo_undoes;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
678 u_doit(count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
679 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
680
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
681 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
682 * If 'cpoptions' contains 'u': Repeat the previous undo or redo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
683 * If 'cpoptions' does not contain 'u': Always redo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
684 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
685 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
686 u_redo(count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
687 int count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
688 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
689 if (vim_strchr(p_cpo, CPO_UNDO) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
690 undo_undoes = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
691 u_doit(count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
692 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
693
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
694 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
695 * Undo or redo, depending on 'undo_undoes', 'count' times.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
696 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
697 static void
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
698 u_doit(startcount)
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
699 int startcount;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
700 {
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
701 int count = startcount;
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
702
632
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
703 if (!undo_allowed())
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
704 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
705
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
706 u_newcount = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
707 u_oldcount = 0;
179
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 168
diff changeset
708 if (curbuf->b_ml.ml_flags & ML_EMPTY)
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 168
diff changeset
709 u_oldcount = -1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
710 while (count--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
711 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
712 if (undo_undoes)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
713 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
714 if (curbuf->b_u_curhead == NULL) /* first undo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
715 curbuf->b_u_curhead = curbuf->b_u_newhead;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
716 else if (p_ul > 0) /* multi level undo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
717 /* get next undo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
718 curbuf->b_u_curhead = curbuf->b_u_curhead->uh_next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
719 /* nothing to undo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
720 if (curbuf->b_u_numhead == 0 || curbuf->b_u_curhead == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
721 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
722 /* stick curbuf->b_u_curhead at end */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
723 curbuf->b_u_curhead = curbuf->b_u_oldhead;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
724 beep_flush();
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
725 if (count == startcount - 1)
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
726 {
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
727 MSG(_("Already at oldest change"));
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
728 return;
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
729 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
730 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
731 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
732
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
733 u_undoredo(TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
734 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
735 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
736 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
737 if (curbuf->b_u_curhead == NULL || p_ul <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
738 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
739 beep_flush(); /* nothing to redo */
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
740 if (count == startcount - 1)
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
741 {
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
742 MSG(_("Already at newest change"));
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
743 return;
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
744 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
745 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
746 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
747
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
748 u_undoredo(FALSE);
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
749
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
750 /* Advance for next redo. Set "newhead" when at the end of the
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
751 * redoable changes. */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
752 if (curbuf->b_u_curhead->uh_prev == NULL)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
753 curbuf->b_u_newhead = curbuf->b_u_curhead;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
754 curbuf->b_u_curhead = curbuf->b_u_curhead->uh_prev;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
755 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
756 }
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
757 u_undo_end(undo_undoes, FALSE);
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
758 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
759
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
760 static int lastmark = 0;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
761
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
762 /*
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
763 * Undo or redo over the timeline.
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
764 * When "step" is negative go back in time, otherwise goes forward in time.
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
765 * When "sec" is FALSE make "step" steps, when "sec" is TRUE use "step" as
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
766 * seconds.
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
767 * When "absolute" is TRUE use "step" as the sequence number to jump to.
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
768 * "sec" must be FALSE then.
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
769 */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
770 void
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
771 undo_time(step, sec, absolute)
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
772 long step;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
773 int sec;
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
774 int absolute;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
775 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
776 long target;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
777 long closest;
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
778 long closest_start;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
779 long closest_seq = 0;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
780 long val;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
781 u_header_T *uhp;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
782 u_header_T *last;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
783 int mark;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
784 int nomark;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
785 int round;
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
786 int dosec = sec;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
787 int above = FALSE;
794
f19994020dad updated for version 7.0231
vimboss
parents: 777
diff changeset
788 int did_undo = TRUE;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
789
766
f0d0d3d3a1e2 updated for version 7.0225
vimboss
parents: 758
diff changeset
790 /* First make sure the current undoable change is synced. */
f0d0d3d3a1e2 updated for version 7.0225
vimboss
parents: 758
diff changeset
791 if (curbuf->b_u_synced == FALSE)
825
6675076019ae updated for version 7.0d
vimboss
parents: 810
diff changeset
792 u_sync(TRUE);
766
f0d0d3d3a1e2 updated for version 7.0225
vimboss
parents: 758
diff changeset
793
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
794 u_newcount = 0;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
795 u_oldcount = 0;
179
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 168
diff changeset
796 if (curbuf->b_ml.ml_flags & ML_EMPTY)
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
797 u_oldcount = -1;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
798
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
799 /* "target" is the node below which we want to be.
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
800 * Init "closest" to a value we can't reach. */
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
801 if (absolute)
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
802 {
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
803 target = step;
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
804 closest = -1;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
805 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
806 else
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
807 {
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
808 /* When doing computations with time_t subtract starttime, because
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
809 * time_t converted to a long may result in a wrong number. */
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
810 if (sec)
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
811 target = (long)(curbuf->b_u_seq_time - starttime) + step;
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
812 else
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
813 target = curbuf->b_u_seq_cur + step;
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
814 if (step < 0)
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
815 {
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
816 if (target < 0)
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
817 target = 0;
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
818 closest = -1;
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
819 }
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
820 else
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
821 {
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
822 if (sec)
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
823 closest = (long)(time(NULL) - starttime + 1);
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
824 else
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
825 closest = curbuf->b_u_seq_last + 2;
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
826 if (target >= closest)
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
827 target = closest - 1;
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
828 }
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
829 }
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
830 closest_start = closest;
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
831 closest_seq = curbuf->b_u_seq_cur;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
832
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
833 /*
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
834 * May do this twice:
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
835 * 1. Search for "target", update "closest" to the best match found.
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
836 * 2. If "target" not found search for "closest".
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
837 *
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
838 * When using the closest time we use the sequence number in the second
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
839 * round, because there may be several entries with the same time.
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
840 */
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
841 for (round = 1; round <= 2; ++round)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
842 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
843 /* Find the path from the current state to where we want to go. The
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
844 * desired state can be anywhere in the undo tree, need to go all over
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
845 * it. We put "nomark" in uh_walk where we have been without success,
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
846 * "mark" where it could possibly be. */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
847 mark = ++lastmark;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
848 nomark = ++lastmark;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
849
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
850 if (curbuf->b_u_curhead == NULL) /* at leaf of the tree */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
851 uhp = curbuf->b_u_newhead;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
852 else
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
853 uhp = curbuf->b_u_curhead;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
854
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
855 while (uhp != NULL)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
856 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
857 uhp->uh_walk = mark;
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
858 val = (long)(dosec ? (uhp->uh_time - starttime) : uhp->uh_seq);
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
859
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
860 if (round == 1)
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
861 {
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
862 /* Remember the header that is closest to the target.
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
863 * It must be at least in the right direction (checked with
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
864 * "b_u_seq_cur"). When the timestamp is equal find the
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
865 * highest/lowest sequence number. */
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
866 if ((step < 0 ? uhp->uh_seq <= curbuf->b_u_seq_cur
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
867 : uhp->uh_seq > curbuf->b_u_seq_cur)
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
868 && ((dosec && val == closest)
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
869 ? (step < 0
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
870 ? uhp->uh_seq < closest_seq
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
871 : uhp->uh_seq > closest_seq)
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
872 : closest == closest_start
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
873 || (val > target
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
874 ? (closest > target
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
875 ? val - target <= closest - target
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
876 : val - target <= target - closest)
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
877 : (closest > target
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
878 ? target - val <= closest - target
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
879 : target - val <= target - closest))))
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
880 {
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
881 closest = val;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
882 closest_seq = uhp->uh_seq;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
883 }
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
884 }
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
885
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
886 /* Quit searching when we found a match. But when searching for a
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
887 * time we need to continue looking for the best uh_seq. */
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
888 if (target == val && !dosec)
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
889 break;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
890
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
891 /* go down in the tree if we haven't been there */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
892 if (uhp->uh_prev != NULL && uhp->uh_prev->uh_walk != nomark
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
893 && uhp->uh_prev->uh_walk != mark)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
894 uhp = uhp->uh_prev;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
895
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
896 /* go to alternate branch if we haven't been there */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
897 else if (uhp->uh_alt_next != NULL
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
898 && uhp->uh_alt_next->uh_walk != nomark
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
899 && uhp->uh_alt_next->uh_walk != mark)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
900 uhp = uhp->uh_alt_next;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
901
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
902 /* go up in the tree if we haven't been there and we are at the
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
903 * start of alternate branches */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
904 else if (uhp->uh_next != NULL && uhp->uh_alt_prev == NULL
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
905 && uhp->uh_next->uh_walk != nomark
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
906 && uhp->uh_next->uh_walk != mark)
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
907 {
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
908 /* If still at the start we don't go through this change. */
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
909 if (uhp == curbuf->b_u_curhead)
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
910 uhp->uh_walk = nomark;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
911 uhp = uhp->uh_next;
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
912 }
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
913
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
914 else
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
915 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
916 /* need to backtrack; mark this node as useless */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
917 uhp->uh_walk = nomark;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
918 if (uhp->uh_alt_prev != NULL)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
919 uhp = uhp->uh_alt_prev;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
920 else
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
921 uhp = uhp->uh_next;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
922 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
923 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
924
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
925 if (uhp != NULL) /* found it */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
926 break;
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
927
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
928 if (absolute)
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
929 {
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
930 EMSGN(_("Undo number %ld not found"), step);
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
931 return;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
932 }
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
933
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
934 if (closest == closest_start)
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
935 {
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
936 if (step < 0)
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
937 MSG(_("Already at oldest change"));
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
938 else
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
939 MSG(_("Already at newest change"));
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
940 return;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
941 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
942
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
943 target = closest_seq;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
944 dosec = FALSE;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
945 if (step < 0)
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
946 above = TRUE; /* stop above the header */
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
947 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
948
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
949 /* If we found it: Follow the path to go to where we want to be. */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
950 if (uhp != NULL)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
951 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
952 /*
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
953 * First go up the tree as much as needed.
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
954 */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
955 for (;;)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
956 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
957 uhp = curbuf->b_u_curhead;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
958 if (uhp == NULL)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
959 uhp = curbuf->b_u_newhead;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
960 else
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
961 uhp = uhp->uh_next;
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
962 if (uhp == NULL || uhp->uh_walk != mark
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
963 || (uhp->uh_seq == target && !above))
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
964 break;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
965 curbuf->b_u_curhead = uhp;
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
966 u_undoredo(TRUE);
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
967 uhp->uh_walk = nomark; /* don't go back down here */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
968 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
969
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
970 /*
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
971 * And now go down the tree (redo), branching off where needed.
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
972 */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
973 uhp = curbuf->b_u_curhead;
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
974 while (uhp != NULL)
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
975 {
1056
e6d25347de2c updated for version 7.0-182
vimboss
parents: 944
diff changeset
976 /* Go back to the first branch with a mark. */
e6d25347de2c updated for version 7.0-182
vimboss
parents: 944
diff changeset
977 while (uhp->uh_alt_prev != NULL
e6d25347de2c updated for version 7.0-182
vimboss
parents: 944
diff changeset
978 && uhp->uh_alt_prev->uh_walk == mark)
e6d25347de2c updated for version 7.0-182
vimboss
parents: 944
diff changeset
979 uhp = uhp->uh_alt_prev;
e6d25347de2c updated for version 7.0-182
vimboss
parents: 944
diff changeset
980
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
981 /* Find the last branch with a mark, that's the one. */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
982 last = uhp;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
983 while (last->uh_alt_next != NULL
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
984 && last->uh_alt_next->uh_walk == mark)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
985 last = last->uh_alt_next;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
986 if (last != uhp)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
987 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
988 /* Make the used branch the first entry in the list of
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
989 * alternatives to make "u" and CTRL-R take this branch. */
1056
e6d25347de2c updated for version 7.0-182
vimboss
parents: 944
diff changeset
990 while (uhp->uh_alt_prev != NULL)
e6d25347de2c updated for version 7.0-182
vimboss
parents: 944
diff changeset
991 uhp = uhp->uh_alt_prev;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
992 if (last->uh_alt_next != NULL)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
993 last->uh_alt_next->uh_alt_prev = last->uh_alt_prev;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
994 last->uh_alt_prev->uh_alt_next = last->uh_alt_next;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
995 last->uh_alt_prev = NULL;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
996 last->uh_alt_next = uhp;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
997 uhp->uh_alt_prev = last;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
998
2181
f838615313cd updated for version 7.2.441
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
999 if (curbuf->b_u_oldhead == uhp)
f838615313cd updated for version 7.2.441
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
1000 curbuf->b_u_oldhead = last;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1001 uhp = last;
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1002 if (uhp->uh_next != NULL)
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1003 uhp->uh_next->uh_prev = uhp;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1004 }
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1005 curbuf->b_u_curhead = uhp;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1006
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1007 if (uhp->uh_walk != mark)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1008 break; /* must have reached the target */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1009
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1010 /* Stop when going backwards in time and didn't find the exact
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1011 * header we were looking for. */
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1012 if (uhp->uh_seq == target && above)
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
1013 {
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
1014 curbuf->b_u_seq_cur = target - 1;
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1015 break;
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
1016 }
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1017
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1018 u_undoredo(FALSE);
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1019
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1020 /* Advance "curhead" to below the header we last used. If it
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1021 * becomes NULL then we need to set "newhead" to this leaf. */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1022 if (uhp->uh_prev == NULL)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1023 curbuf->b_u_newhead = uhp;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1024 curbuf->b_u_curhead = uhp->uh_prev;
794
f19994020dad updated for version 7.0231
vimboss
parents: 777
diff changeset
1025 did_undo = FALSE;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1026
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1027 if (uhp->uh_seq == target) /* found it! */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1028 break;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1029
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1030 uhp = uhp->uh_prev;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1031 if (uhp == NULL || uhp->uh_walk != mark)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1032 {
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1033 /* Need to redo more but can't find it... */
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1034 EMSG2(_(e_intern2), "undo_time()");
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1035 break;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1036 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1037 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1038 }
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
1039 u_undo_end(did_undo, absolute);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1040 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1041
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1042 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1043 * u_undoredo: common code for undo and redo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1044 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1045 * The lines in the file are replaced by the lines in the entry list at
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1046 * curbuf->b_u_curhead. The replaced lines in the file are saved in the entry
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1047 * list for the next undo/redo.
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1048 *
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1049 * When "undo" is TRUE we go up in the tree, when FALSE we go down.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1050 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1051 static void
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1052 u_undoredo(undo)
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1053 int undo;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1054 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1055 char_u **newarray = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1056 linenr_T oldsize;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1057 linenr_T newsize;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1058 linenr_T top, bot;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1059 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1060 linenr_T newlnum = MAXLNUM;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1061 long i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1062 u_entry_T *uep, *nuep;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1063 u_entry_T *newlist = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1064 int old_flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1065 int new_flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1066 pos_T namedm[NMARKS];
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
1067 #ifdef FEAT_VISUAL
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
1068 visualinfo_T visualinfo;
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
1069 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1070 int empty_buffer; /* buffer became empty */
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1071 u_header_T *curhead = curbuf->b_u_curhead;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1072
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
1073 #ifdef U_DEBUG
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
1074 u_check(FALSE);
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
1075 #endif
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1076 old_flags = curhead->uh_flags;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1077 new_flags = (curbuf->b_changed ? UH_CHANGED : 0) +
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1078 ((curbuf->b_ml.ml_flags & ML_EMPTY) ? UH_EMPTYBUF : 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1079 setpcmark();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1080
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1081 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1082 * save marks before undo/redo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1083 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1084 mch_memmove(namedm, curbuf->b_namedm, sizeof(pos_T) * NMARKS);
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
1085 #ifdef FEAT_VISUAL
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
1086 visualinfo = curbuf->b_visual;
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
1087 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1088 curbuf->b_op_start.lnum = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1089 curbuf->b_op_start.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1090 curbuf->b_op_end.lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1091 curbuf->b_op_end.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1092
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1093 for (uep = curhead->uh_entry; uep != NULL; uep = nuep)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1094 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1095 top = uep->ue_top;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1096 bot = uep->ue_bot;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1097 if (bot == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1098 bot = curbuf->b_ml.ml_line_count + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1099 if (top > curbuf->b_ml.ml_line_count || top >= bot
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1100 || bot > curbuf->b_ml.ml_line_count + 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1101 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1102 EMSG(_("E438: u_undo: line numbers wrong"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1103 changed(); /* don't want UNCHANGED now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1104 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1105 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1106
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1107 oldsize = bot - top - 1; /* number of lines before undo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1108 newsize = uep->ue_size; /* number of lines after undo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1109
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1110 if (top < newlnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1111 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1112 /* If the saved cursor is somewhere in this undo block, move it to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1113 * the remembered position. Makes "gwap" put the cursor back
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1114 * where it was. */
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1115 lnum = curhead->uh_cursor.lnum;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1116 if (lnum >= top && lnum <= top + newsize + 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1117 {
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1118 curwin->w_cursor = curhead->uh_cursor;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1119 newlnum = curwin->w_cursor.lnum - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1120 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1121 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1122 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1123 /* Use the first line that actually changed. Avoids that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1124 * undoing auto-formatting puts the cursor in the previous
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1125 * line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1126 for (i = 0; i < newsize && i < oldsize; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1127 if (STRCMP(uep->ue_array[i], ml_get(top + 1 + i)) != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1128 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1129 if (i == newsize && newlnum == MAXLNUM && uep->ue_next == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1130 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1131 newlnum = top;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1132 curwin->w_cursor.lnum = newlnum + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1133 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1134 else if (i < newsize)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1135 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1136 newlnum = top + i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1137 curwin->w_cursor.lnum = newlnum + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1138 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1139 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1140 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1141
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1142 empty_buffer = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1143
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1144 /* delete the lines between top and bot and save them in newarray */
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1145 if (oldsize > 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1146 {
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1147 if ((newarray = (char_u **)U_ALLOC_LINE(
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1148 (unsigned)(sizeof(char_u *) * oldsize))) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1149 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1150 do_outofmem_msg((long_u)(sizeof(char_u *) * oldsize));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1151 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1152 * We have messed up the entry list, repair is impossible.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1153 * we have to free the rest of the list.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1154 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1155 while (uep != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1156 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1157 nuep = uep->ue_next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1158 u_freeentry(uep, uep->ue_size);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1159 uep = nuep;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1160 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1161 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1162 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1163 /* delete backwards, it goes faster in most cases */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1164 for (lnum = bot - 1, i = oldsize; --i >= 0; --lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1165 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1166 /* what can we do when we run out of memory? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1167 if ((newarray[i] = u_save_line(lnum)) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1168 do_outofmem_msg((long_u)0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1169 /* remember we deleted the last line in the buffer, and a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1170 * dummy empty line will be inserted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1171 if (curbuf->b_ml.ml_line_count == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1172 empty_buffer = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1173 ml_delete(lnum, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1174 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1175 }
414
8ab9c77240d4 updated for version 7.0108
vimboss
parents: 407
diff changeset
1176 else
8ab9c77240d4 updated for version 7.0108
vimboss
parents: 407
diff changeset
1177 newarray = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1178
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1179 /* insert the lines in u_array between top and bot */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1180 if (newsize)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1181 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1182 for (lnum = top, i = 0; i < newsize; ++i, ++lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1183 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1184 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1185 * If the file is empty, there is an empty line 1 that we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1186 * should get rid of, by replacing it with the new line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1187 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1188 if (empty_buffer && lnum == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1189 ml_replace((linenr_T)1, uep->ue_array[i], TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1190 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1191 ml_append(lnum, uep->ue_array[i], (colnr_T)0, FALSE);
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1192 U_FREE_LINE(uep->ue_array[i]);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1193 }
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1194 U_FREE_LINE((char_u *)uep->ue_array);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1195 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1196
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1197 /* adjust marks */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1198 if (oldsize != newsize)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1199 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1200 mark_adjust(top + 1, top + oldsize, (long)MAXLNUM,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1201 (long)newsize - (long)oldsize);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1202 if (curbuf->b_op_start.lnum > top + oldsize)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1203 curbuf->b_op_start.lnum += newsize - oldsize;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1204 if (curbuf->b_op_end.lnum > top + oldsize)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1205 curbuf->b_op_end.lnum += newsize - oldsize;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1206 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1207
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1208 changed_lines(top + 1, 0, bot, newsize - oldsize);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1209
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1210 /* set '[ and '] mark */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1211 if (top + 1 < curbuf->b_op_start.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1212 curbuf->b_op_start.lnum = top + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1213 if (newsize == 0 && top + 1 > curbuf->b_op_end.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1214 curbuf->b_op_end.lnum = top + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1215 else if (top + newsize > curbuf->b_op_end.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1216 curbuf->b_op_end.lnum = top + newsize;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1217
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1218 u_newcount += newsize;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1219 u_oldcount += oldsize;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1220 uep->ue_size = oldsize;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1221 uep->ue_array = newarray;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1222 uep->ue_bot = top + newsize + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1223
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1224 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1225 * insert this entry in front of the new entry list
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1226 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1227 nuep = uep->ue_next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1228 uep->ue_next = newlist;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1229 newlist = uep;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1230 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1231
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1232 curhead->uh_entry = newlist;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1233 curhead->uh_flags = new_flags;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1234 if ((old_flags & UH_EMPTYBUF) && bufempty())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1235 curbuf->b_ml.ml_flags |= ML_EMPTY;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1236 if (old_flags & UH_CHANGED)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1237 changed();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1238 else
33
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
1239 #ifdef FEAT_NETBEANS_INTG
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
1240 /* per netbeans undo rules, keep it as modified */
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
1241 if (!isNetbeansModified(curbuf))
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
1242 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1243 unchanged(curbuf, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1244
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1245 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1246 * restore marks from before undo/redo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1247 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1248 for (i = 0; i < NMARKS; ++i)
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1249 if (curhead->uh_namedm[i].lnum != 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1250 {
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1251 curbuf->b_namedm[i] = curhead->uh_namedm[i];
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1252 curhead->uh_namedm[i] = namedm[i];
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1253 }
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
1254 #ifdef FEAT_VISUAL
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1255 if (curhead->uh_visual.vi_start.lnum != 0)
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
1256 {
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1257 curbuf->b_visual = curhead->uh_visual;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1258 curhead->uh_visual = visualinfo;
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
1259 }
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
1260 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1261
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1262 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1263 * If the cursor is only off by one line, put it at the same position as
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1264 * before starting the change (for the "o" command).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1265 * Otherwise the cursor should go to the first undone line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1266 */
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1267 if (curhead->uh_cursor.lnum + 1 == curwin->w_cursor.lnum
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1268 && curwin->w_cursor.lnum > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1269 --curwin->w_cursor.lnum;
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1270 if (curhead->uh_cursor.lnum == curwin->w_cursor.lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1271 {
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1272 curwin->w_cursor.col = curhead->uh_cursor.col;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1273 #ifdef FEAT_VIRTUALEDIT
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1274 if (virtual_active() && curhead->uh_cursor_vcol >= 0)
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1275 coladvance((colnr_T)curhead->uh_cursor_vcol);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1276 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1277 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1278 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1279 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1280 else if (curwin->w_cursor.lnum <= curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1281 beginline(BL_SOL | BL_FIX);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1282 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1283 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1284 /* We get here with the current cursor line being past the end (eg
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1285 * after adding lines at the end of the file, and then undoing it).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1286 * check_cursor() will move the cursor to the last line. Move it to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1287 * the first column here. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1288 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1289 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1290 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1291 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1292 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1293
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1294 /* Make sure the cursor is on an existing line and column. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1295 check_cursor();
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1296
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1297 /* Remember where we are for "g-" and ":earlier 10s". */
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1298 curbuf->b_u_seq_cur = curhead->uh_seq;
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1299 if (undo)
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1300 /* We are below the previous undo. However, to make ":earlier 1s"
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1301 * work we compute this as being just above the just undone change. */
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1302 --curbuf->b_u_seq_cur;
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1303
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1304 /* The timestamp can be the same for multiple changes, just use the one of
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1305 * the undone/redone change. */
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1306 curbuf->b_u_seq_time = curhead->uh_time;
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
1307 #ifdef U_DEBUG
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
1308 u_check(FALSE);
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
1309 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1310 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1311
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1312 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1313 * If we deleted or added lines, report the number of less/more lines.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1314 * Otherwise, report the number of changes (this may be incorrect
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1315 * in some cases, but it's better than nothing).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1316 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1317 static void
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
1318 u_undo_end(did_undo, absolute)
794
f19994020dad updated for version 7.0231
vimboss
parents: 777
diff changeset
1319 int did_undo; /* just did an undo */
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
1320 int absolute; /* used ":undo N" */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1321 {
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 912
diff changeset
1322 char *msgstr;
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1323 u_header_T *uhp;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1324 char_u msgbuf[80];
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1325
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1326 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1327 if ((fdo_flags & FDO_UNDO) && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1328 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1329 #endif
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1330
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1331 if (global_busy /* no messages now, wait until global is finished */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1332 || !messaging()) /* 'lazyredraw' set, don't do messages now */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1333 return;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1334
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1335 if (curbuf->b_ml.ml_flags & ML_EMPTY)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1336 --u_newcount;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1337
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1338 u_oldcount -= u_newcount;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1339 if (u_oldcount == -1)
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 912
diff changeset
1340 msgstr = N_("more line");
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1341 else if (u_oldcount < 0)
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 912
diff changeset
1342 msgstr = N_("more lines");
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1343 else if (u_oldcount == 1)
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 912
diff changeset
1344 msgstr = N_("line less");
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1345 else if (u_oldcount > 1)
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 912
diff changeset
1346 msgstr = N_("fewer lines");
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1347 else
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1348 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1349 u_oldcount = u_newcount;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1350 if (u_newcount == 1)
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 912
diff changeset
1351 msgstr = N_("change");
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1352 else
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 912
diff changeset
1353 msgstr = N_("changes");
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1354 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1355
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1356 if (curbuf->b_u_curhead != NULL)
794
f19994020dad updated for version 7.0231
vimboss
parents: 777
diff changeset
1357 {
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
1358 /* For ":undo N" we prefer a "after #N" message. */
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
1359 if (absolute && curbuf->b_u_curhead->uh_next != NULL)
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
1360 {
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
1361 uhp = curbuf->b_u_curhead->uh_next;
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
1362 did_undo = FALSE;
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
1363 }
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
1364 else if (did_undo)
794
f19994020dad updated for version 7.0231
vimboss
parents: 777
diff changeset
1365 uhp = curbuf->b_u_curhead;
f19994020dad updated for version 7.0231
vimboss
parents: 777
diff changeset
1366 else
f19994020dad updated for version 7.0231
vimboss
parents: 777
diff changeset
1367 uhp = curbuf->b_u_curhead->uh_next;
f19994020dad updated for version 7.0231
vimboss
parents: 777
diff changeset
1368 }
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1369 else
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1370 uhp = curbuf->b_u_newhead;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1371
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1372 if (uhp == NULL)
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1373 *msgbuf = NUL;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1374 else
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1375 u_add_time(msgbuf, sizeof(msgbuf), uhp->uh_time);
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1376
794
f19994020dad updated for version 7.0231
vimboss
parents: 777
diff changeset
1377 smsg((char_u *)_("%ld %s; %s #%ld %s"),
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1378 u_oldcount < 0 ? -u_oldcount : u_oldcount,
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 912
diff changeset
1379 _(msgstr),
794
f19994020dad updated for version 7.0231
vimboss
parents: 777
diff changeset
1380 did_undo ? _("before") : _("after"),
f19994020dad updated for version 7.0231
vimboss
parents: 777
diff changeset
1381 uhp == NULL ? 0L : uhp->uh_seq,
f19994020dad updated for version 7.0231
vimboss
parents: 777
diff changeset
1382 msgbuf);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1383 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1384
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1385 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1386 * u_sync: stop adding to the current entry list
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1387 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1388 void
825
6675076019ae updated for version 7.0d
vimboss
parents: 810
diff changeset
1389 u_sync(force)
6675076019ae updated for version 7.0d
vimboss
parents: 810
diff changeset
1390 int force; /* Also sync when no_u_sync is set. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1391 {
825
6675076019ae updated for version 7.0d
vimboss
parents: 810
diff changeset
1392 /* Skip it when already synced or syncing is disabled. */
6675076019ae updated for version 7.0d
vimboss
parents: 810
diff changeset
1393 if (curbuf->b_u_synced || (!force && no_u_sync > 0))
6675076019ae updated for version 7.0d
vimboss
parents: 810
diff changeset
1394 return;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1395 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1396 if (im_is_preediting())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1397 return; /* XIM is busy, don't break an undo sequence */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1398 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1399 if (p_ul < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1400 curbuf->b_u_synced = TRUE; /* no entries, nothing to do */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1401 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1402 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1403 u_getbot(); /* compute ue_bot of previous u_save */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1404 curbuf->b_u_curhead = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1405 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1406 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1407
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1408 /*
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1409 * ":undolist": List the leafs of the undo tree
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1410 */
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1411 void
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1412 ex_undolist(eap)
2181
f838615313cd updated for version 7.2.441
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
1413 exarg_T *eap UNUSED;
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1414 {
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1415 garray_T ga;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1416 u_header_T *uhp;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1417 int mark;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1418 int nomark;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1419 int changes = 1;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1420 int i;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1421
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1422 /*
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1423 * 1: walk the tree to find all leafs, put the info in "ga".
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1424 * 2: sort the lines
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1425 * 3: display the list
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1426 */
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1427 mark = ++lastmark;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1428 nomark = ++lastmark;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1429 ga_init2(&ga, (int)sizeof(char *), 20);
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1430
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1431 uhp = curbuf->b_u_oldhead;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1432 while (uhp != NULL)
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1433 {
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1434 if (uhp->uh_prev == NULL && uhp->uh_walk != nomark
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1435 && uhp->uh_walk != mark)
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1436 {
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1437 if (ga_grow(&ga, 1) == FAIL)
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1438 break;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1439 vim_snprintf((char *)IObuff, IOSIZE, "%6ld %7ld ",
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1440 uhp->uh_seq, changes);
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1441 u_add_time(IObuff + STRLEN(IObuff), IOSIZE - STRLEN(IObuff),
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1442 uhp->uh_time);
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1443 ((char_u **)(ga.ga_data))[ga.ga_len++] = vim_strsave(IObuff);
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1444 }
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1445
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1446 uhp->uh_walk = mark;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1447
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1448 /* go down in the tree if we haven't been there */
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1449 if (uhp->uh_prev != NULL && uhp->uh_prev->uh_walk != nomark
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1450 && uhp->uh_prev->uh_walk != mark)
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1451 {
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1452 uhp = uhp->uh_prev;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1453 ++changes;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1454 }
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1455
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1456 /* go to alternate branch if we haven't been there */
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1457 else if (uhp->uh_alt_next != NULL
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1458 && uhp->uh_alt_next->uh_walk != nomark
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1459 && uhp->uh_alt_next->uh_walk != mark)
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1460 uhp = uhp->uh_alt_next;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1461
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1462 /* go up in the tree if we haven't been there and we are at the
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1463 * start of alternate branches */
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1464 else if (uhp->uh_next != NULL && uhp->uh_alt_prev == NULL
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1465 && uhp->uh_next->uh_walk != nomark
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1466 && uhp->uh_next->uh_walk != mark)
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1467 {
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1468 uhp = uhp->uh_next;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1469 --changes;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1470 }
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1471
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1472 else
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1473 {
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1474 /* need to backtrack; mark this node as done */
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1475 uhp->uh_walk = nomark;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1476 if (uhp->uh_alt_prev != NULL)
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1477 uhp = uhp->uh_alt_prev;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1478 else
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1479 {
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1480 uhp = uhp->uh_next;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1481 --changes;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1482 }
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1483 }
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1484 }
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1485
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1486 if (ga.ga_len == 0)
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1487 MSG(_("Nothing to undo"));
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1488 else
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1489 {
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1490 sort_strings((char_u **)ga.ga_data, ga.ga_len);
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1491
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1492 msg_start();
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1493 msg_puts_attr((char_u *)_("number changes time"), hl_attr(HLF_T));
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1494 for (i = 0; i < ga.ga_len && !got_int; ++i)
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1495 {
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1496 msg_putchar('\n');
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1497 if (got_int)
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1498 break;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1499 msg_puts(((char_u **)ga.ga_data)[i]);
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1500 }
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1501 msg_end();
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1502
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1503 ga_clear_strings(&ga);
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1504 }
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1505 }
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1506
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1507 /*
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1508 * Put the timestamp of an undo header in "buf[buflen]" in a nice format.
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1509 */
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1510 static void
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1511 u_add_time(buf, buflen, tt)
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1512 char_u *buf;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1513 size_t buflen;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1514 time_t tt;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1515 {
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1516 #ifdef HAVE_STRFTIME
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1517 struct tm *curtime;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1518
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1519 if (time(NULL) - tt >= 100)
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1520 {
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1521 curtime = localtime(&tt);
810
9f345c48220b updated for version 7.0c
vimboss
parents: 798
diff changeset
1522 (void)strftime((char *)buf, buflen, "%H:%M:%S", curtime);
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1523 }
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1524 else
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1525 #endif
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 825
diff changeset
1526 vim_snprintf((char *)buf, buflen, _("%ld seconds ago"),
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1527 (long)(time(NULL) - tt));
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1528 }
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1529
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1530 /*
697
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
1531 * ":undojoin": continue adding to the last entry list
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
1532 */
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
1533 void
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
1534 ex_undojoin(eap)
2181
f838615313cd updated for version 7.2.441
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
1535 exarg_T *eap UNUSED;
697
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
1536 {
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 835
diff changeset
1537 if (curbuf->b_u_newhead == NULL)
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 835
diff changeset
1538 return; /* nothing changed before */
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 835
diff changeset
1539 if (curbuf->b_u_curhead != NULL)
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 835
diff changeset
1540 {
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 835
diff changeset
1541 EMSG(_("E790: undojoin is not allowed after undo"));
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 835
diff changeset
1542 return;
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 835
diff changeset
1543 }
697
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
1544 if (!curbuf->b_u_synced)
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
1545 return; /* already unsynced */
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
1546 if (p_ul < 0)
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
1547 return; /* no entries, nothing to do */
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
1548 else
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
1549 {
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
1550 /* Go back to the last entry */
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
1551 curbuf->b_u_curhead = curbuf->b_u_newhead;
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
1552 curbuf->b_u_synced = FALSE; /* no entries, nothing to do */
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
1553 }
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
1554 }
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
1555
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
1556 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1557 * Called after writing the file and setting b_changed to FALSE.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1558 * Now an undo means that the buffer is modified.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1559 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1560 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1561 u_unchanged(buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1562 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1563 {
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1564 u_unch_branch(buf->b_u_oldhead);
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1565 buf->b_did_warn = FALSE;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1566 }
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1567
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1568 static void
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1569 u_unch_branch(uhp)
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1570 u_header_T *uhp;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1571 {
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1572 u_header_T *uh;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1573
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1574 for (uh = uhp; uh != NULL; uh = uh->uh_prev)
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1575 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1576 uh->uh_flags |= UH_CHANGED;
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1577 if (uh->uh_alt_next != NULL)
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1578 u_unch_branch(uh->uh_alt_next); /* recursive */
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1579 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1580 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1581
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1582 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1583 * Get pointer to last added entry.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1584 * If it's not valid, give an error message and return NULL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1585 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1586 static u_entry_T *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1587 u_get_headentry()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1588 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1589 if (curbuf->b_u_newhead == NULL || curbuf->b_u_newhead->uh_entry == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1590 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1591 EMSG(_("E439: undo list corrupt"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1592 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1593 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1594 return curbuf->b_u_newhead->uh_entry;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1595 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1596
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1597 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1598 * u_getbot(): compute the line number of the previous u_save
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1599 * It is called only when b_u_synced is FALSE.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1600 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1601 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1602 u_getbot()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1603 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1604 u_entry_T *uep;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1605 linenr_T extra;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1606
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1607 uep = u_get_headentry(); /* check for corrupt undo list */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1608 if (uep == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1609 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1610
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1611 uep = curbuf->b_u_newhead->uh_getbot_entry;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1612 if (uep != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1613 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1614 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1615 * the new ue_bot is computed from the number of lines that has been
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1616 * inserted (0 - deleted) since calling u_save. This is equal to the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1617 * old line count subtracted from the current line count.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1618 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1619 extra = curbuf->b_ml.ml_line_count - uep->ue_lcount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1620 uep->ue_bot = uep->ue_top + uep->ue_size + 1 + extra;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1621 if (uep->ue_bot < 1 || uep->ue_bot > curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1622 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1623 EMSG(_("E440: undo line missing"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1624 uep->ue_bot = uep->ue_top + 1; /* assume all lines deleted, will
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1625 * get all the old lines back
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1626 * without deleting the current
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1627 * ones */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1628 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1629
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1630 curbuf->b_u_newhead->uh_getbot_entry = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1631 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1632
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1633 curbuf->b_u_synced = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1634 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1635
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1636 /*
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
1637 * Free one header "uhp" and its entry list and adjust the pointers.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1638 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1639 static void
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1640 u_freeheader(buf, uhp, uhpp)
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1641 buf_T *buf;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1642 u_header_T *uhp;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1643 u_header_T **uhpp; /* if not NULL reset when freeing this header */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1644 {
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
1645 u_header_T *uhap;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
1646
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1647 /* When there is an alternate redo list free that branch completely,
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1648 * because we can never go there. */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1649 if (uhp->uh_alt_next != NULL)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1650 u_freebranch(buf, uhp->uh_alt_next, uhpp);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1651
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1652 if (uhp->uh_alt_prev != NULL)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1653 uhp->uh_alt_prev->uh_alt_next = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1654
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1655 /* Update the links in the list to remove the header. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1656 if (uhp->uh_next == NULL)
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1657 buf->b_u_oldhead = uhp->uh_prev;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1658 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1659 uhp->uh_next->uh_prev = uhp->uh_prev;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1660
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1661 if (uhp->uh_prev == NULL)
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1662 buf->b_u_newhead = uhp->uh_next;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1663 else
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
1664 for (uhap = uhp->uh_prev; uhap != NULL; uhap = uhap->uh_alt_next)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
1665 uhap->uh_next = uhp->uh_next;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1666
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1667 u_freeentries(buf, uhp, uhpp);
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1668 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1669
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1670 /*
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1671 * Free an alternate branch and any following alternate branches.
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1672 */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1673 static void
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1674 u_freebranch(buf, uhp, uhpp)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1675 buf_T *buf;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1676 u_header_T *uhp;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1677 u_header_T **uhpp; /* if not NULL reset when freeing this header */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1678 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1679 u_header_T *tofree, *next;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1680
1440
93ffa40b5320 updated for version 7.1-155
vimboss
parents: 1415
diff changeset
1681 /* If this is the top branch we may need to use u_freeheader() to update
93ffa40b5320 updated for version 7.1-155
vimboss
parents: 1415
diff changeset
1682 * all the pointers. */
93ffa40b5320 updated for version 7.1-155
vimboss
parents: 1415
diff changeset
1683 if (uhp == buf->b_u_oldhead)
93ffa40b5320 updated for version 7.1-155
vimboss
parents: 1415
diff changeset
1684 {
93ffa40b5320 updated for version 7.1-155
vimboss
parents: 1415
diff changeset
1685 u_freeheader(buf, uhp, uhpp);
93ffa40b5320 updated for version 7.1-155
vimboss
parents: 1415
diff changeset
1686 return;
93ffa40b5320 updated for version 7.1-155
vimboss
parents: 1415
diff changeset
1687 }
93ffa40b5320 updated for version 7.1-155
vimboss
parents: 1415
diff changeset
1688
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1689 if (uhp->uh_alt_prev != NULL)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1690 uhp->uh_alt_prev->uh_alt_next = NULL;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1691
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1692 next = uhp;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1693 while (next != NULL)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1694 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1695 tofree = next;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1696 if (tofree->uh_alt_next != NULL)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1697 u_freebranch(buf, tofree->uh_alt_next, uhpp); /* recursive */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1698 next = tofree->uh_prev;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1699 u_freeentries(buf, tofree, uhpp);
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1700 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1701 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1702
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1703 /*
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1704 * Free all the undo entries for one header and the header itself.
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1705 * This means that "uhp" is invalid when returning.
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1706 */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1707 static void
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1708 u_freeentries(buf, uhp, uhpp)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1709 buf_T *buf;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1710 u_header_T *uhp;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1711 u_header_T **uhpp; /* if not NULL reset when freeing this header */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1712 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1713 u_entry_T *uep, *nuep;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1714
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1715 /* Check for pointers to the header that become invalid now. */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1716 if (buf->b_u_curhead == uhp)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1717 buf->b_u_curhead = NULL;
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
1718 if (buf->b_u_newhead == uhp)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
1719 buf->b_u_newhead = NULL; /* freeing the newest entry */
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1720 if (uhpp != NULL && uhp == *uhpp)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1721 *uhpp = NULL;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1722
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1723 for (uep = uhp->uh_entry; uep != NULL; uep = nuep)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1724 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1725 nuep = uep->ue_next;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1726 u_freeentry(uep, uep->ue_size);
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1727 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1728
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
1729 #ifdef U_DEBUG
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
1730 uhp->uh_magic = 0;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
1731 #endif
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1732 U_FREE_LINE((char_u *)uhp);
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1733 --buf->b_u_numhead;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1734 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1735
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1736 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1737 * free entry 'uep' and 'n' lines in uep->ue_array[]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1738 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1739 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1740 u_freeentry(uep, n)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1741 u_entry_T *uep;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1742 long n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1743 {
414
8ab9c77240d4 updated for version 7.0108
vimboss
parents: 407
diff changeset
1744 while (n > 0)
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1745 U_FREE_LINE(uep->ue_array[--n]);
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 356
diff changeset
1746 U_FREE_LINE((char_u *)uep->ue_array);
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
1747 #ifdef U_DEBUG
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
1748 uep->ue_magic = 0;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
1749 #endif
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1750 U_FREE_LINE((char_u *)uep);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1751 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1752
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1753 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1754 * invalidate the undo buffer; called when storage has already been released
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1755 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1756 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1757 u_clearall(buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1758 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1759 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1760 buf->b_u_newhead = buf->b_u_oldhead = buf->b_u_curhead = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1761 buf->b_u_synced = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1762 buf->b_u_numhead = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1763 buf->b_u_line_ptr = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1764 buf->b_u_line_lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1765 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1766
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1767 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1768 * save the line "lnum" for the "U" command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1769 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1770 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1771 u_saveline(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1772 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1773 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1774 if (lnum == curbuf->b_u_line_lnum) /* line is already saved */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1775 return;
356
0f2b5d1b8117 updated for version 7.0092
vimboss
parents: 344
diff changeset
1776 if (lnum < 1 || lnum > curbuf->b_ml.ml_line_count) /* should never happen */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1777 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1778 u_clearline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1779 curbuf->b_u_line_lnum = lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1780 if (curwin->w_cursor.lnum == lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1781 curbuf->b_u_line_colnr = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1782 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1783 curbuf->b_u_line_colnr = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1784 if ((curbuf->b_u_line_ptr = u_save_line(lnum)) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1785 do_outofmem_msg((long_u)0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1786 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1787
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1788 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1789 * clear the line saved for the "U" command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1790 * (this is used externally for crossing a line while in insert mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1791 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1792 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1793 u_clearline()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1794 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1795 if (curbuf->b_u_line_ptr != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1796 {
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1797 U_FREE_LINE(curbuf->b_u_line_ptr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1798 curbuf->b_u_line_ptr = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1799 curbuf->b_u_line_lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1800 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1801 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1802
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1803 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1804 * Implementation of the "U" command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1805 * Differentiation from vi: "U" can be undone with the next "U".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1806 * We also allow the cursor to be in another line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1807 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1808 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1809 u_undoline()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1810 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1811 colnr_T t;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1812 char_u *oldp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1813
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1814 if (undo_off)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1815 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1816
1534
bdfbf8ef447a updated for version 7.1-249
vimboss
parents: 1440
diff changeset
1817 if (curbuf->b_u_line_ptr == NULL
bdfbf8ef447a updated for version 7.1-249
vimboss
parents: 1440
diff changeset
1818 || curbuf->b_u_line_lnum > curbuf->b_ml.ml_line_count)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1819 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1820 beep_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1821 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1822 }
1534
bdfbf8ef447a updated for version 7.1-249
vimboss
parents: 1440
diff changeset
1823
bdfbf8ef447a updated for version 7.1-249
vimboss
parents: 1440
diff changeset
1824 /* first save the line for the 'u' command */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1825 if (u_savecommon(curbuf->b_u_line_lnum - 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1826 curbuf->b_u_line_lnum + 1, (linenr_T)0) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1827 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1828 oldp = u_save_line(curbuf->b_u_line_lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1829 if (oldp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1830 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1831 do_outofmem_msg((long_u)0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1832 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1833 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1834 ml_replace(curbuf->b_u_line_lnum, curbuf->b_u_line_ptr, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1835 changed_bytes(curbuf->b_u_line_lnum, 0);
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1836 U_FREE_LINE(curbuf->b_u_line_ptr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1837 curbuf->b_u_line_ptr = oldp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1838
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1839 t = curbuf->b_u_line_colnr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1840 if (curwin->w_cursor.lnum == curbuf->b_u_line_lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1841 curbuf->b_u_line_colnr = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1842 curwin->w_cursor.col = t;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1843 curwin->w_cursor.lnum = curbuf->b_u_line_lnum;
1534
bdfbf8ef447a updated for version 7.1-249
vimboss
parents: 1440
diff changeset
1844 check_cursor_col();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1845 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1846
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1847 /*
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1848 * There are two implementations of the memory management for undo:
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1849 * 1. Use the standard malloc()/free() functions.
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1850 * This should be fast for allocating memory, but when a buffer is
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1851 * abandoned every single allocated chunk must be freed, which may be slow.
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1852 * 2. Allocate larger blocks of memory and keep track of chunks ourselves.
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1853 * This is fast for abandoning, but the use of linked lists is slow for
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1854 * finding a free chunk. Esp. when a lot of lines are changed or deleted.
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1855 * A bit of profiling showed that the first method is faster, especially when
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1856 * making a large number of changes, under the condition that malloc()/free()
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1857 * is implemented efficiently.
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1858 */
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1859 #ifdef U_USE_MALLOC
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1860 /*
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1861 * Version of undo memory allocation using malloc()/free()
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1862 *
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1863 * U_FREE_LINE() and U_ALLOC_LINE() are macros that invoke vim_free() and
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1864 * lalloc() directly.
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1865 */
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1866
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1867 /*
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1868 * Free all allocated memory blocks for the buffer 'buf'.
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1869 */
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1870 void
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1871 u_blockfree(buf)
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1872 buf_T *buf;
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1873 {
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1874 while (buf->b_u_oldhead != NULL)
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1875 u_freeheader(buf, buf->b_u_oldhead, NULL);
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 356
diff changeset
1876 U_FREE_LINE(buf->b_u_line_ptr);
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1877 }
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1878
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1879 #else
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1880 /*
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1881 * Storage allocation for the undo lines and blocks of the current file.
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1882 * Version where Vim keeps track of the available memory.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1883 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1884
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1885 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1886 * Memory is allocated in relatively large blocks. These blocks are linked
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1887 * in the allocated block list, headed by curbuf->b_block_head. They are all
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1888 * freed when abandoning a file, so we don't have to free every single line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1889 * The list is kept sorted on memory address.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1890 * block_alloc() allocates a block.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1891 * m_blockfree() frees all blocks.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1892 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1893 * The available chunks of memory are kept in free chunk lists. There is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1894 * one free list for each block of allocated memory. The list is kept sorted
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1895 * on memory address.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1896 * u_alloc_line() gets a chunk from the free lists.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1897 * u_free_line() returns a chunk to the free lists.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1898 * curbuf->b_m_search points to the chunk before the chunk that was
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1899 * freed/allocated the last time.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1900 * curbuf->b_mb_current points to the b_head where curbuf->b_m_search
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1901 * points into the free list.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1902 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1903 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1904 * b_block_head /---> block #1 /---> block #2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1905 * mb_next ---/ mb_next ---/ mb_next ---> NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1906 * mb_info mb_info mb_info
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1907 * | | |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1908 * V V V
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1909 * NULL free chunk #1.1 free chunk #2.1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1910 * | |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1911 * V V
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1912 * free chunk #1.2 NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1913 * |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1914 * V
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1915 * NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1916 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1917 * When a single free chunk list would have been used, it could take a lot
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1918 * of time in u_free_line() to find the correct place to insert a chunk in the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1919 * free list. The single free list would become very long when many lines are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1920 * changed (e.g. with :%s/^M$//).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1921 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1922
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1923 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1924 * this blocksize is used when allocating new lines
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1925 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1926 #define MEMBLOCKSIZE 2044
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1927
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1928 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1929 * The size field contains the size of the chunk, including the size field
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1930 * itself.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1931 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1932 * When the chunk is not in-use it is preceded with the m_info structure.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1933 * The m_next field links it in one of the free chunk lists.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1934 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1935 * On most unix systems structures have to be longword (32 or 64 bit) aligned.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1936 * On most other systems they are short (16 bit) aligned.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1937 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1938
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1939 /* the structure definitions are now in structs.h */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1940
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1941 #ifdef ALIGN_LONG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1942 /* size of m_size */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1943 # define M_OFFSET (sizeof(long_u))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1944 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1945 /* size of m_size */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1946 # define M_OFFSET (sizeof(short_u))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1947 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1948
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1949 static char_u *u_blockalloc __ARGS((long_u));
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1950
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1951 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1952 * Allocate a block of memory and link it in the allocated block list.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1953 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1954 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1955 u_blockalloc(size)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1956 long_u size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1957 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1958 mblock_T *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1959 mblock_T *mp, *next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1960
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1961 p = (mblock_T *)lalloc(size + sizeof(mblock_T), FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1962 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1963 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1964 /* Insert the block into the allocated block list, keeping it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1965 sorted on address. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1966 for (mp = &curbuf->b_block_head;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1967 (next = mp->mb_next) != NULL && next < p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1968 mp = next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1969 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1970 p->mb_next = next; /* link in block list */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1971 p->mb_size = size;
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
1972 p->mb_maxsize = 0; /* nothing free yet */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1973 mp->mb_next = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1974 p->mb_info.m_next = NULL; /* clear free list */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1975 p->mb_info.m_size = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1976 curbuf->b_mb_current = p; /* remember current block */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1977 curbuf->b_m_search = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1978 p++; /* return usable memory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1979 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1980 return (char_u *)p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1981 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1982
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1983 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1984 * free all allocated memory blocks for the buffer 'buf'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1985 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1986 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1987 u_blockfree(buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1988 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1989 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1990 mblock_T *p, *np;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1991
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1992 for (p = buf->b_block_head.mb_next; p != NULL; p = np)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1993 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1994 np = p->mb_next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1995 vim_free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1996 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1997 buf->b_block_head.mb_next = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1998 buf->b_m_search = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1999 buf->b_mb_current = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2000 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2001
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2002 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2003 * Free a chunk of memory for the current buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2004 * Insert the chunk into the correct free list, keeping it sorted on address.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2005 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2006 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2007 u_free_line(ptr, keep)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2008 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2009 int keep; /* don't free the block when it's empty */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2010 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2011 minfo_T *next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2012 minfo_T *prev, *curr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2013 minfo_T *mp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2014 mblock_T *nextb;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2015 mblock_T *prevb;
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2016 long_u maxsize;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2017
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2018 if (ptr == NULL || ptr == IObuff)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2019 return; /* illegal address can happen in out-of-memory situations */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2020
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2021 mp = (minfo_T *)(ptr - M_OFFSET);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2022
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2023 /* find block where chunk could be a part off */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2024 /* if we change curbuf->b_mb_current, curbuf->b_m_search is set to NULL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2025 if (curbuf->b_mb_current == NULL || mp < (minfo_T *)curbuf->b_mb_current)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2026 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2027 curbuf->b_mb_current = curbuf->b_block_head.mb_next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2028 curbuf->b_m_search = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2029 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2030 if ((nextb = curbuf->b_mb_current->mb_next) != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2031 && (minfo_T *)nextb < mp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2032 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2033 curbuf->b_mb_current = nextb;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2034 curbuf->b_m_search = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2035 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2036 while ((nextb = curbuf->b_mb_current->mb_next) != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2037 && (minfo_T *)nextb < mp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2038 curbuf->b_mb_current = nextb;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2039
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2040 curr = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2041 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2042 * If mp is smaller than curbuf->b_m_search->m_next go to the start of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2043 * the free list
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2044 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2045 if (curbuf->b_m_search == NULL || mp < (curbuf->b_m_search->m_next))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2046 next = &(curbuf->b_mb_current->mb_info);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2047 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2048 next = curbuf->b_m_search;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2049 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2050 * The following loop is executed very often.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2051 * Therefore it has been optimized at the cost of readability.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2052 * Keep it fast!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2053 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2054 #ifdef SLOW_BUT_EASY_TO_READ
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2055 do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2056 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2057 prev = curr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2058 curr = next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2059 next = next->m_next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2060 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2061 while (mp > next && next != NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2062 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2063 do /* first, middle, last */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2064 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2065 prev = next->m_next; /* curr, next, prev */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2066 if (prev == NULL || mp <= prev)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2067 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2068 prev = curr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2069 curr = next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2070 next = next->m_next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2071 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2072 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2073 curr = prev->m_next; /* next, prev, curr */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2074 if (curr == NULL || mp <= curr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2075 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2076 prev = next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2077 curr = prev->m_next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2078 next = curr->m_next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2079 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2080 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2081 next = curr->m_next; /* prev, curr, next */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2082 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2083 while (mp > next && next != NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2084 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2085
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2086 /* if *mp and *next are concatenated, join them into one chunk */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2087 if ((char_u *)mp + mp->m_size == (char_u *)next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2088 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2089 mp->m_size += next->m_size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2090 mp->m_next = next->m_next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2091 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2092 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2093 mp->m_next = next;
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2094 maxsize = mp->m_size;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2095
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2096 /* if *curr and *mp are concatenated, join them */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2097 if (prev != NULL && (char_u *)curr + curr->m_size == (char_u *)mp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2098 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2099 curr->m_size += mp->m_size;
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2100 maxsize = curr->m_size;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2101 curr->m_next = mp->m_next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2102 curbuf->b_m_search = prev;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2103 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2104 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2105 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2106 curr->m_next = mp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2107 curbuf->b_m_search = curr; /* put curbuf->b_m_search before freed
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2108 chunk */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2109 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2110
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2111 /*
1210
302520c08584 updated for version 7.1b
vimboss
parents: 1056
diff changeset
2112 * If the block only contains free memory now, release it.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2113 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2114 if (!keep && curbuf->b_mb_current->mb_size
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2115 == curbuf->b_mb_current->mb_info.m_next->m_size)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2116 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2117 /* Find the block before the current one to be able to unlink it from
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2118 * the list of blocks. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2119 prevb = &curbuf->b_block_head;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2120 for (nextb = prevb->mb_next; nextb != curbuf->b_mb_current;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2121 nextb = nextb->mb_next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2122 prevb = nextb;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2123 prevb->mb_next = nextb->mb_next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2124 vim_free(nextb);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2125 curbuf->b_mb_current = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2126 curbuf->b_m_search = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2127 }
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2128 else if (curbuf->b_mb_current->mb_maxsize < maxsize)
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2129 curbuf->b_mb_current->mb_maxsize = maxsize;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2130 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2131
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2132 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2133 * Allocate and initialize a new line structure with room for at least
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2134 * 'size' characters plus a terminating NUL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2135 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2136 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2137 u_alloc_line(size)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2138 unsigned size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2139 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2140 minfo_T *mp, *mprev, *mp2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2141 mblock_T *mbp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2142 int size_align;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2143
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2144 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2145 * Add room for size field and trailing NUL byte.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2146 * Adjust for minimal size (must be able to store minfo_T
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2147 * plus a trailing NUL, so the chunk can be released again)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2148 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2149 size += M_OFFSET + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2150 if (size < sizeof(minfo_T) + 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2151 size = sizeof(minfo_T) + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2152
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2153 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2154 * round size up for alignment
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2155 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2156 size_align = (size + ALIGN_MASK) & ~ALIGN_MASK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2157
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2158 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2159 * If curbuf->b_m_search is NULL (uninitialized free list) start at
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2160 * curbuf->b_block_head
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2161 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2162 if (curbuf->b_mb_current == NULL || curbuf->b_m_search == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2163 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2164 curbuf->b_mb_current = &curbuf->b_block_head;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2165 curbuf->b_m_search = &(curbuf->b_block_head.mb_info);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2166 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2167
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2168 /* Search for a block with enough space. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2169 mbp = curbuf->b_mb_current;
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2170 while (mbp->mb_maxsize < size_align)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2171 {
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2172 if (mbp->mb_next != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2173 mbp = mbp->mb_next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2174 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2175 mbp = &curbuf->b_block_head;
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2176 if (mbp == curbuf->b_mb_current)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2177 {
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2178 int n = (size_align > (MEMBLOCKSIZE / 4)
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2179 ? size_align : MEMBLOCKSIZE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2180
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2181 /* Back where we started in block list: need to add a new block
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2182 * with enough space. */
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2183 mp = (minfo_T *)u_blockalloc((long_u)n);
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2184 if (mp == NULL)
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2185 return (NULL);
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2186 mp->m_size = n;
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2187 u_free_line((char_u *)mp + M_OFFSET, TRUE);
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2188 mbp = curbuf->b_mb_current;
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2189 break;
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2190 }
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2191 }
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2192 if (mbp != curbuf->b_mb_current)
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2193 curbuf->b_m_search = &(mbp->mb_info);
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2194
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2195 /* In this block find a chunk with enough space. */
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2196 mprev = curbuf->b_m_search;
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2197 mp = curbuf->b_m_search->m_next;
407
0f6afaf1b8d1 updated for version 7.0106
vimboss
parents: 359
diff changeset
2198 for (;;)
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2199 {
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2200 if (mp == NULL) /* at end of the list */
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2201 mp = &(mbp->mb_info); /* wrap around to begin */
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2202 if (mp->m_size >= size)
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2203 break;
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2204 if (mp == curbuf->b_m_search)
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2205 {
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2206 /* back where we started in free chunk list: "cannot happen" */
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2207 EMSG2(_(e_intern2), "u_alloc_line()");
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2208 return NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2209 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2210 mprev = mp;
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2211 mp = mp->m_next;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2212 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2213
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2214 /* when using the largest chunk adjust mb_maxsize */
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2215 if (mp->m_size >= mbp->mb_maxsize)
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2216 mbp->mb_maxsize = 0;
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2217
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2218 /* if the chunk we found is large enough, split it up in two */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2219 if ((long)mp->m_size - size_align >= (long)(sizeof(minfo_T) + 1))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2220 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2221 mp2 = (minfo_T *)((char_u *)mp + size_align);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2222 mp2->m_size = mp->m_size - size_align;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2223 mp2->m_next = mp->m_next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2224 mprev->m_next = mp2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2225 mp->m_size = size_align;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2226 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2227 else /* remove *mp from the free list */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2228 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2229 mprev->m_next = mp->m_next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2230 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2231 curbuf->b_m_search = mprev;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2232 curbuf->b_mb_current = mbp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2233
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2234 /* If using the largest chunk need to find the new largest chunk */
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2235 if (mbp->mb_maxsize == 0)
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2236 for (mp2 = &(mbp->mb_info); mp2 != NULL; mp2 = mp2->m_next)
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2237 if (mbp->mb_maxsize < mp2->m_size)
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2238 mbp->mb_maxsize = mp2->m_size;
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2239
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2240 mp = (minfo_T *)((char_u *)mp + M_OFFSET);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2241 *(char_u *)mp = NUL; /* set the first byte to NUL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2242
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2243 return ((char_u *)mp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2244 }
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2245 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2246
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2247 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2248 * u_save_line(): allocate memory with u_alloc_line() and copy line 'lnum'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2249 * into it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2250 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2251 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2252 u_save_line(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2253 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2254 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2255 char_u *src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2256 char_u *dst;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2257 unsigned len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2258
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2259 src = ml_get(lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2260 len = (unsigned)STRLEN(src);
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2261 if ((dst = U_ALLOC_LINE(len)) != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2262 mch_memmove(dst, src, (size_t)(len + 1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2263 return (dst);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2264 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2265
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2266 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2267 * Check if the 'modified' flag is set, or 'ff' has changed (only need to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2268 * check the first character, because it can only be "dos", "unix" or "mac").
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2269 * "nofile" and "scratch" type buffers are considered to always be unchanged.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2270 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2271 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2272 bufIsChanged(buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2273 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2274 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2275 return
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2276 #ifdef FEAT_QUICKFIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2277 !bt_dontwrite(buf) &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2278 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2279 (buf->b_changed || file_ff_differs(buf));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2280 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2281
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2282 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2283 curbufIsChanged()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2284 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2285 return
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2286 #ifdef FEAT_QUICKFIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2287 !bt_dontwrite(curbuf) &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2288 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2289 (curbuf->b_changed || file_ff_differs(curbuf));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2290 }