Mercurial > vim
annotate src/undo.c @ 16507:7c6fe15778cf v8.1.1257
patch 8.1.1257: MSVC: name of object directory now always right
commit https://github.com/vim/vim/commit/819d3e52a1eab35409ea7e0ebdb2340507a42684
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri May 3 22:15:03 2019 +0200
patch 8.1.1257: MSVC: name of object directory now always right
Problem: MSVC: name of object directory now always right.
Solution: Adjust comment. Don't use different directory for DIRECTX. Do
use different directory for USE_MSVCRT. (Ken Takata, closes #4333)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 03 May 2019 22:30:05 +0200 |
parents | 840fa633ad64 |
children | 7ad3fc329e08 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9674
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * undo.c: multi level undo facility | |
12 * | |
13 * The saved lines are stored in a list of lists (one for each buffer): | |
14 * | |
15 * b_u_oldhead------------------------------------------------+ | |
16 * | | |
17 * V | |
18 * +--------------+ +--------------+ +--------------+ | |
19 * b_u_newhead--->| u_header | | u_header | | u_header | | |
20 * | uh_next------>| uh_next------>| uh_next---->NULL | |
21 * NULL<--------uh_prev |<---------uh_prev |<---------uh_prev | | |
22 * | uh_entry | | uh_entry | | uh_entry | | |
23 * +--------|-----+ +--------|-----+ +--------|-----+ | |
24 * | | | | |
25 * V V V | |
26 * +--------------+ +--------------+ +--------------+ | |
27 * | u_entry | | u_entry | | u_entry | | |
28 * | ue_next | | ue_next | | ue_next | | |
29 * +--------|-----+ +--------|-----+ +--------|-----+ | |
30 * | | | | |
31 * V V V | |
32 * +--------------+ NULL NULL | |
33 * | u_entry | | |
34 * | ue_next | | |
35 * +--------|-----+ | |
36 * | | |
37 * V | |
38 * etc. | |
39 * | |
40 * Each u_entry list contains the information for one undo or redo. | |
41 * curbuf->b_u_curhead points to the header of the last undo (the next redo), | |
758 | 42 * or is NULL if nothing has been undone (end of the branch). |
7 | 43 * |
753 | 44 * For keeping alternate undo/redo branches the uh_alt field is used. Thus at |
45 * each point in the list a branch may appear for an alternate to redo. The | |
46 * uh_seq field is numbered sequentially to be able to find a newer or older | |
47 * branch. | |
48 * | |
758 | 49 * +---------------+ +---------------+ |
50 * b_u_oldhead --->| u_header | | u_header | | |
51 * | uh_alt_next ---->| uh_alt_next ----> NULL | |
52 * NULL <----- uh_alt_prev |<------ uh_alt_prev | | |
53 * | uh_prev | | uh_prev | | |
54 * +-----|---------+ +-----|---------+ | |
55 * | | | |
56 * V V | |
57 * +---------------+ +---------------+ | |
58 * | u_header | | u_header | | |
59 * | uh_alt_next | | uh_alt_next | | |
60 * b_u_newhead --->| uh_alt_prev | | uh_alt_prev | | |
61 * | uh_prev | | uh_prev | | |
62 * +-----|---------+ +-----|---------+ | |
63 * | | | |
64 * V V | |
65 * NULL +---------------+ +---------------+ | |
66 * | u_header | | u_header | | |
67 * | uh_alt_next ---->| uh_alt_next | | |
68 * | uh_alt_prev |<------ uh_alt_prev | | |
69 * | uh_prev | | uh_prev | | |
70 * +-----|---------+ +-----|---------+ | |
71 * | | | |
72 * etc. etc. | |
73 * | |
74 * | |
2230
290ee42cae85
Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
75 * All data is allocated and will all be freed when the buffer is unloaded. |
7 | 76 */ |
77 | |
1415 | 78 /* Uncomment the next line for including the u_check() function. This warns |
79 * for errors in the debug information. */ | |
80 /* #define U_DEBUG 1 */ | |
81 #define UH_MAGIC 0x18dade /* value for uh_magic when in use */ | |
82 #define UE_MAGIC 0xabc123 /* value for ue_magic when in use */ | |
83 | |
6122 | 84 /* Size of buffer used for encryption. */ |
85 #define CRYPT_BUF_SIZE 8192 | |
86 | |
7 | 87 #include "vim.h" |
88 | |
6122 | 89 /* Structure passed around between functions. |
90 * Avoids passing cryptstate_T when encryption not available. */ | |
91 typedef struct { | |
92 buf_T *bi_buf; | |
93 FILE *bi_fp; | |
94 #ifdef FEAT_CRYPT | |
95 cryptstate_T *bi_state; | |
96 char_u *bi_buffer; /* CRYPT_BUF_SIZE, NULL when not buffering */ | |
97 size_t bi_used; /* bytes written to/read from bi_buffer */ | |
98 size_t bi_avail; /* bytes available in bi_buffer */ | |
99 #endif | |
100 } bufinfo_T; | |
101 | |
102 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
6771
diff
changeset
|
103 static void u_unch_branch(u_header_T *uhp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
6771
diff
changeset
|
104 static u_entry_T *u_get_headentry(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
6771
diff
changeset
|
105 static void u_getbot(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
6771
diff
changeset
|
106 static void u_doit(int count); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
6771
diff
changeset
|
107 static void u_undoredo(int undo); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
6771
diff
changeset
|
108 static void u_undo_end(int did_undo, int absolute); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
6771
diff
changeset
|
109 static void u_add_time(char_u *buf, size_t buflen, time_t tt); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
6771
diff
changeset
|
110 static void u_freeheader(buf_T *buf, u_header_T *uhp, u_header_T **uhpp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
6771
diff
changeset
|
111 static void u_freebranch(buf_T *buf, u_header_T *uhp, u_header_T **uhpp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
6771
diff
changeset
|
112 static void u_freeentries(buf_T *buf, u_header_T *uhp, u_header_T **uhpp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
6771
diff
changeset
|
113 static void u_freeentry(u_entry_T *, long); |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
114 #ifdef FEAT_PERSISTENT_UNDO |
8128
985cd5917560
commit https://github.com/vim/vim/commit/1d6fbe654066845ff2a182ed258e6e9d3408fa90
Christian Brabandt <cb@256bit.org>
parents:
7835
diff
changeset
|
115 # ifdef FEAT_CRYPT |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
6771
diff
changeset
|
116 static int undo_flush(bufinfo_T *bi); |
8128
985cd5917560
commit https://github.com/vim/vim/commit/1d6fbe654066845ff2a182ed258e6e9d3408fa90
Christian Brabandt <cb@256bit.org>
parents:
7835
diff
changeset
|
117 # endif |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
6771
diff
changeset
|
118 static int undo_read(bufinfo_T *bi, char_u *buffer, size_t size); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
6771
diff
changeset
|
119 static int serialize_uep(bufinfo_T *bi, u_entry_T *uep); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
6771
diff
changeset
|
120 static u_entry_T *unserialize_uep(bufinfo_T *bi, int *error, char_u *file_name); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
6771
diff
changeset
|
121 static void serialize_pos(bufinfo_T *bi, pos_T pos); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
6771
diff
changeset
|
122 static void unserialize_pos(bufinfo_T *bi, pos_T *pos); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
6771
diff
changeset
|
123 static void serialize_visualinfo(bufinfo_T *bi, visualinfo_T *info); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
6771
diff
changeset
|
124 static void unserialize_visualinfo(bufinfo_T *bi, visualinfo_T *info); |
168 | 125 #endif |
7 | 126 |
2230
290ee42cae85
Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
127 #define U_ALLOC_LINE(size) lalloc((long_u)(size), FALSE) |
7 | 128 |
2281
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
129 /* used in undo_end() to report number of added and deleted lines */ |
7 | 130 static long u_newcount, u_oldcount; |
131 | |
132 /* | |
133 * When 'u' flag included in 'cpoptions', we behave like vi. Need to remember | |
134 * the action that "u" should do. | |
135 */ | |
136 static int undo_undoes = FALSE; | |
137 | |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
138 static int lastmark = 0; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
139 |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
140 #if defined(U_DEBUG) || defined(PROTO) |
1415 | 141 /* |
142 * Check the undo structures for being valid. Print a warning when something | |
143 * looks wrong. | |
144 */ | |
145 static int seen_b_u_curhead; | |
146 static int seen_b_u_newhead; | |
147 static int header_count; | |
148 | |
149 static void | |
150 u_check_tree(u_header_T *uhp, | |
151 u_header_T *exp_uh_next, | |
152 u_header_T *exp_uh_alt_prev) | |
153 { | |
154 u_entry_T *uep; | |
155 | |
156 if (uhp == NULL) | |
157 return; | |
158 ++header_count; | |
159 if (uhp == curbuf->b_u_curhead && ++seen_b_u_curhead > 1) | |
160 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
161 emsg("b_u_curhead found twice (looping?)"); |
1415 | 162 return; |
163 } | |
164 if (uhp == curbuf->b_u_newhead && ++seen_b_u_newhead > 1) | |
165 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
166 emsg("b_u_newhead found twice (looping?)"); |
1415 | 167 return; |
168 } | |
169 | |
170 if (uhp->uh_magic != UH_MAGIC) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
171 emsg("uh_magic wrong (may be using freed memory)"); |
1415 | 172 else |
173 { | |
174 /* Check pointers back are correct. */ | |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
175 if (uhp->uh_next.ptr != exp_uh_next) |
1415 | 176 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
177 emsg("uh_next wrong"); |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
178 smsg("expected: 0x%x, actual: 0x%x", |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
179 exp_uh_next, uhp->uh_next.ptr); |
1415 | 180 } |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
181 if (uhp->uh_alt_prev.ptr != exp_uh_alt_prev) |
1415 | 182 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
183 emsg("uh_alt_prev wrong"); |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
184 smsg("expected: 0x%x, actual: 0x%x", |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
185 exp_uh_alt_prev, uhp->uh_alt_prev.ptr); |
1415 | 186 } |
187 | |
188 /* Check the undo tree at this header. */ | |
189 for (uep = uhp->uh_entry; uep != NULL; uep = uep->ue_next) | |
190 { | |
191 if (uep->ue_magic != UE_MAGIC) | |
192 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
193 emsg("ue_magic wrong (may be using freed memory)"); |
1415 | 194 break; |
195 } | |
196 } | |
197 | |
198 /* Check the next alt tree. */ | |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
199 u_check_tree(uhp->uh_alt_next.ptr, uhp->uh_next.ptr, uhp); |
1415 | 200 |
201 /* Check the next header in this branch. */ | |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
202 u_check_tree(uhp->uh_prev.ptr, uhp, NULL); |
1415 | 203 } |
204 } | |
205 | |
2189 | 206 static void |
1415 | 207 u_check(int newhead_may_be_NULL) |
208 { | |
209 seen_b_u_newhead = 0; | |
210 seen_b_u_curhead = 0; | |
211 header_count = 0; | |
212 | |
213 u_check_tree(curbuf->b_u_oldhead, NULL, NULL); | |
214 | |
215 if (seen_b_u_newhead == 0 && curbuf->b_u_oldhead != NULL | |
216 && !(newhead_may_be_NULL && curbuf->b_u_newhead == NULL)) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
217 semsg("b_u_newhead invalid: 0x%x", curbuf->b_u_newhead); |
1415 | 218 if (curbuf->b_u_curhead != NULL && seen_b_u_curhead == 0) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
219 semsg("b_u_curhead invalid: 0x%x", curbuf->b_u_curhead); |
1415 | 220 if (header_count != curbuf->b_u_numhead) |
221 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
222 emsg("b_u_numhead invalid"); |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
223 smsg("expected: %ld, actual: %ld", |
1415 | 224 (long)header_count, (long)curbuf->b_u_numhead); |
225 } | |
226 } | |
227 #endif | |
228 | |
7 | 229 /* |
344 | 230 * Save the current line for both the "u" and "U" command. |
4303 | 231 * Careful: may trigger autocommands that reload the buffer. |
344 | 232 * Returns OK or FAIL. |
7 | 233 */ |
234 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
235 u_save_cursor(void) |
7 | 236 { |
237 return (u_save((linenr_T)(curwin->w_cursor.lnum - 1), | |
238 (linenr_T)(curwin->w_cursor.lnum + 1))); | |
239 } | |
240 | |
241 /* | |
242 * Save the lines between "top" and "bot" for both the "u" and "U" command. | |
243 * "top" may be 0 and bot may be curbuf->b_ml.ml_line_count + 1. | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2288
diff
changeset
|
244 * Careful: may trigger autocommands that reload the buffer. |
7 | 245 * Returns FAIL when lines could not be saved, OK otherwise. |
246 */ | |
247 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
248 u_save(linenr_T top, linenr_T bot) |
7 | 249 { |
250 if (undo_off) | |
251 return OK; | |
252 | |
14327
b8f1167aa8ad
patch 8.1.0179: redundant condition for boundary check
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
253 if (top >= bot || bot > curbuf->b_ml.ml_line_count + 1) |
b8f1167aa8ad
patch 8.1.0179: redundant condition for boundary check
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
254 return FAIL; // rely on caller to give an error message |
7 | 255 |
256 if (top + 2 == bot) | |
257 u_saveline((linenr_T)(top + 1)); | |
258 | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
259 return (u_savecommon(top, bot, (linenr_T)0, FALSE)); |
7 | 260 } |
261 | |
262 /* | |
2181 | 263 * Save the line "lnum" (used by ":s" and "~" command). |
7 | 264 * The line is replaced, so the new bottom line is lnum + 1. |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2288
diff
changeset
|
265 * Careful: may trigger autocommands that reload the buffer. |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2288
diff
changeset
|
266 * Returns FAIL when lines could not be saved, OK otherwise. |
7 | 267 */ |
268 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
269 u_savesub(linenr_T lnum) |
7 | 270 { |
271 if (undo_off) | |
272 return OK; | |
273 | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
274 return (u_savecommon(lnum - 1, lnum + 1, lnum + 1, FALSE)); |
7 | 275 } |
276 | |
277 /* | |
2181 | 278 * A new line is inserted before line "lnum" (used by :s command). |
7 | 279 * The line is inserted, so the new bottom line is lnum + 1. |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2288
diff
changeset
|
280 * Careful: may trigger autocommands that reload the buffer. |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2288
diff
changeset
|
281 * Returns FAIL when lines could not be saved, OK otherwise. |
7 | 282 */ |
283 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
284 u_inssub(linenr_T lnum) |
7 | 285 { |
286 if (undo_off) | |
287 return OK; | |
288 | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
289 return (u_savecommon(lnum - 1, lnum, lnum + 1, FALSE)); |
7 | 290 } |
291 | |
292 /* | |
2181 | 293 * Save the lines "lnum" - "lnum" + nlines (used by delete command). |
7 | 294 * The lines are deleted, so the new bottom line is lnum, unless the buffer |
295 * becomes empty. | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2288
diff
changeset
|
296 * Careful: may trigger autocommands that reload the buffer. |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2288
diff
changeset
|
297 * Returns FAIL when lines could not be saved, OK otherwise. |
7 | 298 */ |
299 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
300 u_savedel(linenr_T lnum, long nlines) |
7 | 301 { |
302 if (undo_off) | |
303 return OK; | |
304 | |
305 return (u_savecommon(lnum - 1, lnum + nlines, | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
306 nlines == curbuf->b_ml.ml_line_count ? 2 : lnum, FALSE)); |
7 | 307 } |
308 | |
632 | 309 /* |
310 * Return TRUE when undo is allowed. Otherwise give an error message and | |
311 * return FALSE. | |
312 */ | |
912 | 313 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
314 undo_allowed(void) |
632 | 315 { |
316 /* Don't allow changes when 'modifiable' is off. */ | |
317 if (!curbuf->b_p_ma) | |
318 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
319 emsg(_(e_modifiable)); |
632 | 320 return FALSE; |
321 } | |
322 | |
323 #ifdef HAVE_SANDBOX | |
324 /* In the sandbox it's not allowed to change the text. */ | |
325 if (sandbox != 0) | |
326 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
327 emsg(_(e_sandbox)); |
632 | 328 return FALSE; |
329 } | |
330 #endif | |
331 | |
332 /* Don't allow changes in the buffer while editing the cmdline. The | |
333 * caller of getcmdline() may get confused. */ | |
634 | 334 if (textlock != 0) |
632 | 335 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
336 emsg(_(e_secure)); |
632 | 337 return FALSE; |
338 } | |
339 | |
340 return TRUE; | |
341 } | |
342 | |
2189 | 343 /* |
5446 | 344 * Get the undolevle value for the current buffer. |
345 */ | |
346 static long | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
347 get_undolevel(void) |
5446 | 348 { |
349 if (curbuf->b_p_ul == NO_LOCAL_UNDOLEVEL) | |
350 return p_ul; | |
351 return curbuf->b_p_ul; | |
352 } | |
353 | |
354 /* | |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
355 * u_save_line(): save an allocated copy of line "lnum" into "ul". |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
356 * Returns FAIL when out of memory. |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
357 */ |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
358 static int |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
359 u_save_line(undoline_T *ul, linenr_T lnum) |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
360 { |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
361 char_u *line = ml_get(lnum); |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
362 |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
363 if (curbuf->b_ml.ml_line_len == 0) |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
364 { |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
365 ul->ul_len = 1; |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
366 ul->ul_line = vim_strsave((char_u *)""); |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
367 } |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
368 else |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
369 { |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
370 ul->ul_len = curbuf->b_ml.ml_line_len; |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
371 ul->ul_line = vim_memsave(line, ul->ul_len); |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
372 } |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
373 return ul->ul_line == NULL ? FAIL : OK; |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
374 } |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
375 |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
376 /* |
2189 | 377 * Common code for various ways to save text before a change. |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2288
diff
changeset
|
378 * "top" is the line above the first changed line. |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2288
diff
changeset
|
379 * "bot" is the line below the last changed line. |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
380 * "newbot" is the new bottom line. Use zero when not known. |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
381 * "reload" is TRUE when saving for a buffer reload. |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2288
diff
changeset
|
382 * Careful: may trigger autocommands that reload the buffer. |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2288
diff
changeset
|
383 * Returns FAIL when lines could not be saved, OK otherwise. |
2189 | 384 */ |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
385 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
386 u_savecommon( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
387 linenr_T top, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
388 linenr_T bot, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
389 linenr_T newbot, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
390 int reload) |
7 | 391 { |
753 | 392 linenr_T lnum; |
393 long i; | |
394 u_header_T *uhp; | |
395 u_header_T *old_curhead; | |
396 u_entry_T *uep; | |
397 u_entry_T *prev_uep; | |
398 long size; | |
7 | 399 |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
400 if (!reload) |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
401 { |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
402 /* When making changes is not allowed return FAIL. It's a crude way |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
403 * to make all change commands fail. */ |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
404 if (!undo_allowed()) |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
405 return FAIL; |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
406 |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
407 #ifdef FEAT_NETBEANS_INTG |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
408 /* |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
409 * Netbeans defines areas that cannot be modified. Bail out here when |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
410 * trying to change text in a guarded area. |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
411 */ |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
412 if (netbeans_active()) |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
413 { |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
414 if (netbeans_is_guarded(top, bot)) |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
415 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
416 emsg(_(e_guarded)); |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
417 return FAIL; |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
418 } |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
419 if (curbuf->b_p_ro) |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
420 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
421 emsg(_(e_nbreadonly)); |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
422 return FAIL; |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
423 } |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
424 } |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
425 #endif |
11836
f080b225a2a4
patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents:
11506
diff
changeset
|
426 #ifdef FEAT_TERMINAL |
f080b225a2a4
patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents:
11506
diff
changeset
|
427 /* A change in a terminal buffer removes the highlighting. */ |
f080b225a2a4
patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents:
11506
diff
changeset
|
428 term_change_in_curbuf(); |
f080b225a2a4
patch 8.0.0798: no highlighting in a terminal window with a finished job
Christian Brabandt <cb@256bit.org>
parents:
11506
diff
changeset
|
429 #endif |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
430 |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
431 /* |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
432 * Saving text for undo means we are going to make a change. Give a |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
433 * warning for a read-only file before making the change, so that the |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
434 * FileChangedRO event can replace the buffer with a read-write version |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
435 * (e.g., obtained from a source control system). |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
436 */ |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
437 change_warning(0); |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
438 if (bot > curbuf->b_ml.ml_line_count + 1) |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
439 { |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
440 /* This happens when the FileChangedRO autocommand changes the |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
441 * file in a way it becomes shorter. */ |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
442 emsg(_("E881: Line count changed unexpectedly")); |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
443 return FAIL; |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
444 } |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
445 } |
7 | 446 |
1415 | 447 #ifdef U_DEBUG |
448 u_check(FALSE); | |
449 #endif | |
7 | 450 |
451 size = bot - top - 1; | |
452 | |
453 /* | |
2189 | 454 * If curbuf->b_u_synced == TRUE make a new header. |
7 | 455 */ |
456 if (curbuf->b_u_synced) | |
457 { | |
458 #ifdef FEAT_JUMPLIST | |
459 /* Need to create new entry in b_changelist. */ | |
460 curbuf->b_new_change = TRUE; | |
461 #endif | |
462 | |
5446 | 463 if (get_undolevel() >= 0) |
753 | 464 { |
465 /* | |
466 * Make a new header entry. Do this first so that we don't mess | |
467 * up the undo info when out of memory. | |
468 */ | |
2230
290ee42cae85
Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
469 uhp = (u_header_T *)U_ALLOC_LINE(sizeof(u_header_T)); |
753 | 470 if (uhp == NULL) |
471 goto nomem; | |
1415 | 472 #ifdef U_DEBUG |
473 uhp->uh_magic = UH_MAGIC; | |
474 #endif | |
753 | 475 } |
766 | 476 else |
477 uhp = NULL; | |
753 | 478 |
7 | 479 /* |
758 | 480 * If we undid more than we redid, move the entry lists before and |
481 * including curbuf->b_u_curhead to an alternate branch. | |
7 | 482 */ |
753 | 483 old_curhead = curbuf->b_u_curhead; |
484 if (old_curhead != NULL) | |
485 { | |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
486 curbuf->b_u_newhead = old_curhead->uh_next.ptr; |
753 | 487 curbuf->b_u_curhead = NULL; |
488 } | |
7 | 489 |
490 /* | |
491 * free headers to keep the size right | |
492 */ | |
5446 | 493 while (curbuf->b_u_numhead > get_undolevel() |
494 && curbuf->b_u_oldhead != NULL) | |
753 | 495 { |
758 | 496 u_header_T *uhfree = curbuf->b_u_oldhead; |
753 | 497 |
1415 | 498 if (uhfree == old_curhead) |
499 /* Can't reconnect the branch, delete all of it. */ | |
500 u_freebranch(curbuf, uhfree, &old_curhead); | |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
501 else if (uhfree->uh_alt_next.ptr == NULL) |
1415 | 502 /* There is no branch, only free one header. */ |
758 | 503 u_freeheader(curbuf, uhfree, &old_curhead); |
753 | 504 else |
505 { | |
506 /* Free the oldest alternate branch as a whole. */ | |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
507 while (uhfree->uh_alt_next.ptr != NULL) |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
508 uhfree = uhfree->uh_alt_next.ptr; |
758 | 509 u_freebranch(curbuf, uhfree, &old_curhead); |
753 | 510 } |
1415 | 511 #ifdef U_DEBUG |
512 u_check(TRUE); | |
513 #endif | |
753 | 514 } |
7 | 515 |
766 | 516 if (uhp == NULL) /* no undo at all */ |
7 | 517 { |
753 | 518 if (old_curhead != NULL) |
519 u_freebranch(curbuf, old_curhead, NULL); | |
7 | 520 curbuf->b_u_synced = FALSE; |
521 return OK; | |
522 } | |
523 | |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
524 uhp->uh_prev.ptr = NULL; |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
525 uhp->uh_next.ptr = curbuf->b_u_newhead; |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
526 uhp->uh_alt_next.ptr = old_curhead; |
753 | 527 if (old_curhead != NULL) |
528 { | |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
529 uhp->uh_alt_prev.ptr = old_curhead->uh_alt_prev.ptr; |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
530 if (uhp->uh_alt_prev.ptr != NULL) |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
531 uhp->uh_alt_prev.ptr->uh_alt_next.ptr = uhp; |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
532 old_curhead->uh_alt_prev.ptr = uhp; |
753 | 533 if (curbuf->b_u_oldhead == old_curhead) |
534 curbuf->b_u_oldhead = uhp; | |
535 } | |
1056 | 536 else |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
537 uhp->uh_alt_prev.ptr = NULL; |
758 | 538 if (curbuf->b_u_newhead != NULL) |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
539 curbuf->b_u_newhead->uh_prev.ptr = uhp; |
758 | 540 |
777 | 541 uhp->uh_seq = ++curbuf->b_u_seq_last; |
542 curbuf->b_u_seq_cur = uhp->uh_seq; | |
9674
adc7212951ee
commit https://github.com/vim/vim/commit/170b10b421f0c9fda08b7cfd3bb043c064f3659a
Christian Brabandt <cb@256bit.org>
parents:
9536
diff
changeset
|
543 uhp->uh_time = vim_time(); |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
544 uhp->uh_save_nr = 0; |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
545 curbuf->b_u_time_cur = uhp->uh_time + 1; |
758 | 546 |
753 | 547 uhp->uh_walk = 0; |
7 | 548 uhp->uh_entry = NULL; |
549 uhp->uh_getbot_entry = NULL; | |
550 uhp->uh_cursor = curwin->w_cursor; /* save cursor pos. for undo */ | |
551 if (virtual_active() && curwin->w_cursor.coladd > 0) | |
552 uhp->uh_cursor_vcol = getviscol(); | |
553 else | |
554 uhp->uh_cursor_vcol = -1; | |
555 | |
556 /* save changed and buffer empty flag for undo */ | |
557 uhp->uh_flags = (curbuf->b_changed ? UH_CHANGED : 0) + | |
558 ((curbuf->b_ml.ml_flags & ML_EMPTY) ? UH_EMPTYBUF : 0); | |
559 | |
692 | 560 /* save named marks and Visual marks for undo */ |
7 | 561 mch_memmove(uhp->uh_namedm, curbuf->b_namedm, sizeof(pos_T) * NMARKS); |
692 | 562 uhp->uh_visual = curbuf->b_visual; |
563 | |
7 | 564 curbuf->b_u_newhead = uhp; |
565 if (curbuf->b_u_oldhead == NULL) | |
566 curbuf->b_u_oldhead = uhp; | |
567 ++curbuf->b_u_numhead; | |
568 } | |
569 else | |
570 { | |
5446 | 571 if (get_undolevel() < 0) /* no undo at all */ |
7 | 572 return OK; |
573 | |
574 /* | |
575 * When saving a single line, and it has been saved just before, it | |
576 * doesn't make sense saving it again. Saves a lot of memory when | |
577 * making lots of changes inside the same line. | |
578 * This is only possible if the previous change didn't increase or | |
579 * decrease the number of lines. | |
580 * Check the ten last changes. More doesn't make sense and takes too | |
581 * long. | |
582 */ | |
583 if (size == 1) | |
584 { | |
585 uep = u_get_headentry(); | |
586 prev_uep = NULL; | |
587 for (i = 0; i < 10; ++i) | |
588 { | |
589 if (uep == NULL) | |
590 break; | |
591 | |
592 /* If lines have been inserted/deleted we give up. | |
593 * Also when the line was included in a multi-line save. */ | |
594 if ((curbuf->b_u_newhead->uh_getbot_entry != uep | |
595 ? (uep->ue_top + uep->ue_size + 1 | |
596 != (uep->ue_bot == 0 | |
597 ? curbuf->b_ml.ml_line_count + 1 | |
598 : uep->ue_bot)) | |
599 : uep->ue_lcount != curbuf->b_ml.ml_line_count) | |
600 || (uep->ue_size > 1 | |
601 && top >= uep->ue_top | |
602 && top + 2 <= uep->ue_top + uep->ue_size + 1)) | |
603 break; | |
604 | |
605 /* If it's the same line we can skip saving it again. */ | |
606 if (uep->ue_size == 1 && uep->ue_top == top) | |
607 { | |
608 if (i > 0) | |
609 { | |
610 /* It's not the last entry: get ue_bot for the last | |
611 * entry now. Following deleted/inserted lines go to | |
612 * the re-used entry. */ | |
613 u_getbot(); | |
614 curbuf->b_u_synced = FALSE; | |
615 | |
616 /* Move the found entry to become the last entry. The | |
617 * order of undo/redo doesn't matter for the entries | |
618 * we move it over, since they don't change the line | |
619 * count and don't include this line. It does matter | |
620 * for the found entry if the line count is changed by | |
621 * the executed command. */ | |
622 prev_uep->ue_next = uep->ue_next; | |
623 uep->ue_next = curbuf->b_u_newhead->uh_entry; | |
624 curbuf->b_u_newhead->uh_entry = uep; | |
625 } | |
626 | |
627 /* The executed command may change the line count. */ | |
628 if (newbot != 0) | |
629 uep->ue_bot = newbot; | |
630 else if (bot > curbuf->b_ml.ml_line_count) | |
631 uep->ue_bot = 0; | |
632 else | |
633 { | |
634 uep->ue_lcount = curbuf->b_ml.ml_line_count; | |
635 curbuf->b_u_newhead->uh_getbot_entry = uep; | |
636 } | |
637 return OK; | |
638 } | |
639 prev_uep = uep; | |
640 uep = uep->ue_next; | |
641 } | |
642 } | |
643 | |
644 /* find line number for ue_bot for previous u_save() */ | |
645 u_getbot(); | |
646 } | |
647 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
648 #if !defined(UNIX) && !defined(MSWIN) |
7 | 649 /* |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8128
diff
changeset
|
650 * With Amiga we can't handle big undo's, because |
7 | 651 * then u_alloc_line would have to allocate a block larger than 32K |
652 */ | |
653 if (size >= 8000) | |
654 goto nomem; | |
655 #endif | |
656 | |
657 /* | |
658 * add lines in front of entry list | |
659 */ | |
2230
290ee42cae85
Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
660 uep = (u_entry_T *)U_ALLOC_LINE(sizeof(u_entry_T)); |
7 | 661 if (uep == NULL) |
662 goto nomem; | |
2215
cccb71c2c5c1
Fix uninit memory read in undo code. Fix uint32_t in proto file.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
663 vim_memset(uep, 0, sizeof(u_entry_T)); |
1415 | 664 #ifdef U_DEBUG |
665 uep->ue_magic = UE_MAGIC; | |
666 #endif | |
7 | 667 |
668 uep->ue_size = size; | |
669 uep->ue_top = top; | |
670 if (newbot != 0) | |
671 uep->ue_bot = newbot; | |
672 /* | |
673 * Use 0 for ue_bot if bot is below last line. | |
674 * Otherwise we have to compute ue_bot later. | |
675 */ | |
676 else if (bot > curbuf->b_ml.ml_line_count) | |
677 uep->ue_bot = 0; | |
678 else | |
679 { | |
680 uep->ue_lcount = curbuf->b_ml.ml_line_count; | |
681 curbuf->b_u_newhead->uh_getbot_entry = uep; | |
682 } | |
683 | |
168 | 684 if (size > 0) |
7 | 685 { |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
686 if ((uep->ue_array = (undoline_T *)U_ALLOC_LINE( |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
687 sizeof(undoline_T) * size)) == NULL) |
7 | 688 { |
689 u_freeentry(uep, 0L); | |
690 goto nomem; | |
691 } | |
692 for (i = 0, lnum = top + 1; i < size; ++i) | |
693 { | |
481 | 694 fast_breakcheck(); |
695 if (got_int) | |
696 { | |
697 u_freeentry(uep, i); | |
698 return FAIL; | |
699 } | |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
700 if (u_save_line(&uep->ue_array[i], lnum++) == FAIL) |
7 | 701 { |
702 u_freeentry(uep, i); | |
703 goto nomem; | |
704 } | |
705 } | |
706 } | |
359 | 707 else |
708 uep->ue_array = NULL; | |
7 | 709 uep->ue_next = curbuf->b_u_newhead->uh_entry; |
710 curbuf->b_u_newhead->uh_entry = uep; | |
711 curbuf->b_u_synced = FALSE; | |
712 undo_undoes = FALSE; | |
713 | |
1415 | 714 #ifdef U_DEBUG |
715 u_check(FALSE); | |
716 #endif | |
7 | 717 return OK; |
718 | |
719 nomem: | |
720 msg_silent = 0; /* must display the prompt */ | |
721 if (ask_yesno((char_u *)_("No undo possible; continue anyway"), TRUE) | |
722 == 'y') | |
723 { | |
724 undo_off = TRUE; /* will be reset when character typed */ | |
725 return OK; | |
726 } | |
727 do_outofmem_msg((long_u)0); | |
728 return FAIL; | |
729 } | |
730 | |
2266
ae2e615a7320
Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents:
2262
diff
changeset
|
731 #if defined(FEAT_PERSISTENT_UNDO) || defined(PROTO) |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
732 |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
733 # define UF_START_MAGIC "Vim\237UnDo\345" /* magic at start of undofile */ |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
734 # define UF_START_MAGIC_LEN 9 |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
735 # define UF_HEADER_MAGIC 0x5fd0 /* magic at start of header */ |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
736 # define UF_HEADER_END_MAGIC 0xe7aa /* magic after last header */ |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
737 # define UF_ENTRY_MAGIC 0xf518 /* magic at start of entry */ |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
738 # define UF_ENTRY_END_MAGIC 0x3581 /* magic after last entry */ |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
739 # define UF_VERSION 2 /* 2-byte undofile version number */ |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
740 # define UF_VERSION_CRYPT 0x8002 /* idem, encrypted */ |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
741 |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
742 /* extra fields for header */ |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
743 # define UF_LAST_SAVE_NR 1 |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
744 |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
745 /* extra fields for uhp */ |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
746 # define UHP_SAVE_NR 1 |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
747 |
2229
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2223
diff
changeset
|
748 static char_u e_not_open[] = N_("E828: Cannot open undo file for writing: %s"); |
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2223
diff
changeset
|
749 |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
750 /* |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
751 * Compute the hash for the current buffer text into hash[UNDO_HASH_SIZE]. |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
752 */ |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
753 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
754 u_compute_hash(char_u *hash) |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
755 { |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
756 context_sha256_T ctx; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
757 linenr_T lnum; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
758 char_u *p; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
759 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
760 sha256_start(&ctx); |
3194 | 761 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
762 { |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
763 p = ml_get(lnum); |
2217
120502692d82
Improve the MS-Windows installer.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
764 sha256_update(&ctx, p, (UINT32_T)(STRLEN(p) + 1)); |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
765 } |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
766 sha256_finish(&ctx, hash); |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
767 } |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
768 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
769 /* |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
770 * Return an allocated string of the full path of the target undofile. |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
771 * When "reading" is TRUE find the file to read, go over all directories in |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
772 * 'undodir'. |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
773 * When "reading" is FALSE use the first name where the directory exists. |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
774 * Returns NULL when there is no place to write or no file to read. |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
775 */ |
2236
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2235
diff
changeset
|
776 char_u * |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
777 u_get_undo_file_name(char_u *buf_ffname, int reading) |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
778 { |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
779 char_u *dirp; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
780 char_u dir_name[IOSIZE + 1]; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
781 char_u *munged_name = NULL; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
782 char_u *undo_file_name = NULL; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
783 int dir_len; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
784 char_u *p; |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
8568
diff
changeset
|
785 stat_T st; |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
786 char_u *ffname = buf_ffname; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
787 #ifdef HAVE_READLINK |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
788 char_u fname_buf[MAXPATHL]; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
789 #endif |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
790 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
791 if (ffname == NULL) |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
792 return NULL; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
793 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
794 #ifdef HAVE_READLINK |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
795 /* Expand symlink in the file name, so that we put the undo file with the |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
796 * actual file instead of with the symlink. */ |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
797 if (resolve_symlink(ffname, fname_buf) == OK) |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
798 ffname = fname_buf; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
799 #endif |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
800 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
801 /* Loop over 'undodir'. When reading find the first file that exists. |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
802 * When not reading use the first directory that exists or ".". */ |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
803 dirp = p_udir; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
804 while (*dirp != NUL) |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
805 { |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
806 dir_len = copy_option_part(&dirp, dir_name, IOSIZE, ","); |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
807 if (dir_len == 1 && dir_name[0] == '.') |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
808 { |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
809 /* Use same directory as the ffname, |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
810 * "dir/name" -> "dir/.name.un~" */ |
2217
120502692d82
Improve the MS-Windows installer.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
811 undo_file_name = vim_strnsave(ffname, (int)(STRLEN(ffname) + 5)); |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
812 if (undo_file_name == NULL) |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
813 break; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
814 p = gettail(undo_file_name); |
5704 | 815 #ifdef VMS |
816 /* VMS can not handle more than one dot in the filenames | |
817 * use "dir/name" -> "dir/_un_name" - add _un_ | |
818 * at the beginning to keep the extension */ | |
819 mch_memmove(p + 4, p, STRLEN(p) + 1); | |
820 mch_memmove(p, "_un_", 4); | |
821 | |
822 #else | |
823 /* Use same directory as the ffname, | |
824 * "dir/name" -> "dir/.name.un~" */ | |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
825 mch_memmove(p + 1, p, STRLEN(p) + 1); |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
826 *p = '.'; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
827 STRCAT(p, ".un~"); |
5704 | 828 #endif |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
829 } |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
830 else |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
831 { |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
832 dir_name[dir_len] = NUL; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
833 if (mch_isdir(dir_name)) |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
834 { |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
835 if (munged_name == NULL) |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
836 { |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
837 munged_name = vim_strsave(ffname); |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
838 if (munged_name == NULL) |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
839 return NULL; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
840 for (p = munged_name; *p != NUL; MB_PTR_ADV(p)) |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
841 if (vim_ispathsep(*p)) |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
842 *p = '%'; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
843 } |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
844 undo_file_name = concat_fnames(dir_name, munged_name, TRUE); |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
845 } |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
846 } |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
847 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
848 /* When reading check if the file exists. */ |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
849 if (undo_file_name != NULL && (!reading |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
850 || mch_stat((char *)undo_file_name, &st) >= 0)) |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
851 break; |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13138
diff
changeset
|
852 VIM_CLEAR(undo_file_name); |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
853 } |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
854 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
855 vim_free(munged_name); |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
856 return undo_file_name; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
857 } |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
858 |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
859 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
860 corruption_error(char *mesg, char_u *file_name) |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
861 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
862 semsg(_("E825: Corrupted undo file (%s): %s"), mesg, file_name); |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
863 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
864 |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
865 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
866 u_free_uhp(u_header_T *uhp) |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
867 { |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
868 u_entry_T *nuep; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
869 u_entry_T *uep; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
870 |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
871 uep = uhp->uh_entry; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
872 while (uep != NULL) |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
873 { |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
874 nuep = uep->ue_next; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
875 u_freeentry(uep, uep->ue_size); |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
876 uep = nuep; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
877 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
878 vim_free(uhp); |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
879 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
880 |
2266
ae2e615a7320
Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents:
2262
diff
changeset
|
881 /* |
6122 | 882 * Write a sequence of bytes to the undo file. |
883 * Buffers and encrypts as needed. | |
884 * Returns OK or FAIL. | |
2266
ae2e615a7320
Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents:
2262
diff
changeset
|
885 */ |
6122 | 886 static int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
887 undo_write(bufinfo_T *bi, char_u *ptr, size_t len) |
6122 | 888 { |
889 #ifdef FEAT_CRYPT | |
890 if (bi->bi_buffer != NULL) | |
891 { | |
892 size_t len_todo = len; | |
893 char_u *p = ptr; | |
894 | |
895 while (bi->bi_used + len_todo >= CRYPT_BUF_SIZE) | |
896 { | |
897 size_t n = CRYPT_BUF_SIZE - bi->bi_used; | |
898 | |
899 mch_memmove(bi->bi_buffer + bi->bi_used, p, n); | |
900 len_todo -= n; | |
901 p += n; | |
902 bi->bi_used = CRYPT_BUF_SIZE; | |
903 if (undo_flush(bi) == FAIL) | |
904 return FAIL; | |
905 } | |
906 if (len_todo > 0) | |
907 { | |
908 mch_memmove(bi->bi_buffer + bi->bi_used, p, len_todo); | |
909 bi->bi_used += len_todo; | |
910 } | |
911 return OK; | |
912 } | |
913 #endif | |
914 if (fwrite(ptr, len, (size_t)1, bi->bi_fp) != 1) | |
915 return FAIL; | |
916 return OK; | |
917 } | |
918 | |
919 #ifdef FEAT_CRYPT | |
920 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
921 undo_flush(bufinfo_T *bi) |
6122 | 922 { |
12216
e971ef6c0dee
patch 8.0.0988: warning from Covscan about using NULL pointer
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
923 if (bi->bi_buffer != NULL && bi->bi_state != NULL && bi->bi_used > 0) |
6122 | 924 { |
925 crypt_encode_inplace(bi->bi_state, bi->bi_buffer, bi->bi_used); | |
926 if (fwrite(bi->bi_buffer, bi->bi_used, (size_t)1, bi->bi_fp) != 1) | |
927 return FAIL; | |
928 bi->bi_used = 0; | |
929 } | |
930 return OK; | |
931 } | |
932 #endif | |
933 | |
934 /* | |
935 * Write "ptr[len]" and crypt the bytes when needed. | |
936 * Returns OK or FAIL. | |
937 */ | |
938 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
939 fwrite_crypt(bufinfo_T *bi, char_u *ptr, size_t len) |
2266
ae2e615a7320
Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents:
2262
diff
changeset
|
940 { |
ae2e615a7320
Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents:
2262
diff
changeset
|
941 #ifdef FEAT_CRYPT |
ae2e615a7320
Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents:
2262
diff
changeset
|
942 char_u *copy; |
ae2e615a7320
Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents:
2262
diff
changeset
|
943 char_u small_buf[100]; |
ae2e615a7320
Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents:
2262
diff
changeset
|
944 size_t i; |
ae2e615a7320
Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents:
2262
diff
changeset
|
945 |
6122 | 946 if (bi->bi_state != NULL && bi->bi_buffer == NULL) |
2266
ae2e615a7320
Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents:
2262
diff
changeset
|
947 { |
6122 | 948 /* crypting every piece of text separately */ |
949 if (len < 100) | |
950 copy = small_buf; /* no malloc()/free() for short strings */ | |
951 else | |
952 { | |
953 copy = lalloc(len, FALSE); | |
954 if (copy == NULL) | |
955 return 0; | |
956 } | |
957 crypt_encode(bi->bi_state, ptr, len, copy); | |
958 i = fwrite(copy, len, (size_t)1, bi->bi_fp); | |
959 if (copy != small_buf) | |
960 vim_free(copy); | |
961 return i == 1 ? OK : FAIL; | |
2266
ae2e615a7320
Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents:
2262
diff
changeset
|
962 } |
ae2e615a7320
Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents:
2262
diff
changeset
|
963 #endif |
6122 | 964 return undo_write(bi, ptr, len); |
965 } | |
966 | |
967 /* | |
968 * Write a number, MSB first, in "len" bytes. | |
969 * Must match with undo_read_?c() functions. | |
970 * Returns OK or FAIL. | |
971 */ | |
972 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
973 undo_write_bytes(bufinfo_T *bi, long_u nr, int len) |
6122 | 974 { |
975 char_u buf[8]; | |
976 int i; | |
977 int bufi = 0; | |
978 | |
979 for (i = len - 1; i >= 0; --i) | |
6132 | 980 buf[bufi++] = (char_u)(nr >> (i * 8)); |
6122 | 981 return undo_write(bi, buf, (size_t)len); |
2266
ae2e615a7320
Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents:
2262
diff
changeset
|
982 } |
ae2e615a7320
Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents:
2262
diff
changeset
|
983 |
ae2e615a7320
Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents:
2262
diff
changeset
|
984 /* |
6122 | 985 * Write the pointer to an undo header. Instead of writing the pointer itself |
986 * we use the sequence number of the header. This is converted back to | |
987 * pointers when reading. */ | |
988 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
989 put_header_ptr(bufinfo_T *bi, u_header_T *uhp) |
6122 | 990 { |
991 undo_write_bytes(bi, (long_u)(uhp != NULL ? uhp->uh_seq : 0), 4); | |
992 } | |
993 | |
994 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
995 undo_read_4c(bufinfo_T *bi) |
2266
ae2e615a7320
Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents:
2262
diff
changeset
|
996 { |
ae2e615a7320
Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents:
2262
diff
changeset
|
997 #ifdef FEAT_CRYPT |
6122 | 998 if (bi->bi_buffer != NULL) |
999 { | |
1000 char_u buf[4]; | |
1001 int n; | |
1002 | |
1003 undo_read(bi, buf, (size_t)4); | |
6216 | 1004 n = ((unsigned)buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + buf[3]; |
6122 | 1005 return n; |
1006 } | |
2266
ae2e615a7320
Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents:
2262
diff
changeset
|
1007 #endif |
6122 | 1008 return get4c(bi->bi_fp); |
1009 } | |
1010 | |
1011 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1012 undo_read_2c(bufinfo_T *bi) |
6122 | 1013 { |
1014 #ifdef FEAT_CRYPT | |
1015 if (bi->bi_buffer != NULL) | |
1016 { | |
1017 char_u buf[2]; | |
1018 int n; | |
1019 | |
1020 undo_read(bi, buf, (size_t)2); | |
1021 n = (buf[0] << 8) + buf[1]; | |
1022 return n; | |
1023 } | |
1024 #endif | |
1025 return get2c(bi->bi_fp); | |
2266
ae2e615a7320
Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents:
2262
diff
changeset
|
1026 } |
ae2e615a7320
Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents:
2262
diff
changeset
|
1027 |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1028 static int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1029 undo_read_byte(bufinfo_T *bi) |
6122 | 1030 { |
1031 #ifdef FEAT_CRYPT | |
1032 if (bi->bi_buffer != NULL) | |
1033 { | |
1034 char_u buf[1]; | |
1035 | |
1036 undo_read(bi, buf, (size_t)1); | |
1037 return buf[0]; | |
1038 } | |
1039 #endif | |
1040 return getc(bi->bi_fp); | |
1041 } | |
1042 | |
1043 static time_t | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1044 undo_read_time(bufinfo_T *bi) |
6122 | 1045 { |
1046 #ifdef FEAT_CRYPT | |
1047 if (bi->bi_buffer != NULL) | |
1048 { | |
1049 char_u buf[8]; | |
1050 time_t n = 0; | |
1051 int i; | |
1052 | |
1053 undo_read(bi, buf, (size_t)8); | |
1054 for (i = 0; i < 8; ++i) | |
1055 n = (n << 8) + buf[i]; | |
1056 return n; | |
1057 } | |
1058 #endif | |
1059 return get8ctime(bi->bi_fp); | |
1060 } | |
1061 | |
1062 /* | |
1063 * Read "buffer[size]" from the undo file. | |
1064 * Return OK or FAIL. | |
1065 */ | |
1066 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1067 undo_read(bufinfo_T *bi, char_u *buffer, size_t size) |
6122 | 1068 { |
11506
7140ff4857eb
patch 8.0.0636: when reading the undo file fails may use uninitialized data
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1069 int retval = OK; |
7140ff4857eb
patch 8.0.0636: when reading the undo file fails may use uninitialized data
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1070 |
6122 | 1071 #ifdef FEAT_CRYPT |
1072 if (bi->bi_buffer != NULL) | |
1073 { | |
6132 | 1074 int size_todo = (int)size; |
6122 | 1075 char_u *p = buffer; |
1076 | |
1077 while (size_todo > 0) | |
1078 { | |
1079 size_t n; | |
1080 | |
1081 if (bi->bi_used >= bi->bi_avail) | |
1082 { | |
1083 n = fread(bi->bi_buffer, 1, (size_t)CRYPT_BUF_SIZE, bi->bi_fp); | |
10336
9d282593ba24
commit https://github.com/vim/vim/commit/55952d4dd490bb2f63bda5d7f6d8fb69f58c333c
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1084 if (n == 0) |
6122 | 1085 { |
11506
7140ff4857eb
patch 8.0.0636: when reading the undo file fails may use uninitialized data
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1086 retval = FAIL; |
7140ff4857eb
patch 8.0.0636: when reading the undo file fails may use uninitialized data
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1087 break; |
6122 | 1088 } |
1089 bi->bi_avail = n; | |
1090 bi->bi_used = 0; | |
1091 crypt_decode_inplace(bi->bi_state, bi->bi_buffer, bi->bi_avail); | |
1092 } | |
1093 n = size_todo; | |
1094 if (n > bi->bi_avail - bi->bi_used) | |
1095 n = bi->bi_avail - bi->bi_used; | |
1096 mch_memmove(p, bi->bi_buffer + bi->bi_used, n); | |
1097 bi->bi_used += n; | |
6132 | 1098 size_todo -= (int)n; |
6122 | 1099 p += n; |
1100 } | |
1101 } | |
11506
7140ff4857eb
patch 8.0.0636: when reading the undo file fails may use uninitialized data
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1102 else |
6122 | 1103 #endif |
1104 if (fread(buffer, (size_t)size, 1, bi->bi_fp) != 1) | |
11506
7140ff4857eb
patch 8.0.0636: when reading the undo file fails may use uninitialized data
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1105 retval = FAIL; |
7140ff4857eb
patch 8.0.0636: when reading the undo file fails may use uninitialized data
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1106 |
7140ff4857eb
patch 8.0.0636: when reading the undo file fails may use uninitialized data
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1107 if (retval == FAIL) |
7140ff4857eb
patch 8.0.0636: when reading the undo file fails may use uninitialized data
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1108 /* Error may be checked for only later. Fill with zeros, |
7140ff4857eb
patch 8.0.0636: when reading the undo file fails may use uninitialized data
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1109 * so that the reader won't use garbage. */ |
7140ff4857eb
patch 8.0.0636: when reading the undo file fails may use uninitialized data
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1110 vim_memset(buffer, 0, size); |
7140ff4857eb
patch 8.0.0636: when reading the undo file fails may use uninitialized data
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1111 return retval; |
6122 | 1112 } |
1113 | |
1114 /* | |
1115 * Read a string of length "len" from "bi->bi_fd". | |
1116 * "len" can be zero to allocate an empty line. | |
1117 * Decrypt the bytes if needed. | |
1118 * Append a NUL. | |
1119 * Returns a pointer to allocated memory or NULL for failure. | |
1120 */ | |
1121 static char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1122 read_string_decrypt(bufinfo_T *bi, int len) |
6122 | 1123 { |
1124 char_u *ptr = alloc((unsigned)len + 1); | |
1125 | |
1126 if (ptr != NULL) | |
1127 { | |
1128 if (len > 0 && undo_read(bi, ptr, len) == FAIL) | |
1129 { | |
1130 vim_free(ptr); | |
1131 return NULL; | |
1132 } | |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1133 // In case there are text properties there already is a NUL, but |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1134 // checking for that is more expensive than just adding a dummy byte. |
6122 | 1135 ptr[len] = NUL; |
1136 #ifdef FEAT_CRYPT | |
1137 if (bi->bi_state != NULL && bi->bi_buffer == NULL) | |
1138 crypt_decode_inplace(bi->bi_state, ptr, len); | |
1139 #endif | |
1140 } | |
1141 return ptr; | |
1142 } | |
1143 | |
1144 /* | |
1145 * Writes the (not encrypted) header and initializes encryption if needed. | |
1146 */ | |
1147 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1148 serialize_header(bufinfo_T *bi, char_u *hash) |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1149 { |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1150 long len; |
6122 | 1151 buf_T *buf = bi->bi_buf; |
1152 FILE *fp = bi->bi_fp; | |
1153 char_u time_buf[8]; | |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1154 |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1155 /* Start writing, first the magic marker and undo info version. */ |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1156 if (fwrite(UF_START_MAGIC, (size_t)UF_START_MAGIC_LEN, (size_t)1, fp) != 1) |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1157 return FAIL; |
2239
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
1158 |
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
1159 /* If the buffer is encrypted then all text bytes following will be |
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
1160 * encrypted. Numbers and other info is not crypted. */ |
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
1161 #ifdef FEAT_CRYPT |
2410
8f6106dd3d12
Fix: editing a not encrypted file after a crypted file messed up reading the
Bram Moolenaar <bram@vim.org>
parents:
2394
diff
changeset
|
1162 if (*buf->b_p_key != NUL) |
2239
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
1163 { |
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
1164 char_u *header; |
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
1165 int header_len; |
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
1166 |
6122 | 1167 undo_write_bytes(bi, (long_u)UF_VERSION_CRYPT, 2); |
1168 bi->bi_state = crypt_create_for_writing(crypt_get_method_nr(buf), | |
1169 buf->b_p_key, &header, &header_len); | |
1170 if (bi->bi_state == NULL) | |
2239
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
1171 return FAIL; |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1172 len = (long)fwrite(header, (size_t)header_len, (size_t)1, fp); |
2239
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
1173 vim_free(header); |
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
1174 if (len != 1) |
2267 | 1175 { |
6122 | 1176 crypt_free_state(bi->bi_state); |
1177 bi->bi_state = NULL; | |
2239
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
1178 return FAIL; |
2267 | 1179 } |
6122 | 1180 |
1181 if (crypt_whole_undofile(crypt_get_method_nr(buf))) | |
1182 { | |
1183 bi->bi_buffer = alloc(CRYPT_BUF_SIZE); | |
1184 if (bi->bi_buffer == NULL) | |
1185 { | |
1186 crypt_free_state(bi->bi_state); | |
1187 bi->bi_state = NULL; | |
1188 return FAIL; | |
1189 } | |
1190 bi->bi_used = 0; | |
1191 } | |
2239
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
1192 } |
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
1193 else |
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
1194 #endif |
6122 | 1195 undo_write_bytes(bi, (long_u)UF_VERSION, 2); |
2239
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
1196 |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1197 |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1198 /* Write a hash of the buffer text, so that we can verify it is still the |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1199 * same when reading the buffer text. */ |
6122 | 1200 if (undo_write(bi, hash, (size_t)UNDO_HASH_SIZE) == FAIL) |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1201 return FAIL; |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1202 |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1203 /* buffer-specific data */ |
6122 | 1204 undo_write_bytes(bi, (long_u)buf->b_ml.ml_line_count, 4); |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1205 len = buf->b_u_line_ptr.ul_line == NULL |
15390
00aa76a735e7
patch 8.1.0703: compiler warnings with 64-bit compiler
Bram Moolenaar <Bram@vim.org>
parents:
15361
diff
changeset
|
1206 ? 0L : (long)STRLEN(buf->b_u_line_ptr.ul_line); |
6122 | 1207 undo_write_bytes(bi, (long_u)len, 4); |
15390
00aa76a735e7
patch 8.1.0703: compiler warnings with 64-bit compiler
Bram Moolenaar <Bram@vim.org>
parents:
15361
diff
changeset
|
1208 if (len > 0 && fwrite_crypt(bi, buf->b_u_line_ptr.ul_line, (size_t)len) |
00aa76a735e7
patch 8.1.0703: compiler warnings with 64-bit compiler
Bram Moolenaar <Bram@vim.org>
parents:
15361
diff
changeset
|
1209 == FAIL) |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1210 return FAIL; |
6122 | 1211 undo_write_bytes(bi, (long_u)buf->b_u_line_lnum, 4); |
1212 undo_write_bytes(bi, (long_u)buf->b_u_line_colnr, 4); | |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1213 |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1214 /* Undo structures header data */ |
6122 | 1215 put_header_ptr(bi, buf->b_u_oldhead); |
1216 put_header_ptr(bi, buf->b_u_newhead); | |
1217 put_header_ptr(bi, buf->b_u_curhead); | |
1218 | |
1219 undo_write_bytes(bi, (long_u)buf->b_u_numhead, 4); | |
1220 undo_write_bytes(bi, (long_u)buf->b_u_seq_last, 4); | |
1221 undo_write_bytes(bi, (long_u)buf->b_u_seq_cur, 4); | |
1222 time_to_bytes(buf->b_u_time_cur, time_buf); | |
1223 undo_write(bi, time_buf, 8); | |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
1224 |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
1225 /* Optional fields. */ |
6122 | 1226 undo_write_bytes(bi, 4, 1); |
1227 undo_write_bytes(bi, UF_LAST_SAVE_NR, 1); | |
1228 undo_write_bytes(bi, (long_u)buf->b_u_save_nr_last, 4); | |
1229 | |
1230 undo_write_bytes(bi, 0, 1); /* end marker */ | |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1231 |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1232 return OK; |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1233 } |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1234 |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1235 static int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1236 serialize_uhp(bufinfo_T *bi, u_header_T *uhp) |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1237 { |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1238 int i; |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1239 u_entry_T *uep; |
6122 | 1240 char_u time_buf[8]; |
1241 | |
1242 if (undo_write_bytes(bi, (long_u)UF_HEADER_MAGIC, 2) == FAIL) | |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1243 return FAIL; |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1244 |
6122 | 1245 put_header_ptr(bi, uhp->uh_next.ptr); |
1246 put_header_ptr(bi, uhp->uh_prev.ptr); | |
1247 put_header_ptr(bi, uhp->uh_alt_next.ptr); | |
1248 put_header_ptr(bi, uhp->uh_alt_prev.ptr); | |
1249 undo_write_bytes(bi, uhp->uh_seq, 4); | |
1250 serialize_pos(bi, uhp->uh_cursor); | |
1251 undo_write_bytes(bi, (long_u)uhp->uh_cursor_vcol, 4); | |
1252 undo_write_bytes(bi, (long_u)uhp->uh_flags, 2); | |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1253 /* Assume NMARKS will stay the same. */ |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1254 for (i = 0; i < NMARKS; ++i) |
6122 | 1255 serialize_pos(bi, uhp->uh_namedm[i]); |
1256 serialize_visualinfo(bi, &uhp->uh_visual); | |
1257 time_to_bytes(uhp->uh_time, time_buf); | |
1258 undo_write(bi, time_buf, 8); | |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1259 |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
1260 /* Optional fields. */ |
6122 | 1261 undo_write_bytes(bi, 4, 1); |
1262 undo_write_bytes(bi, UHP_SAVE_NR, 1); | |
1263 undo_write_bytes(bi, (long_u)uhp->uh_save_nr, 4); | |
1264 | |
1265 undo_write_bytes(bi, 0, 1); /* end marker */ | |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
1266 |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1267 /* Write all the entries. */ |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1268 for (uep = uhp->uh_entry; uep != NULL; uep = uep->ue_next) |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1269 { |
6122 | 1270 undo_write_bytes(bi, (long_u)UF_ENTRY_MAGIC, 2); |
1271 if (serialize_uep(bi, uep) == FAIL) | |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1272 return FAIL; |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1273 } |
6122 | 1274 undo_write_bytes(bi, (long_u)UF_ENTRY_END_MAGIC, 2); |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1275 return OK; |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1276 } |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1277 |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1278 static u_header_T * |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1279 unserialize_uhp(bufinfo_T *bi, char_u *file_name) |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1280 { |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1281 u_header_T *uhp; |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1282 int i; |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1283 u_entry_T *uep, *last_uep; |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1284 int c; |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1285 int error; |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1286 |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1287 uhp = (u_header_T *)U_ALLOC_LINE(sizeof(u_header_T)); |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1288 if (uhp == NULL) |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1289 return NULL; |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1290 vim_memset(uhp, 0, sizeof(u_header_T)); |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1291 #ifdef U_DEBUG |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1292 uhp->uh_magic = UH_MAGIC; |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1293 #endif |
6122 | 1294 uhp->uh_next.seq = undo_read_4c(bi); |
1295 uhp->uh_prev.seq = undo_read_4c(bi); | |
1296 uhp->uh_alt_next.seq = undo_read_4c(bi); | |
1297 uhp->uh_alt_prev.seq = undo_read_4c(bi); | |
1298 uhp->uh_seq = undo_read_4c(bi); | |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1299 if (uhp->uh_seq <= 0) |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1300 { |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1301 corruption_error("uh_seq", file_name); |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1302 vim_free(uhp); |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1303 return NULL; |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1304 } |
6122 | 1305 unserialize_pos(bi, &uhp->uh_cursor); |
1306 uhp->uh_cursor_vcol = undo_read_4c(bi); | |
1307 uhp->uh_flags = undo_read_2c(bi); | |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1308 for (i = 0; i < NMARKS; ++i) |
6122 | 1309 unserialize_pos(bi, &uhp->uh_namedm[i]); |
1310 unserialize_visualinfo(bi, &uhp->uh_visual); | |
1311 uhp->uh_time = undo_read_time(bi); | |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1312 |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
1313 /* Optional fields. */ |
2342
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1314 for (;;) |
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1315 { |
6122 | 1316 int len = undo_read_byte(bi); |
2342
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1317 int what; |
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1318 |
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1319 if (len == 0) |
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1320 break; |
6122 | 1321 what = undo_read_byte(bi); |
2342
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1322 switch (what) |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
1323 { |
2342
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1324 case UHP_SAVE_NR: |
6122 | 1325 uhp->uh_save_nr = undo_read_4c(bi); |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
1326 break; |
2342
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1327 default: |
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1328 /* field not supported, skip */ |
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1329 while (--len >= 0) |
6122 | 1330 (void)undo_read_byte(bi); |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
1331 } |
2342
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1332 } |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
1333 |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1334 /* Unserialize the uep list. */ |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1335 last_uep = NULL; |
6122 | 1336 while ((c = undo_read_2c(bi)) == UF_ENTRY_MAGIC) |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1337 { |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1338 error = FALSE; |
6122 | 1339 uep = unserialize_uep(bi, &error, file_name); |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1340 if (last_uep == NULL) |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1341 uhp->uh_entry = uep; |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1342 else |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1343 last_uep->ue_next = uep; |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1344 last_uep = uep; |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1345 if (uep == NULL || error) |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1346 { |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1347 u_free_uhp(uhp); |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1348 return NULL; |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1349 } |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1350 } |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1351 if (c != UF_ENTRY_END_MAGIC) |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1352 { |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1353 corruption_error("entry end", file_name); |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1354 u_free_uhp(uhp); |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1355 return NULL; |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1356 } |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1357 |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1358 return uhp; |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1359 } |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1360 |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1361 /* |
6122 | 1362 * Serialize "uep". |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1363 */ |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1364 static int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1365 serialize_uep( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1366 bufinfo_T *bi, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1367 u_entry_T *uep) |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1368 { |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1369 int i; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1370 size_t len; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1371 |
6122 | 1372 undo_write_bytes(bi, (long_u)uep->ue_top, 4); |
1373 undo_write_bytes(bi, (long_u)uep->ue_bot, 4); | |
1374 undo_write_bytes(bi, (long_u)uep->ue_lcount, 4); | |
1375 undo_write_bytes(bi, (long_u)uep->ue_size, 4); | |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1376 for (i = 0; i < uep->ue_size; ++i) |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1377 { |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1378 // Text is written without the text properties, since we cannot restore |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1379 // the text property types. |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1380 len = STRLEN(uep->ue_array[i].ul_line); |
6122 | 1381 if (undo_write_bytes(bi, (long_u)len, 4) == FAIL) |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1382 return FAIL; |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1383 if (len > 0 && fwrite_crypt(bi, uep->ue_array[i].ul_line, len) == FAIL) |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1384 return FAIL; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1385 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1386 return OK; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1387 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1388 |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1389 static u_entry_T * |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1390 unserialize_uep(bufinfo_T *bi, int *error, char_u *file_name) |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1391 { |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1392 int i; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1393 u_entry_T *uep; |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1394 undoline_T *array = NULL; |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1395 char_u *line; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1396 int line_len; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1397 |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1398 uep = (u_entry_T *)U_ALLOC_LINE(sizeof(u_entry_T)); |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1399 if (uep == NULL) |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1400 return NULL; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1401 vim_memset(uep, 0, sizeof(u_entry_T)); |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1402 #ifdef U_DEBUG |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1403 uep->ue_magic = UE_MAGIC; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1404 #endif |
6122 | 1405 uep->ue_top = undo_read_4c(bi); |
1406 uep->ue_bot = undo_read_4c(bi); | |
1407 uep->ue_lcount = undo_read_4c(bi); | |
1408 uep->ue_size = undo_read_4c(bi); | |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1409 if (uep->ue_size > 0) |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1410 { |
10978
f3d64d9e5d76
patch 8.0.0378: possible overflow when reading corrupted undo file
Christian Brabandt <cb@256bit.org>
parents:
10976
diff
changeset
|
1411 if (uep->ue_size < LONG_MAX / (int)sizeof(char_u *)) |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1412 array = (undoline_T *)U_ALLOC_LINE(sizeof(undoline_T) * uep->ue_size); |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1413 if (array == NULL) |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1414 { |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1415 *error = TRUE; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1416 return uep; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1417 } |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1418 vim_memset(array, 0, sizeof(undoline_T) * uep->ue_size); |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1419 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1420 uep->ue_array = array; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1421 |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1422 for (i = 0; i < uep->ue_size; ++i) |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1423 { |
6122 | 1424 line_len = undo_read_4c(bi); |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1425 if (line_len >= 0) |
6122 | 1426 line = read_string_decrypt(bi, line_len); |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1427 else |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1428 { |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1429 line = NULL; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1430 corruption_error("line length", file_name); |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1431 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1432 if (line == NULL) |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1433 { |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1434 *error = TRUE; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1435 return uep; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1436 } |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1437 array[i].ul_line = line; |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1438 array[i].ul_len = line_len + 1; |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1439 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1440 return uep; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1441 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1442 |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1443 /* |
6122 | 1444 * Serialize "pos". |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1445 */ |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1446 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1447 serialize_pos(bufinfo_T *bi, pos_T pos) |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1448 { |
6122 | 1449 undo_write_bytes(bi, (long_u)pos.lnum, 4); |
1450 undo_write_bytes(bi, (long_u)pos.col, 4); | |
1451 undo_write_bytes(bi, (long_u)pos.coladd, 4); | |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1452 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1453 |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1454 /* |
6122 | 1455 * Unserialize the pos_T at the current position. |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1456 */ |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1457 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1458 unserialize_pos(bufinfo_T *bi, pos_T *pos) |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1459 { |
6122 | 1460 pos->lnum = undo_read_4c(bi); |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1461 if (pos->lnum < 0) |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1462 pos->lnum = 0; |
6122 | 1463 pos->col = undo_read_4c(bi); |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1464 if (pos->col < 0) |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1465 pos->col = 0; |
6122 | 1466 pos->coladd = undo_read_4c(bi); |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1467 if (pos->coladd < 0) |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1468 pos->coladd = 0; |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1469 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1470 |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1471 /* |
6122 | 1472 * Serialize "info". |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1473 */ |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1474 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1475 serialize_visualinfo(bufinfo_T *bi, visualinfo_T *info) |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1476 { |
6122 | 1477 serialize_pos(bi, info->vi_start); |
1478 serialize_pos(bi, info->vi_end); | |
1479 undo_write_bytes(bi, (long_u)info->vi_mode, 4); | |
1480 undo_write_bytes(bi, (long_u)info->vi_curswant, 4); | |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1481 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1482 |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1483 /* |
6122 | 1484 * Unserialize the visualinfo_T at the current position. |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1485 */ |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1486 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1487 unserialize_visualinfo(bufinfo_T *bi, visualinfo_T *info) |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1488 { |
6122 | 1489 unserialize_pos(bi, &info->vi_start); |
1490 unserialize_pos(bi, &info->vi_end); | |
1491 info->vi_mode = undo_read_4c(bi); | |
1492 info->vi_curswant = undo_read_4c(bi); | |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1493 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1494 |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1495 /* |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1496 * Write the undo tree in an undo file. |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1497 * When "name" is not NULL, use it as the name of the undo file. |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1498 * Otherwise use buf->b_ffname to generate the undo file name. |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1499 * "buf" must never be null, buf->b_ffname is used to obtain the original file |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1500 * permissions. |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1501 * "forceit" is TRUE for ":wundo!", FALSE otherwise. |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1502 * "hash[UNDO_HASH_SIZE]" must be the hash value of the buffer text. |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1503 */ |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1504 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1505 u_write_undo( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1506 char_u *name, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1507 int forceit, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1508 buf_T *buf, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1509 char_u *hash) |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1510 { |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1511 u_header_T *uhp; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1512 char_u *file_name; |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1513 int mark; |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1514 #ifdef U_DEBUG |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1515 int headers_written = 0; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1516 #endif |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1517 int fd; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1518 FILE *fp = NULL; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1519 int perm; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1520 int write_ok = FALSE; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1521 #ifdef UNIX |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1522 int st_old_valid = FALSE; |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
8568
diff
changeset
|
1523 stat_T st_old; |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
8568
diff
changeset
|
1524 stat_T st_new; |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1525 #endif |
6122 | 1526 bufinfo_T bi; |
1527 | |
6128 | 1528 vim_memset(&bi, 0, sizeof(bi)); |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1529 |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1530 if (name == NULL) |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1531 { |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1532 file_name = u_get_undo_file_name(buf->b_ffname, FALSE); |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1533 if (file_name == NULL) |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1534 { |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1535 if (p_verbose > 0) |
2235
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1536 { |
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1537 verbose_enter(); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
1538 smsg( |
2235
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1539 _("Cannot write undo file in any directory in 'undodir'")); |
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1540 verbose_leave(); |
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1541 } |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1542 return; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1543 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1544 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1545 else |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1546 file_name = name; |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1547 |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1548 /* |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1549 * Decide about the permission to use for the undo file. If the buffer |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1550 * has a name use the permission of the original file. Otherwise only |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1551 * allow the user to access the undo file. |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1552 */ |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1553 perm = 0600; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1554 if (buf->b_ffname != NULL) |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1555 { |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1556 #ifdef UNIX |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1557 if (mch_stat((char *)buf->b_ffname, &st_old) >= 0) |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1558 { |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1559 perm = st_old.st_mode; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1560 st_old_valid = TRUE; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1561 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1562 #else |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1563 perm = mch_getperm(buf->b_ffname); |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1564 if (perm < 0) |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1565 perm = 0600; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1566 #endif |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1567 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1568 |
6771 | 1569 /* strip any s-bit and executable bit */ |
1570 perm = perm & 0666; | |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1571 |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1572 /* If the undo file already exists, verify that it actually is an undo |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1573 * file, and delete it. */ |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1574 if (mch_getperm(file_name) >= 0) |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1575 { |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1576 if (name == NULL || !forceit) |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1577 { |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1578 /* Check we can read it and it's an undo file. */ |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1579 fd = mch_open((char *)file_name, O_RDONLY|O_EXTRA, 0); |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1580 if (fd < 0) |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1581 { |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1582 if (name != NULL || p_verbose > 0) |
2235
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1583 { |
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1584 if (name == NULL) |
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1585 verbose_enter(); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
1586 smsg( |
2235
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1587 _("Will not overwrite with undo file, cannot read: %s"), |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1588 file_name); |
2235
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1589 if (name == NULL) |
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1590 verbose_leave(); |
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1591 } |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1592 goto theend; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1593 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1594 else |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1595 { |
2271
2b33a7678e7b
Fix compiler warnings for shadowed variables. Make 'conceal' a long instead
Bram Moolenaar <bram@vim.org>
parents:
2267
diff
changeset
|
1596 char_u mbuf[UF_START_MAGIC_LEN]; |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1597 int len; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1598 |
2664 | 1599 len = read_eintr(fd, mbuf, UF_START_MAGIC_LEN); |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1600 close(fd); |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1601 if (len < UF_START_MAGIC_LEN |
2271
2b33a7678e7b
Fix compiler warnings for shadowed variables. Make 'conceal' a long instead
Bram Moolenaar <bram@vim.org>
parents:
2267
diff
changeset
|
1602 || memcmp(mbuf, UF_START_MAGIC, UF_START_MAGIC_LEN) != 0) |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1603 { |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1604 if (name != NULL || p_verbose > 0) |
2235
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1605 { |
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1606 if (name == NULL) |
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1607 verbose_enter(); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
1608 smsg( |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1609 _("Will not overwrite, this is not an undo file: %s"), |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1610 file_name); |
2235
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1611 if (name == NULL) |
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1612 verbose_leave(); |
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1613 } |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1614 goto theend; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1615 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1616 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1617 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1618 mch_remove(file_name); |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1619 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1620 |
2235
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1621 /* If there is no undo information at all, quit here after deleting any |
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1622 * existing undo file. */ |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1623 if (buf->b_u_numhead == 0 && buf->b_u_line_ptr.ul_line == NULL) |
2235
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1624 { |
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1625 if (p_verbose > 0) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1626 verb_msg(_("Skipping undo file write, nothing to undo")); |
2235
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1627 goto theend; |
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1628 } |
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1629 |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1630 fd = mch_open((char *)file_name, |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1631 O_CREAT|O_EXTRA|O_WRONLY|O_EXCL|O_NOFOLLOW, perm); |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1632 if (fd < 0) |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1633 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
1634 semsg(_(e_not_open), file_name); |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1635 goto theend; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1636 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1637 (void)mch_setperm(file_name, perm); |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1638 if (p_verbose > 0) |
2235
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1639 { |
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1640 verbose_enter(); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
1641 smsg(_("Writing undo file: %s"), file_name); |
2235
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1642 verbose_leave(); |
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1643 } |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1644 |
2233
43cad213cb7f
A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents:
2232
diff
changeset
|
1645 #ifdef U_DEBUG |
2235
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1646 /* Check there is no problem in undo info before writing. */ |
2233
43cad213cb7f
A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents:
2232
diff
changeset
|
1647 u_check(FALSE); |
43cad213cb7f
A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents:
2232
diff
changeset
|
1648 #endif |
43cad213cb7f
A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents:
2232
diff
changeset
|
1649 |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1650 #ifdef UNIX |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1651 /* |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1652 * Try to set the group of the undo file same as the original file. If |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1653 * this fails, set the protection bits for the group same as the |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1654 * protection bits for others. |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1655 */ |
2367
76b7ba68a098
Fix build problem when fchown() not available. (Gary Johnson)
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
1656 if (st_old_valid |
76b7ba68a098
Fix build problem when fchown() not available. (Gary Johnson)
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
1657 && mch_stat((char *)file_name, &st_new) >= 0 |
76b7ba68a098
Fix build problem when fchown() not available. (Gary Johnson)
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
1658 && st_new.st_gid != st_old.st_gid |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1659 # ifdef HAVE_FCHOWN /* sequent-ptx lacks fchown() */ |
2367
76b7ba68a098
Fix build problem when fchown() not available. (Gary Johnson)
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
1660 && fchown(fd, (uid_t)-1, st_old.st_gid) != 0 |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1661 # endif |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1662 ) |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1663 mch_setperm(file_name, (perm & 0707) | ((perm & 07) << 3)); |
5788 | 1664 # if defined(HAVE_SELINUX) || defined(HAVE_SMACK) |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1665 if (buf->b_ffname != NULL) |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1666 mch_copy_sec(buf->b_ffname, file_name); |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1667 # endif |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1668 #endif |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1669 |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1670 fp = fdopen(fd, "w"); |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1671 if (fp == NULL) |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1672 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
1673 semsg(_(e_not_open), file_name); |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1674 close(fd); |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1675 mch_remove(file_name); |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1676 goto theend; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1677 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1678 |
2233
43cad213cb7f
A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents:
2232
diff
changeset
|
1679 /* Undo must be synced. */ |
43cad213cb7f
A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents:
2232
diff
changeset
|
1680 u_sync(TRUE); |
43cad213cb7f
A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents:
2232
diff
changeset
|
1681 |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1682 /* |
6122 | 1683 * Write the header. Initializes encryption, if enabled. |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1684 */ |
6122 | 1685 bi.bi_buf = buf; |
1686 bi.bi_fp = fp; | |
1687 if (serialize_header(&bi, hash) == FAIL) | |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1688 goto write_error; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1689 |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1690 /* |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1691 * Iteratively serialize UHPs and their UEPs from the top down. |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1692 */ |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1693 mark = ++lastmark; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1694 uhp = buf->b_u_oldhead; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1695 while (uhp != NULL) |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1696 { |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1697 /* Serialize current UHP if we haven't seen it */ |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1698 if (uhp->uh_walk != mark) |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1699 { |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1700 uhp->uh_walk = mark; |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1701 #ifdef U_DEBUG |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1702 ++headers_written; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1703 #endif |
6122 | 1704 if (serialize_uhp(&bi, uhp) == FAIL) |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1705 goto write_error; |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1706 } |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1707 |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1708 /* Now walk through the tree - algorithm from undo_time(). */ |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1709 if (uhp->uh_prev.ptr != NULL && uhp->uh_prev.ptr->uh_walk != mark) |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1710 uhp = uhp->uh_prev.ptr; |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1711 else if (uhp->uh_alt_next.ptr != NULL |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
1712 && uhp->uh_alt_next.ptr->uh_walk != mark) |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1713 uhp = uhp->uh_alt_next.ptr; |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1714 else if (uhp->uh_next.ptr != NULL && uhp->uh_alt_prev.ptr == NULL |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
1715 && uhp->uh_next.ptr->uh_walk != mark) |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1716 uhp = uhp->uh_next.ptr; |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1717 else if (uhp->uh_alt_prev.ptr != NULL) |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1718 uhp = uhp->uh_alt_prev.ptr; |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1719 else |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1720 uhp = uhp->uh_next.ptr; |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1721 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1722 |
6122 | 1723 if (undo_write_bytes(&bi, (long_u)UF_HEADER_END_MAGIC, 2) == OK) |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1724 write_ok = TRUE; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1725 #ifdef U_DEBUG |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1726 if (headers_written != buf->b_u_numhead) |
4827
60301d4d1682
updated for version 7.3.1160
Bram Moolenaar <bram@vim.org>
parents:
4303
diff
changeset
|
1727 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
1728 semsg("Written %ld headers, ...", headers_written); |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
1729 semsg("... but numhead is %ld", buf->b_u_numhead); |
4827
60301d4d1682
updated for version 7.3.1160
Bram Moolenaar <bram@vim.org>
parents:
4303
diff
changeset
|
1730 } |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1731 #endif |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1732 |
6122 | 1733 #ifdef FEAT_CRYPT |
1734 if (bi.bi_state != NULL && undo_flush(&bi) == FAIL) | |
1735 write_ok = FALSE; | |
1736 #endif | |
1737 | |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1738 write_error: |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1739 fclose(fp); |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1740 if (!write_ok) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
1741 semsg(_("E829: write error in undo file: %s"), file_name); |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1742 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
1743 #if defined(MSWIN) |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1744 /* Copy file attributes; for systems where this can only be done after |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1745 * closing the file. */ |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1746 if (buf->b_ffname != NULL) |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1747 (void)mch_copy_file_attribute(buf->b_ffname, file_name); |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1748 #endif |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1749 #ifdef HAVE_ACL |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1750 if (buf->b_ffname != NULL) |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1751 { |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1752 vim_acl_T acl; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1753 |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1754 /* For systems that support ACL: get the ACL from the original file. */ |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1755 acl = mch_get_acl(buf->b_ffname); |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1756 mch_set_acl(file_name, acl); |
3545 | 1757 mch_free_acl(acl); |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1758 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1759 #endif |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1760 |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1761 theend: |
2267 | 1762 #ifdef FEAT_CRYPT |
6122 | 1763 if (bi.bi_state != NULL) |
1764 crypt_free_state(bi.bi_state); | |
1765 vim_free(bi.bi_buffer); | |
2267 | 1766 #endif |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1767 if (file_name != name) |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1768 vim_free(file_name); |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1769 } |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1770 |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1771 /* |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1772 * Load the undo tree from an undo file. |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1773 * If "name" is not NULL use it as the undo file name. This also means being |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1774 * a bit more verbose. |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1775 * Otherwise use curbuf->b_ffname to generate the undo file name. |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1776 * "hash[UNDO_HASH_SIZE]" must be the hash value of the buffer text. |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1777 */ |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1778 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1779 u_read_undo(char_u *name, char_u *hash, char_u *orig_name) |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1780 { |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1781 char_u *file_name; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1782 FILE *fp; |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1783 long version, str_len; |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1784 undoline_T line_ptr; |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1785 linenr_T line_lnum; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1786 colnr_T line_colnr; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1787 linenr_T line_count; |
10976
f97a72ad8ffa
patch 8.0.0377: possible overflow when reading corrupted undo file
Christian Brabandt <cb@256bit.org>
parents:
10631
diff
changeset
|
1788 long num_head = 0; |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1789 long old_header_seq, new_header_seq, cur_header_seq; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1790 long seq_last, seq_cur; |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2281
diff
changeset
|
1791 long last_save_nr = 0; |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1792 short old_idx = -1, new_idx = -1, cur_idx = -1; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1793 long num_read_uhps = 0; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1794 time_t seq_time; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1795 int i, j; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1796 int c; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1797 u_header_T *uhp; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1798 u_header_T **uhp_table = NULL; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1799 char_u read_hash[UNDO_HASH_SIZE]; |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1800 char_u magic_buf[UF_START_MAGIC_LEN]; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1801 #ifdef U_DEBUG |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1802 int *uhp_table_used; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1803 #endif |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1804 #ifdef UNIX |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
8568
diff
changeset
|
1805 stat_T st_orig; |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
8568
diff
changeset
|
1806 stat_T st_undo; |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1807 #endif |
6122 | 1808 bufinfo_T bi; |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1809 |
6128 | 1810 vim_memset(&bi, 0, sizeof(bi)); |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1811 line_ptr.ul_len = 0; |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1812 line_ptr.ul_line = NULL; |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1813 |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1814 if (name == NULL) |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1815 { |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1816 file_name = u_get_undo_file_name(curbuf->b_ffname, TRUE); |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1817 if (file_name == NULL) |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1818 return; |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1819 |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1820 #ifdef UNIX |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1821 /* For safety we only read an undo file if the owner is equal to the |
5343 | 1822 * owner of the text file or equal to the current user. */ |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1823 if (mch_stat((char *)orig_name, &st_orig) >= 0 |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1824 && mch_stat((char *)file_name, &st_undo) >= 0 |
5343 | 1825 && st_orig.st_uid != st_undo.st_uid |
1826 && st_undo.st_uid != getuid()) | |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1827 { |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1828 if (p_verbose > 0) |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1829 { |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1830 verbose_enter(); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
1831 smsg(_("Not reading undo file, owner differs: %s"), |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1832 file_name); |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1833 verbose_leave(); |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1834 } |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1835 return; |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1836 } |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1837 #endif |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1838 } |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1839 else |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1840 file_name = name; |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1841 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1842 if (p_verbose > 0) |
2235
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1843 { |
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1844 verbose_enter(); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
1845 smsg(_("Reading undo file: %s"), file_name); |
2235
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1846 verbose_leave(); |
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1847 } |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1848 |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1849 fp = mch_fopen((char *)file_name, "r"); |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1850 if (fp == NULL) |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1851 { |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1852 if (name != NULL || p_verbose > 0) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
1853 semsg(_("E822: Cannot open undo file for reading: %s"), file_name); |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1854 goto error; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1855 } |
6122 | 1856 bi.bi_buf = curbuf; |
1857 bi.bi_fp = fp; | |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1858 |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1859 /* |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1860 * Read the undo file header. |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1861 */ |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1862 if (fread(magic_buf, UF_START_MAGIC_LEN, 1, fp) != 1 |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1863 || memcmp(magic_buf, UF_START_MAGIC, UF_START_MAGIC_LEN) != 0) |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1864 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
1865 semsg(_("E823: Not an undo file: %s"), file_name); |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1866 goto error; |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1867 } |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1868 version = get2c(fp); |
2342
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1869 if (version == UF_VERSION_CRYPT) |
2239
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
1870 { |
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
1871 #ifdef FEAT_CRYPT |
2251
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
2245
diff
changeset
|
1872 if (*curbuf->b_p_key == NUL) |
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
2245
diff
changeset
|
1873 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
1874 semsg(_("E832: Non-encrypted file has encrypted undo file: %s"), |
2251
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
2245
diff
changeset
|
1875 file_name); |
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
2245
diff
changeset
|
1876 goto error; |
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
2245
diff
changeset
|
1877 } |
6122 | 1878 bi.bi_state = crypt_create_from_file(fp, curbuf->b_p_key); |
1879 if (bi.bi_state == NULL) | |
2239
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
1880 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
1881 semsg(_("E826: Undo file decryption failed: %s"), file_name); |
2239
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
1882 goto error; |
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
1883 } |
6122 | 1884 if (crypt_whole_undofile(bi.bi_state->method_nr)) |
1885 { | |
1886 bi.bi_buffer = alloc(CRYPT_BUF_SIZE); | |
1887 if (bi.bi_buffer == NULL) | |
1888 { | |
1889 crypt_free_state(bi.bi_state); | |
1890 bi.bi_state = NULL; | |
1891 goto error; | |
1892 } | |
1893 bi.bi_avail = 0; | |
1894 bi.bi_used = 0; | |
1895 } | |
2239
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
1896 #else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
1897 semsg(_("E827: Undo file is encrypted: %s"), file_name); |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1898 goto error; |
2239
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
1899 #endif |
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
1900 } |
2342
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1901 else if (version != UF_VERSION) |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1902 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
1903 semsg(_("E824: Incompatible undo file: %s"), file_name); |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1904 goto error; |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1905 } |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1906 |
6122 | 1907 if (undo_read(&bi, read_hash, (size_t)UNDO_HASH_SIZE) == FAIL) |
2229
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2223
diff
changeset
|
1908 { |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
1909 corruption_error("hash", file_name); |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1910 goto error; |
2229
d45902a5c61c
Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents:
2223
diff
changeset
|
1911 } |
6122 | 1912 line_count = (linenr_T)undo_read_4c(&bi); |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1913 if (memcmp(hash, read_hash, UNDO_HASH_SIZE) != 0 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1914 || line_count != curbuf->b_ml.ml_line_count) |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1915 { |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1916 if (p_verbose > 0 || name != NULL) |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1917 { |
2235
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1918 if (name == NULL) |
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1919 verbose_enter(); |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1920 give_warning((char_u *) |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1921 _("File contents changed, cannot use undo info"), TRUE); |
2235
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1922 if (name == NULL) |
4ba83ae8d505
Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents:
2234
diff
changeset
|
1923 verbose_leave(); |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1924 } |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1925 goto error; |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1926 } |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1927 |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1928 /* Read undo data for "U" command. */ |
6122 | 1929 str_len = undo_read_4c(&bi); |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1930 if (str_len < 0) |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1931 goto error; |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1932 if (str_len > 0) |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1933 { |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1934 line_ptr.ul_line = read_string_decrypt(&bi, str_len); |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1935 line_ptr.ul_len = str_len + 1; |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1936 } |
6122 | 1937 line_lnum = (linenr_T)undo_read_4c(&bi); |
1938 line_colnr = (colnr_T)undo_read_4c(&bi); | |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1939 if (line_lnum < 0 || line_colnr < 0) |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1940 { |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1941 corruption_error("line lnum/col", file_name); |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1942 goto error; |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1943 } |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1944 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1945 /* Begin general undo data */ |
6122 | 1946 old_header_seq = undo_read_4c(&bi); |
1947 new_header_seq = undo_read_4c(&bi); | |
1948 cur_header_seq = undo_read_4c(&bi); | |
1949 num_head = undo_read_4c(&bi); | |
1950 seq_last = undo_read_4c(&bi); | |
1951 seq_cur = undo_read_4c(&bi); | |
1952 seq_time = undo_read_time(&bi); | |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1953 |
2342
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1954 /* Optional header fields. */ |
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1955 for (;;) |
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1956 { |
6122 | 1957 int len = undo_read_byte(&bi); |
2342
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1958 int what; |
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1959 |
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1960 if (len == 0 || len == EOF) |
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1961 break; |
6122 | 1962 what = undo_read_byte(&bi); |
2342
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1963 switch (what) |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
1964 { |
2342
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1965 case UF_LAST_SAVE_NR: |
6122 | 1966 last_save_nr = undo_read_4c(&bi); |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
1967 break; |
2342
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1968 default: |
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1969 /* field not supported, skip */ |
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1970 while (--len >= 0) |
6122 | 1971 (void)undo_read_byte(&bi); |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
1972 } |
2342
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1973 } |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
1974 |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1975 /* uhp_table will store the freshly created undo headers we allocate |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1976 * until we insert them into curbuf. The table remains sorted by the |
2230
290ee42cae85
Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
1977 * sequence numbers of the headers. |
290ee42cae85
Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
1978 * When there are no headers uhp_table is NULL. */ |
290ee42cae85
Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
1979 if (num_head > 0) |
290ee42cae85
Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
1980 { |
10976
f97a72ad8ffa
patch 8.0.0377: possible overflow when reading corrupted undo file
Christian Brabandt <cb@256bit.org>
parents:
10631
diff
changeset
|
1981 if (num_head < LONG_MAX / (long)sizeof(u_header_T *)) |
f97a72ad8ffa
patch 8.0.0377: possible overflow when reading corrupted undo file
Christian Brabandt <cb@256bit.org>
parents:
10631
diff
changeset
|
1982 uhp_table = (u_header_T **)U_ALLOC_LINE( |
2230
290ee42cae85
Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
1983 num_head * sizeof(u_header_T *)); |
290ee42cae85
Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
1984 if (uhp_table == NULL) |
290ee42cae85
Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
1985 goto error; |
290ee42cae85
Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
1986 } |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1987 |
6122 | 1988 while ((c = undo_read_2c(&bi)) == UF_HEADER_MAGIC) |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1989 { |
2223
81b83a19e127
More strict checks for the undo file.
Bram Moolenaar <bram@vim.org>
parents:
2222
diff
changeset
|
1990 if (num_read_uhps >= num_head) |
81b83a19e127
More strict checks for the undo file.
Bram Moolenaar <bram@vim.org>
parents:
2222
diff
changeset
|
1991 { |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1992 corruption_error("num_head too small", file_name); |
2223
81b83a19e127
More strict checks for the undo file.
Bram Moolenaar <bram@vim.org>
parents:
2222
diff
changeset
|
1993 goto error; |
81b83a19e127
More strict checks for the undo file.
Bram Moolenaar <bram@vim.org>
parents:
2222
diff
changeset
|
1994 } |
81b83a19e127
More strict checks for the undo file.
Bram Moolenaar <bram@vim.org>
parents:
2222
diff
changeset
|
1995 |
6122 | 1996 uhp = unserialize_uhp(&bi, file_name); |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1997 if (uhp == NULL) |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
1998 goto error; |
2233
43cad213cb7f
A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents:
2232
diff
changeset
|
1999 uhp_table[num_read_uhps++] = uhp; |
43cad213cb7f
A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents:
2232
diff
changeset
|
2000 } |
43cad213cb7f
A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents:
2232
diff
changeset
|
2001 |
43cad213cb7f
A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents:
2232
diff
changeset
|
2002 if (num_read_uhps != num_head) |
43cad213cb7f
A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents:
2232
diff
changeset
|
2003 { |
43cad213cb7f
A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents:
2232
diff
changeset
|
2004 corruption_error("num_head", file_name); |
43cad213cb7f
A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents:
2232
diff
changeset
|
2005 goto error; |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2006 } |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2007 if (c != UF_HEADER_END_MAGIC) |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2008 { |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2009 corruption_error("end marker", file_name); |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2010 goto error; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2011 } |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2012 |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2013 #ifdef U_DEBUG |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2014 uhp_table_used = (int *)alloc_clear( |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2015 (unsigned)(sizeof(int) * num_head + 1)); |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2016 # define SET_FLAG(j) ++uhp_table_used[j] |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2017 #else |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2018 # define SET_FLAG(j) |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2019 #endif |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2020 |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
2021 /* We have put all of the headers into a table. Now we iterate through the |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2022 * table and swizzle each sequence number we have stored in uh_*_seq into |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2023 * a pointer corresponding to the header with that sequence number. */ |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2024 for (i = 0; i < num_head; i++) |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2025 { |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2026 uhp = uhp_table[i]; |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2027 if (uhp == NULL) |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2028 continue; |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2029 for (j = 0; j < num_head; j++) |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2030 if (uhp_table[j] != NULL && i != j |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2031 && uhp_table[i]->uh_seq == uhp_table[j]->uh_seq) |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2032 { |
2233
43cad213cb7f
A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents:
2232
diff
changeset
|
2033 corruption_error("duplicate uh_seq", file_name); |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2034 goto error; |
2233
43cad213cb7f
A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents:
2232
diff
changeset
|
2035 } |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2036 for (j = 0; j < num_head; j++) |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2037 if (uhp_table[j] != NULL |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2038 && uhp_table[j]->uh_seq == uhp->uh_next.seq) |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2039 { |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2040 uhp->uh_next.ptr = uhp_table[j]; |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2041 SET_FLAG(j); |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2042 break; |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2043 } |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2044 for (j = 0; j < num_head; j++) |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2045 if (uhp_table[j] != NULL |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2046 && uhp_table[j]->uh_seq == uhp->uh_prev.seq) |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2047 { |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2048 uhp->uh_prev.ptr = uhp_table[j]; |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2049 SET_FLAG(j); |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2050 break; |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2051 } |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2052 for (j = 0; j < num_head; j++) |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2053 if (uhp_table[j] != NULL |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2054 && uhp_table[j]->uh_seq == uhp->uh_alt_next.seq) |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2055 { |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2056 uhp->uh_alt_next.ptr = uhp_table[j]; |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2057 SET_FLAG(j); |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2058 break; |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2059 } |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2060 for (j = 0; j < num_head; j++) |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2061 if (uhp_table[j] != NULL |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2062 && uhp_table[j]->uh_seq == uhp->uh_alt_prev.seq) |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2063 { |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2064 uhp->uh_alt_prev.ptr = uhp_table[j]; |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2065 SET_FLAG(j); |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2066 break; |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2067 } |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2068 if (old_header_seq > 0 && old_idx < 0 && uhp->uh_seq == old_header_seq) |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2069 { |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2070 old_idx = i; |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2071 SET_FLAG(i); |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2072 } |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2073 if (new_header_seq > 0 && new_idx < 0 && uhp->uh_seq == new_header_seq) |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2074 { |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2075 new_idx = i; |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2076 SET_FLAG(i); |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2077 } |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2078 if (cur_header_seq > 0 && cur_idx < 0 && uhp->uh_seq == cur_header_seq) |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2079 { |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2080 cur_idx = i; |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2081 SET_FLAG(i); |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2082 } |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2083 } |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2084 |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2085 /* Now that we have read the undo info successfully, free the current undo |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2086 * info and use the info from the file. */ |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2087 u_blockfree(curbuf); |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2088 curbuf->b_u_oldhead = old_idx < 0 ? NULL : uhp_table[old_idx]; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2089 curbuf->b_u_newhead = new_idx < 0 ? NULL : uhp_table[new_idx]; |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2090 curbuf->b_u_curhead = cur_idx < 0 ? NULL : uhp_table[cur_idx]; |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2091 curbuf->b_u_line_ptr = line_ptr; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2092 curbuf->b_u_line_lnum = line_lnum; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2093 curbuf->b_u_line_colnr = line_colnr; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2094 curbuf->b_u_numhead = num_head; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2095 curbuf->b_u_seq_last = seq_last; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2096 curbuf->b_u_seq_cur = seq_cur; |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
2097 curbuf->b_u_time_cur = seq_time; |
2281
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2098 curbuf->b_u_save_nr_last = last_save_nr; |
2627 | 2099 curbuf->b_u_save_nr_cur = last_save_nr; |
2233
43cad213cb7f
A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents:
2232
diff
changeset
|
2100 |
43cad213cb7f
A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents:
2232
diff
changeset
|
2101 curbuf->b_u_synced = TRUE; |
2230
290ee42cae85
Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2102 vim_free(uhp_table); |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2103 |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2104 #ifdef U_DEBUG |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2105 for (i = 0; i < num_head; ++i) |
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2106 if (uhp_table_used[i] == 0) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
2107 semsg("uhp_table entry %ld not used, leaking memory", i); |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2108 vim_free(uhp_table_used); |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2109 u_check(TRUE); |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2110 #endif |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2230
diff
changeset
|
2111 |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2112 if (name != NULL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
2113 smsg(_("Finished reading undo file %s"), file_name); |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2114 goto theend; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2115 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2116 error: |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2117 vim_free(line_ptr.ul_line); |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2118 if (uhp_table != NULL) |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2119 { |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2120 for (i = 0; i < num_read_uhps; i++) |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2121 if (uhp_table[i] != NULL) |
2223
81b83a19e127
More strict checks for the undo file.
Bram Moolenaar <bram@vim.org>
parents:
2222
diff
changeset
|
2122 u_free_uhp(uhp_table[i]); |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2123 vim_free(uhp_table); |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2124 } |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2125 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2126 theend: |
2267 | 2127 #ifdef FEAT_CRYPT |
6122 | 2128 if (bi.bi_state != NULL) |
2129 crypt_free_state(bi.bi_state); | |
2130 vim_free(bi.bi_buffer); | |
2267 | 2131 #endif |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2132 if (fp != NULL) |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2133 fclose(fp); |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2134 if (file_name != name) |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2135 vim_free(file_name); |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2136 return; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2137 } |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2138 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2139 #endif /* FEAT_PERSISTENT_UNDO */ |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2140 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2141 |
7 | 2142 /* |
2143 * If 'cpoptions' contains 'u': Undo the previous undo or redo (vi compatible). | |
2144 * If 'cpoptions' does not contain 'u': Always undo. | |
2145 */ | |
2146 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2147 u_undo(int count) |
7 | 2148 { |
2149 /* | |
2150 * If we get an undo command while executing a macro, we behave like the | |
2151 * original vi. If this happens twice in one macro the result will not | |
2152 * be compatible. | |
2153 */ | |
2154 if (curbuf->b_u_synced == FALSE) | |
2155 { | |
825 | 2156 u_sync(TRUE); |
7 | 2157 count = 1; |
2158 } | |
2159 | |
2160 if (vim_strchr(p_cpo, CPO_UNDO) == NULL) | |
2161 undo_undoes = TRUE; | |
2162 else | |
2163 undo_undoes = !undo_undoes; | |
2164 u_doit(count); | |
2165 } | |
2166 | |
2167 /* | |
2168 * If 'cpoptions' contains 'u': Repeat the previous undo or redo. | |
2169 * If 'cpoptions' does not contain 'u': Always redo. | |
2170 */ | |
2171 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2172 u_redo(int count) |
7 | 2173 { |
2174 if (vim_strchr(p_cpo, CPO_UNDO) == NULL) | |
2175 undo_undoes = FALSE; | |
2176 u_doit(count); | |
2177 } | |
2178 | |
2179 /* | |
2180 * Undo or redo, depending on 'undo_undoes', 'count' times. | |
2181 */ | |
2182 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2183 u_doit(int startcount) |
7 | 2184 { |
777 | 2185 int count = startcount; |
2186 | |
632 | 2187 if (!undo_allowed()) |
7 | 2188 return; |
2189 | |
2190 u_newcount = 0; | |
2191 u_oldcount = 0; | |
179 | 2192 if (curbuf->b_ml.ml_flags & ML_EMPTY) |
2193 u_oldcount = -1; | |
7 | 2194 while (count--) |
2195 { | |
2189 | 2196 /* Do the change warning now, so that it triggers FileChangedRO when |
2197 * needed. This may cause the file to be reloaded, that must happen | |
2198 * before we do anything, because it may change curbuf->b_u_curhead | |
2199 * and more. */ | |
2200 change_warning(0); | |
2201 | |
7 | 2202 if (undo_undoes) |
2203 { | |
2204 if (curbuf->b_u_curhead == NULL) /* first undo */ | |
2205 curbuf->b_u_curhead = curbuf->b_u_newhead; | |
5446 | 2206 else if (get_undolevel() > 0) /* multi level undo */ |
7 | 2207 /* get next undo */ |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2208 curbuf->b_u_curhead = curbuf->b_u_curhead->uh_next.ptr; |
7 | 2209 /* nothing to undo */ |
2210 if (curbuf->b_u_numhead == 0 || curbuf->b_u_curhead == NULL) | |
2211 { | |
2212 /* stick curbuf->b_u_curhead at end */ | |
2213 curbuf->b_u_curhead = curbuf->b_u_oldhead; | |
2214 beep_flush(); | |
777 | 2215 if (count == startcount - 1) |
2216 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
2217 msg(_("Already at oldest change")); |
777 | 2218 return; |
2219 } | |
7 | 2220 break; |
2221 } | |
2222 | |
777 | 2223 u_undoredo(TRUE); |
7 | 2224 } |
2225 else | |
2226 { | |
5446 | 2227 if (curbuf->b_u_curhead == NULL || get_undolevel() <= 0) |
7 | 2228 { |
2229 beep_flush(); /* nothing to redo */ | |
777 | 2230 if (count == startcount - 1) |
2231 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
2232 msg(_("Already at newest change")); |
777 | 2233 return; |
2234 } | |
7 | 2235 break; |
2236 } | |
2237 | |
777 | 2238 u_undoredo(FALSE); |
753 | 2239 |
2240 /* Advance for next redo. Set "newhead" when at the end of the | |
2241 * redoable changes. */ | |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2242 if (curbuf->b_u_curhead->uh_prev.ptr == NULL) |
753 | 2243 curbuf->b_u_newhead = curbuf->b_u_curhead; |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2244 curbuf->b_u_curhead = curbuf->b_u_curhead->uh_prev.ptr; |
7 | 2245 } |
2246 } | |
798 | 2247 u_undo_end(undo_undoes, FALSE); |
753 | 2248 } |
2249 | |
2250 /* | |
2251 * Undo or redo over the timeline. | |
2252 * When "step" is negative go back in time, otherwise goes forward in time. | |
758 | 2253 * When "sec" is FALSE make "step" steps, when "sec" is TRUE use "step" as |
2254 * seconds. | |
2281
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2255 * When "file" is TRUE use "step" as a number of file writes. |
772 | 2256 * When "absolute" is TRUE use "step" as the sequence number to jump to. |
2257 * "sec" must be FALSE then. | |
753 | 2258 */ |
2259 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2260 undo_time( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2261 long step, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2262 int sec, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2263 int file, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2264 int absolute) |
753 | 2265 { |
2266 long target; | |
2267 long closest; | |
758 | 2268 long closest_start; |
2269 long closest_seq = 0; | |
2270 long val; | |
13134
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2271 u_header_T *uhp = NULL; |
753 | 2272 u_header_T *last; |
2273 int mark; | |
16405
840fa633ad64
patch 8.1.1207: some compilers give warning messages
Bram Moolenaar <Bram@vim.org>
parents:
16097
diff
changeset
|
2274 int nomark = 0; // shut up compiler |
753 | 2275 int round; |
758 | 2276 int dosec = sec; |
2281
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2277 int dofile = file; |
758 | 2278 int above = FALSE; |
794 | 2279 int did_undo = TRUE; |
753 | 2280 |
766 | 2281 /* First make sure the current undoable change is synced. */ |
2282 if (curbuf->b_u_synced == FALSE) | |
825 | 2283 u_sync(TRUE); |
766 | 2284 |
753 | 2285 u_newcount = 0; |
2286 u_oldcount = 0; | |
179 | 2287 if (curbuf->b_ml.ml_flags & ML_EMPTY) |
753 | 2288 u_oldcount = -1; |
2289 | |
777 | 2290 /* "target" is the node below which we want to be. |
2291 * Init "closest" to a value we can't reach. */ | |
772 | 2292 if (absolute) |
2293 { | |
13134
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2294 target = step; |
777 | 2295 closest = -1; |
753 | 2296 } |
2297 else | |
2298 { | |
2281
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2299 if (dosec) |
10518
de77fa909414
commit https://github.com/vim/vim/commit/cbd4de44e8d08fba3c09eb40ad6e36e83faf020a
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
2300 target = (long)(curbuf->b_u_time_cur) + step; |
2281
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2301 else if (dofile) |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2302 { |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2303 if (step < 0) |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2304 { |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2305 /* Going back to a previous write. If there were changes after |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2306 * the last write, count that as moving one file-write, so |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2307 * that ":earlier 1f" undoes all changes since the last save. */ |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2308 uhp = curbuf->b_u_curhead; |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2309 if (uhp != NULL) |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2310 uhp = uhp->uh_next.ptr; |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2311 else |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2312 uhp = curbuf->b_u_newhead; |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2313 if (uhp != NULL && uhp->uh_save_nr != 0) |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2314 /* "uh_save_nr" was set in the last block, that means |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2315 * there were no changes since the last write */ |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2316 target = curbuf->b_u_save_nr_cur + step; |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2317 else |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2318 /* count the changes since the last write as one step */ |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2319 target = curbuf->b_u_save_nr_cur + step + 1; |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2320 if (target <= 0) |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2321 /* Go to before first write: before the oldest change. Use |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2322 * the sequence number for that. */ |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2323 dofile = FALSE; |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2324 } |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2325 else |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2326 { |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2327 /* Moving forward to a newer write. */ |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2328 target = curbuf->b_u_save_nr_cur + step; |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2329 if (target > curbuf->b_u_save_nr_last) |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2330 { |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2331 /* Go to after last write: after the latest change. Use |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2332 * the sequence number for that. */ |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2333 target = curbuf->b_u_seq_last + 1; |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2334 dofile = FALSE; |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2335 } |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2336 } |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2337 } |
777 | 2338 else |
2339 target = curbuf->b_u_seq_cur + step; | |
2340 if (step < 0) | |
758 | 2341 { |
777 | 2342 if (target < 0) |
2343 target = 0; | |
2344 closest = -1; | |
758 | 2345 } |
2346 else | |
2347 { | |
2281
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2348 if (dosec) |
10518
de77fa909414
commit https://github.com/vim/vim/commit/cbd4de44e8d08fba3c09eb40ad6e36e83faf020a
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
2349 closest = (long)(vim_time() + 1); |
2281
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2350 else if (dofile) |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2351 closest = curbuf->b_u_save_nr_last + 2; |
777 | 2352 else |
2353 closest = curbuf->b_u_seq_last + 2; | |
2354 if (target >= closest) | |
2355 target = closest - 1; | |
758 | 2356 } |
753 | 2357 } |
758 | 2358 closest_start = closest; |
777 | 2359 closest_seq = curbuf->b_u_seq_cur; |
753 | 2360 |
13134
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2361 /* When "target" is 0; Back to origin. */ |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2362 if (target == 0) |
13138
0f906f414c69
patch 8.0.1443: compiler complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
13134
diff
changeset
|
2363 { |
0f906f414c69
patch 8.0.1443: compiler complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
13134
diff
changeset
|
2364 mark = lastmark; /* avoid that GCC complains */ |
0f906f414c69
patch 8.0.1443: compiler complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
13134
diff
changeset
|
2365 goto target_zero; |
0f906f414c69
patch 8.0.1443: compiler complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
13134
diff
changeset
|
2366 } |
13134
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2367 |
758 | 2368 /* |
2369 * May do this twice: | |
753 | 2370 * 1. Search for "target", update "closest" to the best match found. |
758 | 2371 * 2. If "target" not found search for "closest". |
2372 * | |
2373 * When using the closest time we use the sequence number in the second | |
2374 * round, because there may be several entries with the same time. | |
2375 */ | |
753 | 2376 for (round = 1; round <= 2; ++round) |
2377 { | |
2378 /* Find the path from the current state to where we want to go. The | |
2379 * desired state can be anywhere in the undo tree, need to go all over | |
2380 * it. We put "nomark" in uh_walk where we have been without success, | |
2381 * "mark" where it could possibly be. */ | |
2382 mark = ++lastmark; | |
2383 nomark = ++lastmark; | |
2384 | |
2385 if (curbuf->b_u_curhead == NULL) /* at leaf of the tree */ | |
2386 uhp = curbuf->b_u_newhead; | |
2387 else | |
2388 uhp = curbuf->b_u_curhead; | |
2389 | |
2390 while (uhp != NULL) | |
2391 { | |
2392 uhp->uh_walk = mark; | |
2281
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2393 if (dosec) |
10518
de77fa909414
commit https://github.com/vim/vim/commit/cbd4de44e8d08fba3c09eb40ad6e36e83faf020a
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
2394 val = (long)(uhp->uh_time); |
2281
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2395 else if (dofile) |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2396 val = uhp->uh_save_nr; |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2397 else |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2398 val = uhp->uh_seq; |
753 | 2399 |
2281
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2400 if (round == 1 && !(dofile && val == 0)) |
758 | 2401 { |
2402 /* Remember the header that is closest to the target. | |
2403 * It must be at least in the right direction (checked with | |
777 | 2404 * "b_u_seq_cur"). When the timestamp is equal find the |
758 | 2405 * highest/lowest sequence number. */ |
777 | 2406 if ((step < 0 ? uhp->uh_seq <= curbuf->b_u_seq_cur |
2407 : uhp->uh_seq > curbuf->b_u_seq_cur) | |
2408 && ((dosec && val == closest) | |
2409 ? (step < 0 | |
2410 ? uhp->uh_seq < closest_seq | |
2411 : uhp->uh_seq > closest_seq) | |
2412 : closest == closest_start | |
2413 || (val > target | |
2414 ? (closest > target | |
2415 ? val - target <= closest - target | |
2416 : val - target <= target - closest) | |
2417 : (closest > target | |
2418 ? target - val <= closest - target | |
2419 : target - val <= target - closest)))) | |
758 | 2420 { |
2421 closest = val; | |
2422 closest_seq = uhp->uh_seq; | |
2423 } | |
2424 } | |
2425 | |
2426 /* Quit searching when we found a match. But when searching for a | |
2427 * time we need to continue looking for the best uh_seq. */ | |
2428 if (target == val && !dosec) | |
2281
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2429 { |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2430 target = uhp->uh_seq; |
758 | 2431 break; |
2281
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2432 } |
753 | 2433 |
2434 /* go down in the tree if we haven't been there */ | |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2435 if (uhp->uh_prev.ptr != NULL && uhp->uh_prev.ptr->uh_walk != nomark |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2436 && uhp->uh_prev.ptr->uh_walk != mark) |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2437 uhp = uhp->uh_prev.ptr; |
753 | 2438 |
2439 /* go to alternate branch if we haven't been there */ | |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2440 else if (uhp->uh_alt_next.ptr != NULL |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2441 && uhp->uh_alt_next.ptr->uh_walk != nomark |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2442 && uhp->uh_alt_next.ptr->uh_walk != mark) |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2443 uhp = uhp->uh_alt_next.ptr; |
753 | 2444 |
2445 /* go up in the tree if we haven't been there and we are at the | |
2446 * start of alternate branches */ | |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2447 else if (uhp->uh_next.ptr != NULL && uhp->uh_alt_prev.ptr == NULL |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2448 && uhp->uh_next.ptr->uh_walk != nomark |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2449 && uhp->uh_next.ptr->uh_walk != mark) |
798 | 2450 { |
2451 /* If still at the start we don't go through this change. */ | |
2452 if (uhp == curbuf->b_u_curhead) | |
2453 uhp->uh_walk = nomark; | |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2454 uhp = uhp->uh_next.ptr; |
798 | 2455 } |
753 | 2456 |
2457 else | |
2458 { | |
2459 /* need to backtrack; mark this node as useless */ | |
2460 uhp->uh_walk = nomark; | |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2461 if (uhp->uh_alt_prev.ptr != NULL) |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2462 uhp = uhp->uh_alt_prev.ptr; |
753 | 2463 else |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2464 uhp = uhp->uh_next.ptr; |
753 | 2465 } |
2466 } | |
2467 | |
2468 if (uhp != NULL) /* found it */ | |
2469 break; | |
772 | 2470 |
2471 if (absolute) | |
2472 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
2473 semsg(_("E830: Undo number %ld not found"), step); |
772 | 2474 return; |
2475 } | |
2476 | |
758 | 2477 if (closest == closest_start) |
753 | 2478 { |
758 | 2479 if (step < 0) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
2480 msg(_("Already at oldest change")); |
758 | 2481 else |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
2482 msg(_("Already at newest change")); |
753 | 2483 return; |
2484 } | |
2485 | |
758 | 2486 target = closest_seq; |
2487 dosec = FALSE; | |
2281
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2488 dofile = FALSE; |
758 | 2489 if (step < 0) |
2490 above = TRUE; /* stop above the header */ | |
753 | 2491 } |
2492 | |
13138
0f906f414c69
patch 8.0.1443: compiler complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
13134
diff
changeset
|
2493 target_zero: |
753 | 2494 /* If we found it: Follow the path to go to where we want to be. */ |
13134
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2495 if (uhp != NULL || target == 0) |
753 | 2496 { |
2497 /* | |
2498 * First go up the tree as much as needed. | |
2499 */ | |
2189 | 2500 while (!got_int) |
753 | 2501 { |
2189 | 2502 /* Do the change warning now, for the same reason as above. */ |
2503 change_warning(0); | |
2504 | |
753 | 2505 uhp = curbuf->b_u_curhead; |
2506 if (uhp == NULL) | |
2507 uhp = curbuf->b_u_newhead; | |
2508 else | |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2509 uhp = uhp->uh_next.ptr; |
13134
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2510 if (uhp == NULL || (target > 0 && uhp->uh_walk != mark) |
777 | 2511 || (uhp->uh_seq == target && !above)) |
753 | 2512 break; |
2513 curbuf->b_u_curhead = uhp; | |
777 | 2514 u_undoredo(TRUE); |
13134
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2515 if (target > 0) |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2516 uhp->uh_walk = nomark; /* don't go back down here */ |
753 | 2517 } |
2518 | |
13134
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2519 /* When back to origin, redo is not needed. */ |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2520 if (target > 0) |
753 | 2521 { |
13134
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2522 /* |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2523 * And now go down the tree (redo), branching off where needed. |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2524 */ |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2525 while (!got_int) |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2526 { |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2527 /* Do the change warning now, for the same reason as above. */ |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2528 change_warning(0); |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2529 |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2530 uhp = curbuf->b_u_curhead; |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2531 if (uhp == NULL) |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2532 break; |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2533 |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2534 /* Go back to the first branch with a mark. */ |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2535 while (uhp->uh_alt_prev.ptr != NULL |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2536 && uhp->uh_alt_prev.ptr->uh_walk == mark) |
13134
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2537 uhp = uhp->uh_alt_prev.ptr; |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2538 |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2539 /* Find the last branch with a mark, that's the one. */ |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2540 last = uhp; |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2541 while (last->uh_alt_next.ptr != NULL |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2542 && last->uh_alt_next.ptr->uh_walk == mark) |
13134
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2543 last = last->uh_alt_next.ptr; |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2544 if (last != uhp) |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2545 { |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2546 /* Make the used branch the first entry in the list of |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2547 * alternatives to make "u" and CTRL-R take this branch. */ |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2548 while (uhp->uh_alt_prev.ptr != NULL) |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2549 uhp = uhp->uh_alt_prev.ptr; |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2550 if (last->uh_alt_next.ptr != NULL) |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2551 last->uh_alt_next.ptr->uh_alt_prev.ptr = |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2552 last->uh_alt_prev.ptr; |
13134
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2553 last->uh_alt_prev.ptr->uh_alt_next.ptr = |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2554 last->uh_alt_next.ptr; |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2555 last->uh_alt_prev.ptr = NULL; |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2556 last->uh_alt_next.ptr = uhp; |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2557 uhp->uh_alt_prev.ptr = last; |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2558 |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2559 if (curbuf->b_u_oldhead == uhp) |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2560 curbuf->b_u_oldhead = last; |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2561 uhp = last; |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2562 if (uhp->uh_next.ptr != NULL) |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2563 uhp->uh_next.ptr->uh_prev.ptr = uhp; |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2564 } |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2565 curbuf->b_u_curhead = uhp; |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2566 |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2567 if (uhp->uh_walk != mark) |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2568 break; /* must have reached the target */ |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2569 |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2570 /* Stop when going backwards in time and didn't find the exact |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2571 * header we were looking for. */ |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2572 if (uhp->uh_seq == target && above) |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2573 { |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2574 curbuf->b_u_seq_cur = target - 1; |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2575 break; |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2576 } |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2577 |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2578 u_undoredo(FALSE); |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2579 |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2580 /* Advance "curhead" to below the header we last used. If it |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2581 * becomes NULL then we need to set "newhead" to this leaf. */ |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2582 if (uhp->uh_prev.ptr == NULL) |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2583 curbuf->b_u_newhead = uhp; |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2584 curbuf->b_u_curhead = uhp->uh_prev.ptr; |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2585 did_undo = FALSE; |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2586 |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2587 if (uhp->uh_seq == target) /* found it! */ |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2588 break; |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2589 |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2590 uhp = uhp->uh_prev.ptr; |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2591 if (uhp == NULL || uhp->uh_walk != mark) |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2592 { |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2593 /* Need to redo more but can't find it... */ |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2594 internal_error("undo_time()"); |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2595 break; |
c4b5ad2b3596
patch 8.0.1441: using ":undo 0" leaves undo in wrong state
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
2596 } |
753 | 2597 } |
2598 } | |
2599 } | |
798 | 2600 u_undo_end(did_undo, absolute); |
7 | 2601 } |
2602 | |
2603 /* | |
2604 * u_undoredo: common code for undo and redo | |
2605 * | |
2606 * The lines in the file are replaced by the lines in the entry list at | |
2607 * curbuf->b_u_curhead. The replaced lines in the file are saved in the entry | |
2608 * list for the next undo/redo. | |
777 | 2609 * |
2610 * When "undo" is TRUE we go up in the tree, when FALSE we go down. | |
7 | 2611 */ |
2612 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2613 u_undoredo(int undo) |
7 | 2614 { |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2615 undoline_T *newarray = NULL; |
7 | 2616 linenr_T oldsize; |
2617 linenr_T newsize; | |
2618 linenr_T top, bot; | |
2619 linenr_T lnum; | |
2620 linenr_T newlnum = MAXLNUM; | |
2621 long i; | |
2622 u_entry_T *uep, *nuep; | |
2623 u_entry_T *newlist = NULL; | |
2624 int old_flags; | |
2625 int new_flags; | |
2626 pos_T namedm[NMARKS]; | |
692 | 2627 visualinfo_T visualinfo; |
7 | 2628 int empty_buffer; /* buffer became empty */ |
758 | 2629 u_header_T *curhead = curbuf->b_u_curhead; |
7 | 2630 |
2189 | 2631 /* Don't want autocommands using the undo structures here, they are |
2632 * invalid till the end. */ | |
2633 block_autocmds(); | |
2634 | |
1415 | 2635 #ifdef U_DEBUG |
2636 u_check(FALSE); | |
2637 #endif | |
758 | 2638 old_flags = curhead->uh_flags; |
7 | 2639 new_flags = (curbuf->b_changed ? UH_CHANGED : 0) + |
2640 ((curbuf->b_ml.ml_flags & ML_EMPTY) ? UH_EMPTYBUF : 0); | |
2641 setpcmark(); | |
2642 | |
2643 /* | |
2644 * save marks before undo/redo | |
2645 */ | |
2646 mch_memmove(namedm, curbuf->b_namedm, sizeof(pos_T) * NMARKS); | |
692 | 2647 visualinfo = curbuf->b_visual; |
7 | 2648 curbuf->b_op_start.lnum = curbuf->b_ml.ml_line_count; |
2649 curbuf->b_op_start.col = 0; | |
2650 curbuf->b_op_end.lnum = 0; | |
2651 curbuf->b_op_end.col = 0; | |
2652 | |
758 | 2653 for (uep = curhead->uh_entry; uep != NULL; uep = nuep) |
7 | 2654 { |
2655 top = uep->ue_top; | |
2656 bot = uep->ue_bot; | |
2657 if (bot == 0) | |
2658 bot = curbuf->b_ml.ml_line_count + 1; | |
2659 if (top > curbuf->b_ml.ml_line_count || top >= bot | |
2660 || bot > curbuf->b_ml.ml_line_count + 1) | |
2661 { | |
2189 | 2662 unblock_autocmds(); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
2663 iemsg(_("E438: u_undo: line numbers wrong")); |
7 | 2664 changed(); /* don't want UNCHANGED now */ |
2665 return; | |
2666 } | |
2667 | |
2668 oldsize = bot - top - 1; /* number of lines before undo */ | |
2669 newsize = uep->ue_size; /* number of lines after undo */ | |
2670 | |
2671 if (top < newlnum) | |
2672 { | |
2673 /* If the saved cursor is somewhere in this undo block, move it to | |
2674 * the remembered position. Makes "gwap" put the cursor back | |
2675 * where it was. */ | |
758 | 2676 lnum = curhead->uh_cursor.lnum; |
7 | 2677 if (lnum >= top && lnum <= top + newsize + 1) |
2678 { | |
758 | 2679 curwin->w_cursor = curhead->uh_cursor; |
7 | 2680 newlnum = curwin->w_cursor.lnum - 1; |
2681 } | |
2682 else | |
2683 { | |
2684 /* Use the first line that actually changed. Avoids that | |
2685 * undoing auto-formatting puts the cursor in the previous | |
2686 * line. */ | |
2687 for (i = 0; i < newsize && i < oldsize; ++i) | |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2688 { |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2689 char_u *p = ml_get(top + 1 + i); |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2690 |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2691 if (curbuf->b_ml.ml_line_len != uep->ue_array[i].ul_len |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2692 || memcmp(uep->ue_array[i].ul_line, p, curbuf->b_ml.ml_line_len) != 0) |
7 | 2693 break; |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2694 } |
7 | 2695 if (i == newsize && newlnum == MAXLNUM && uep->ue_next == NULL) |
2696 { | |
2697 newlnum = top; | |
2698 curwin->w_cursor.lnum = newlnum + 1; | |
2699 } | |
2700 else if (i < newsize) | |
2701 { | |
2702 newlnum = top + i; | |
2703 curwin->w_cursor.lnum = newlnum + 1; | |
2704 } | |
2705 } | |
2706 } | |
2707 | |
2708 empty_buffer = FALSE; | |
2709 | |
2710 /* delete the lines between top and bot and save them in newarray */ | |
168 | 2711 if (oldsize > 0) |
7 | 2712 { |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2713 if ((newarray = (undoline_T *)U_ALLOC_LINE( |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2714 sizeof(undoline_T) * oldsize)) == NULL) |
7 | 2715 { |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2716 do_outofmem_msg((long_u)(sizeof(undoline_T) * oldsize)); |
7 | 2717 /* |
2718 * We have messed up the entry list, repair is impossible. | |
2719 * we have to free the rest of the list. | |
2720 */ | |
2721 while (uep != NULL) | |
2722 { | |
2723 nuep = uep->ue_next; | |
2724 u_freeentry(uep, uep->ue_size); | |
2725 uep = nuep; | |
2726 } | |
2727 break; | |
2728 } | |
2729 /* delete backwards, it goes faster in most cases */ | |
2730 for (lnum = bot - 1, i = oldsize; --i >= 0; --lnum) | |
2731 { | |
2732 /* what can we do when we run out of memory? */ | |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2733 if (u_save_line(&newarray[i], lnum) == FAIL) |
7 | 2734 do_outofmem_msg((long_u)0); |
2735 /* remember we deleted the last line in the buffer, and a | |
2736 * dummy empty line will be inserted */ | |
2737 if (curbuf->b_ml.ml_line_count == 1) | |
2738 empty_buffer = TRUE; | |
2739 ml_delete(lnum, FALSE); | |
2740 } | |
2741 } | |
414 | 2742 else |
2743 newarray = NULL; | |
7 | 2744 |
2745 /* insert the lines in u_array between top and bot */ | |
2746 if (newsize) | |
2747 { | |
2748 for (lnum = top, i = 0; i < newsize; ++i, ++lnum) | |
2749 { | |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2750 // If the file is empty, there is an empty line 1 that we |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2751 // should get rid of, by replacing it with the new line. |
7 | 2752 if (empty_buffer && lnum == 0) |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2753 ml_replace_len((linenr_T)1, uep->ue_array[i].ul_line, uep->ue_array[i].ul_len, TRUE, TRUE); |
7 | 2754 else |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2755 ml_append(lnum, uep->ue_array[i].ul_line, (colnr_T)uep->ue_array[i].ul_len, FALSE); |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2756 vim_free(uep->ue_array[i].ul_line); |
7 | 2757 } |
2230
290ee42cae85
Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2758 vim_free((char_u *)uep->ue_array); |
7 | 2759 } |
2760 | |
2761 /* adjust marks */ | |
2762 if (oldsize != newsize) | |
2763 { | |
2764 mark_adjust(top + 1, top + oldsize, (long)MAXLNUM, | |
2765 (long)newsize - (long)oldsize); | |
2766 if (curbuf->b_op_start.lnum > top + oldsize) | |
2767 curbuf->b_op_start.lnum += newsize - oldsize; | |
2768 if (curbuf->b_op_end.lnum > top + oldsize) | |
2769 curbuf->b_op_end.lnum += newsize - oldsize; | |
2770 } | |
2771 | |
2772 changed_lines(top + 1, 0, bot, newsize - oldsize); | |
2773 | |
2774 /* set '[ and '] mark */ | |
2775 if (top + 1 < curbuf->b_op_start.lnum) | |
2776 curbuf->b_op_start.lnum = top + 1; | |
2777 if (newsize == 0 && top + 1 > curbuf->b_op_end.lnum) | |
2778 curbuf->b_op_end.lnum = top + 1; | |
2779 else if (top + newsize > curbuf->b_op_end.lnum) | |
2780 curbuf->b_op_end.lnum = top + newsize; | |
2781 | |
2782 u_newcount += newsize; | |
2783 u_oldcount += oldsize; | |
2784 uep->ue_size = oldsize; | |
2785 uep->ue_array = newarray; | |
2786 uep->ue_bot = top + newsize + 1; | |
2787 | |
2788 /* | |
2789 * insert this entry in front of the new entry list | |
2790 */ | |
2791 nuep = uep->ue_next; | |
2792 uep->ue_next = newlist; | |
2793 newlist = uep; | |
2794 } | |
2795 | |
758 | 2796 curhead->uh_entry = newlist; |
2797 curhead->uh_flags = new_flags; | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10978
diff
changeset
|
2798 if ((old_flags & UH_EMPTYBUF) && BUFEMPTY()) |
7 | 2799 curbuf->b_ml.ml_flags |= ML_EMPTY; |
2800 if (old_flags & UH_CHANGED) | |
2801 changed(); | |
2802 else | |
33 | 2803 #ifdef FEAT_NETBEANS_INTG |
2804 /* per netbeans undo rules, keep it as modified */ | |
2805 if (!isNetbeansModified(curbuf)) | |
2806 #endif | |
7 | 2807 unchanged(curbuf, FALSE); |
2808 | |
2809 /* | |
2810 * restore marks from before undo/redo | |
2811 */ | |
2812 for (i = 0; i < NMARKS; ++i) | |
6616 | 2813 { |
758 | 2814 if (curhead->uh_namedm[i].lnum != 0) |
2815 curbuf->b_namedm[i] = curhead->uh_namedm[i]; | |
6616 | 2816 if (namedm[i].lnum != 0) |
758 | 2817 curhead->uh_namedm[i] = namedm[i]; |
6616 | 2818 else |
2819 curhead->uh_namedm[i].lnum = 0; | |
2820 } | |
758 | 2821 if (curhead->uh_visual.vi_start.lnum != 0) |
692 | 2822 { |
758 | 2823 curbuf->b_visual = curhead->uh_visual; |
2824 curhead->uh_visual = visualinfo; | |
692 | 2825 } |
7 | 2826 |
2827 /* | |
2828 * If the cursor is only off by one line, put it at the same position as | |
2829 * before starting the change (for the "o" command). | |
2830 * Otherwise the cursor should go to the first undone line. | |
2831 */ | |
758 | 2832 if (curhead->uh_cursor.lnum + 1 == curwin->w_cursor.lnum |
7 | 2833 && curwin->w_cursor.lnum > 1) |
2834 --curwin->w_cursor.lnum; | |
2501
c43e99e9baaf
Fix: ml_get errors when using undo with 'virtualedit'.
Bram Moolenaar <bram@vim.org>
parents:
2482
diff
changeset
|
2835 if (curwin->w_cursor.lnum <= curbuf->b_ml.ml_line_count) |
7 | 2836 { |
2501
c43e99e9baaf
Fix: ml_get errors when using undo with 'virtualedit'.
Bram Moolenaar <bram@vim.org>
parents:
2482
diff
changeset
|
2837 if (curhead->uh_cursor.lnum == curwin->w_cursor.lnum) |
c43e99e9baaf
Fix: ml_get errors when using undo with 'virtualedit'.
Bram Moolenaar <bram@vim.org>
parents:
2482
diff
changeset
|
2838 { |
c43e99e9baaf
Fix: ml_get errors when using undo with 'virtualedit'.
Bram Moolenaar <bram@vim.org>
parents:
2482
diff
changeset
|
2839 curwin->w_cursor.col = curhead->uh_cursor.col; |
c43e99e9baaf
Fix: ml_get errors when using undo with 'virtualedit'.
Bram Moolenaar <bram@vim.org>
parents:
2482
diff
changeset
|
2840 if (virtual_active() && curhead->uh_cursor_vcol >= 0) |
c43e99e9baaf
Fix: ml_get errors when using undo with 'virtualedit'.
Bram Moolenaar <bram@vim.org>
parents:
2482
diff
changeset
|
2841 coladvance((colnr_T)curhead->uh_cursor_vcol); |
c43e99e9baaf
Fix: ml_get errors when using undo with 'virtualedit'.
Bram Moolenaar <bram@vim.org>
parents:
2482
diff
changeset
|
2842 else |
c43e99e9baaf
Fix: ml_get errors when using undo with 'virtualedit'.
Bram Moolenaar <bram@vim.org>
parents:
2482
diff
changeset
|
2843 curwin->w_cursor.coladd = 0; |
c43e99e9baaf
Fix: ml_get errors when using undo with 'virtualedit'.
Bram Moolenaar <bram@vim.org>
parents:
2482
diff
changeset
|
2844 } |
7 | 2845 else |
2501
c43e99e9baaf
Fix: ml_get errors when using undo with 'virtualedit'.
Bram Moolenaar <bram@vim.org>
parents:
2482
diff
changeset
|
2846 beginline(BL_SOL | BL_FIX); |
7 | 2847 } |
2848 else | |
2849 { | |
2850 /* We get here with the current cursor line being past the end (eg | |
2851 * after adding lines at the end of the file, and then undoing it). | |
2852 * check_cursor() will move the cursor to the last line. Move it to | |
2853 * the first column here. */ | |
2854 curwin->w_cursor.col = 0; | |
2855 curwin->w_cursor.coladd = 0; | |
2856 } | |
2857 | |
2858 /* Make sure the cursor is on an existing line and column. */ | |
2859 check_cursor(); | |
758 | 2860 |
2861 /* Remember where we are for "g-" and ":earlier 10s". */ | |
2862 curbuf->b_u_seq_cur = curhead->uh_seq; | |
777 | 2863 if (undo) |
12827
ff494a964ab7
patch 8.0.1290: seq_cur of undotree() wrong after undo
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2864 { |
777 | 2865 /* We are below the previous undo. However, to make ":earlier 1s" |
2866 * work we compute this as being just above the just undone change. */ | |
12827
ff494a964ab7
patch 8.0.1290: seq_cur of undotree() wrong after undo
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2867 if (curhead->uh_next.ptr != NULL) |
ff494a964ab7
patch 8.0.1290: seq_cur of undotree() wrong after undo
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2868 curbuf->b_u_seq_cur = curhead->uh_next.ptr->uh_seq; |
ff494a964ab7
patch 8.0.1290: seq_cur of undotree() wrong after undo
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2869 else |
ff494a964ab7
patch 8.0.1290: seq_cur of undotree() wrong after undo
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2870 curbuf->b_u_seq_cur = 0; |
ff494a964ab7
patch 8.0.1290: seq_cur of undotree() wrong after undo
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2871 } |
777 | 2872 |
2281
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2873 /* Remember where we are for ":earlier 1f" and ":later 1f". */ |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2874 if (curhead->uh_save_nr != 0) |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2875 { |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2876 if (undo) |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2877 curbuf->b_u_save_nr_cur = curhead->uh_save_nr - 1; |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2878 else |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2879 curbuf->b_u_save_nr_cur = curhead->uh_save_nr; |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2880 } |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
2881 |
777 | 2882 /* The timestamp can be the same for multiple changes, just use the one of |
2883 * the undone/redone change. */ | |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
2884 curbuf->b_u_time_cur = curhead->uh_time; |
2189 | 2885 |
2886 unblock_autocmds(); | |
1415 | 2887 #ifdef U_DEBUG |
2888 u_check(FALSE); | |
2889 #endif | |
7 | 2890 } |
2891 | |
2892 /* | |
2893 * If we deleted or added lines, report the number of less/more lines. | |
2894 * Otherwise, report the number of changes (this may be incorrect | |
2895 * in some cases, but it's better than nothing). | |
2896 */ | |
2897 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2898 u_undo_end( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2899 int did_undo, /* just did an undo */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2900 int absolute) /* used ":undo N" */ |
7 | 2901 { |
944 | 2902 char *msgstr; |
772 | 2903 u_header_T *uhp; |
2904 char_u msgbuf[80]; | |
753 | 2905 |
7 | 2906 #ifdef FEAT_FOLDING |
2907 if ((fdo_flags & FDO_UNDO) && KeyTyped) | |
2908 foldOpenCursor(); | |
2909 #endif | |
753 | 2910 |
2911 if (global_busy /* no messages now, wait until global is finished */ | |
2912 || !messaging()) /* 'lazyredraw' set, don't do messages now */ | |
2913 return; | |
2914 | |
2915 if (curbuf->b_ml.ml_flags & ML_EMPTY) | |
2916 --u_newcount; | |
2917 | |
2918 u_oldcount -= u_newcount; | |
2919 if (u_oldcount == -1) | |
944 | 2920 msgstr = N_("more line"); |
753 | 2921 else if (u_oldcount < 0) |
944 | 2922 msgstr = N_("more lines"); |
753 | 2923 else if (u_oldcount == 1) |
944 | 2924 msgstr = N_("line less"); |
753 | 2925 else if (u_oldcount > 1) |
944 | 2926 msgstr = N_("fewer lines"); |
753 | 2927 else |
2928 { | |
2929 u_oldcount = u_newcount; | |
2930 if (u_newcount == 1) | |
944 | 2931 msgstr = N_("change"); |
753 | 2932 else |
944 | 2933 msgstr = N_("changes"); |
753 | 2934 } |
2935 | |
772 | 2936 if (curbuf->b_u_curhead != NULL) |
794 | 2937 { |
798 | 2938 /* For ":undo N" we prefer a "after #N" message. */ |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2939 if (absolute && curbuf->b_u_curhead->uh_next.ptr != NULL) |
798 | 2940 { |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2941 uhp = curbuf->b_u_curhead->uh_next.ptr; |
798 | 2942 did_undo = FALSE; |
2943 } | |
2944 else if (did_undo) | |
794 | 2945 uhp = curbuf->b_u_curhead; |
2946 else | |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
2947 uhp = curbuf->b_u_curhead->uh_next.ptr; |
794 | 2948 } |
753 | 2949 else |
772 | 2950 uhp = curbuf->b_u_newhead; |
753 | 2951 |
772 | 2952 if (uhp == NULL) |
2953 *msgbuf = NUL; | |
2954 else | |
2955 u_add_time(msgbuf, sizeof(msgbuf), uhp->uh_time); | |
2956 | |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2281
diff
changeset
|
2957 #ifdef FEAT_CONCEAL |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2281
diff
changeset
|
2958 { |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2281
diff
changeset
|
2959 win_T *wp; |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2281
diff
changeset
|
2960 |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2281
diff
changeset
|
2961 FOR_ALL_WINDOWS(wp) |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2281
diff
changeset
|
2962 { |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2367
diff
changeset
|
2963 if (wp->w_buffer == curbuf && wp->w_p_cole > 0) |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2281
diff
changeset
|
2964 redraw_win_later(wp, NOT_VALID); |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2281
diff
changeset
|
2965 } |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2281
diff
changeset
|
2966 } |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2281
diff
changeset
|
2967 #endif |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2281
diff
changeset
|
2968 |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
2969 smsg_attr_keep(0, _("%ld %s; %s #%ld %s"), |
777 | 2970 u_oldcount < 0 ? -u_oldcount : u_oldcount, |
944 | 2971 _(msgstr), |
794 | 2972 did_undo ? _("before") : _("after"), |
2973 uhp == NULL ? 0L : uhp->uh_seq, | |
2974 msgbuf); | |
7 | 2975 } |
2976 | |
2977 /* | |
2978 * u_sync: stop adding to the current entry list | |
2979 */ | |
2980 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2981 u_sync( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2982 int force) /* Also sync when no_u_sync is set. */ |
7 | 2983 { |
825 | 2984 /* Skip it when already synced or syncing is disabled. */ |
2985 if (curbuf->b_u_synced || (!force && no_u_sync > 0)) | |
2986 return; | |
7 | 2987 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
12293
1ff5e5dfa9b0
patch 8.0.1026: GTK on-the-spot input has problems
Christian Brabandt <cb@256bit.org>
parents:
12216
diff
changeset
|
2988 if (p_imst == IM_ON_THE_SPOT && im_is_preediting()) |
7 | 2989 return; /* XIM is busy, don't break an undo sequence */ |
2990 #endif | |
5446 | 2991 if (get_undolevel() < 0) |
7 | 2992 curbuf->b_u_synced = TRUE; /* no entries, nothing to do */ |
2993 else | |
2994 { | |
2995 u_getbot(); /* compute ue_bot of previous u_save */ | |
2996 curbuf->b_u_curhead = NULL; | |
2997 } | |
2998 } | |
2999 | |
3000 /* | |
772 | 3001 * ":undolist": List the leafs of the undo tree |
3002 */ | |
3003 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3004 ex_undolist(exarg_T *eap UNUSED) |
772 | 3005 { |
3006 garray_T ga; | |
3007 u_header_T *uhp; | |
3008 int mark; | |
3009 int nomark; | |
3010 int changes = 1; | |
3011 int i; | |
3012 | |
3013 /* | |
3014 * 1: walk the tree to find all leafs, put the info in "ga". | |
3015 * 2: sort the lines | |
3016 * 3: display the list | |
3017 */ | |
3018 mark = ++lastmark; | |
3019 nomark = ++lastmark; | |
3020 ga_init2(&ga, (int)sizeof(char *), 20); | |
3021 | |
3022 uhp = curbuf->b_u_oldhead; | |
3023 while (uhp != NULL) | |
3024 { | |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3025 if (uhp->uh_prev.ptr == NULL && uhp->uh_walk != nomark |
777 | 3026 && uhp->uh_walk != mark) |
772 | 3027 { |
3028 if (ga_grow(&ga, 1) == FAIL) | |
3029 break; | |
13610
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
3030 vim_snprintf((char *)IObuff, IOSIZE, "%6ld %7d ", |
772 | 3031 uhp->uh_seq, changes); |
3032 u_add_time(IObuff + STRLEN(IObuff), IOSIZE - STRLEN(IObuff), | |
3033 uhp->uh_time); | |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3034 if (uhp->uh_save_nr > 0) |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3035 { |
2627 | 3036 while (STRLEN(IObuff) < 33) |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3037 STRCAT(IObuff, " "); |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3038 vim_snprintf_add((char *)IObuff, IOSIZE, |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3039 " %3ld", uhp->uh_save_nr); |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3040 } |
772 | 3041 ((char_u **)(ga.ga_data))[ga.ga_len++] = vim_strsave(IObuff); |
3042 } | |
3043 | |
3044 uhp->uh_walk = mark; | |
3045 | |
3046 /* go down in the tree if we haven't been there */ | |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3047 if (uhp->uh_prev.ptr != NULL && uhp->uh_prev.ptr->uh_walk != nomark |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3048 && uhp->uh_prev.ptr->uh_walk != mark) |
772 | 3049 { |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3050 uhp = uhp->uh_prev.ptr; |
772 | 3051 ++changes; |
3052 } | |
3053 | |
3054 /* go to alternate branch if we haven't been there */ | |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3055 else if (uhp->uh_alt_next.ptr != NULL |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3056 && uhp->uh_alt_next.ptr->uh_walk != nomark |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3057 && uhp->uh_alt_next.ptr->uh_walk != mark) |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3058 uhp = uhp->uh_alt_next.ptr; |
772 | 3059 |
3060 /* go up in the tree if we haven't been there and we are at the | |
3061 * start of alternate branches */ | |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3062 else if (uhp->uh_next.ptr != NULL && uhp->uh_alt_prev.ptr == NULL |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3063 && uhp->uh_next.ptr->uh_walk != nomark |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3064 && uhp->uh_next.ptr->uh_walk != mark) |
772 | 3065 { |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3066 uhp = uhp->uh_next.ptr; |
772 | 3067 --changes; |
3068 } | |
3069 | |
3070 else | |
3071 { | |
3072 /* need to backtrack; mark this node as done */ | |
3073 uhp->uh_walk = nomark; | |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3074 if (uhp->uh_alt_prev.ptr != NULL) |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3075 uhp = uhp->uh_alt_prev.ptr; |
772 | 3076 else |
3077 { | |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3078 uhp = uhp->uh_next.ptr; |
772 | 3079 --changes; |
3080 } | |
3081 } | |
3082 } | |
3083 | |
3084 if (ga.ga_len == 0) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3085 msg(_("Nothing to undo")); |
772 | 3086 else |
3087 { | |
3088 sort_strings((char_u **)ga.ga_data, ga.ga_len); | |
3089 | |
3090 msg_start(); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3091 msg_puts_attr(_("number changes when saved"), |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
3092 HL_ATTR(HLF_T)); |
772 | 3093 for (i = 0; i < ga.ga_len && !got_int; ++i) |
3094 { | |
3095 msg_putchar('\n'); | |
3096 if (got_int) | |
3097 break; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3098 msg_puts(((char **)ga.ga_data)[i]); |
772 | 3099 } |
3100 msg_end(); | |
3101 | |
3102 ga_clear_strings(&ga); | |
3103 } | |
3104 } | |
3105 | |
3106 /* | |
3107 * Put the timestamp of an undo header in "buf[buflen]" in a nice format. | |
3108 */ | |
3109 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3110 u_add_time(char_u *buf, size_t buflen, time_t tt) |
772 | 3111 { |
3112 #ifdef HAVE_STRFTIME | |
3113 struct tm *curtime; | |
3114 | |
9674
adc7212951ee
commit https://github.com/vim/vim/commit/170b10b421f0c9fda08b7cfd3bb043c064f3659a
Christian Brabandt <cb@256bit.org>
parents:
9536
diff
changeset
|
3115 if (vim_time() - tt >= 100) |
772 | 3116 { |
3117 curtime = localtime(&tt); | |
9674
adc7212951ee
commit https://github.com/vim/vim/commit/170b10b421f0c9fda08b7cfd3bb043c064f3659a
Christian Brabandt <cb@256bit.org>
parents:
9536
diff
changeset
|
3118 if (vim_time() - tt < (60L * 60L * 12L)) |
2627 | 3119 /* within 12 hours */ |
3120 (void)strftime((char *)buf, buflen, "%H:%M:%S", curtime); | |
3121 else | |
3751 | 3122 /* longer ago */ |
2689 | 3123 (void)strftime((char *)buf, buflen, "%Y/%m/%d %H:%M:%S", curtime); |
772 | 3124 } |
3125 else | |
3126 #endif | |
14589
9c9ee53868b9
patch 8.1.0308: a quick undo shows "1 seconds ago"
Christian Brabandt <cb@256bit.org>
parents:
14327
diff
changeset
|
3127 { |
9c9ee53868b9
patch 8.1.0308: a quick undo shows "1 seconds ago"
Christian Brabandt <cb@256bit.org>
parents:
14327
diff
changeset
|
3128 long seconds = (long)(vim_time() - tt); |
9c9ee53868b9
patch 8.1.0308: a quick undo shows "1 seconds ago"
Christian Brabandt <cb@256bit.org>
parents:
14327
diff
changeset
|
3129 |
9c9ee53868b9
patch 8.1.0308: a quick undo shows "1 seconds ago"
Christian Brabandt <cb@256bit.org>
parents:
14327
diff
changeset
|
3130 vim_snprintf((char *)buf, buflen, |
9c9ee53868b9
patch 8.1.0308: a quick undo shows "1 seconds ago"
Christian Brabandt <cb@256bit.org>
parents:
14327
diff
changeset
|
3131 NGETTEXT("%ld second ago", "%ld seconds ago", seconds), |
9c9ee53868b9
patch 8.1.0308: a quick undo shows "1 seconds ago"
Christian Brabandt <cb@256bit.org>
parents:
14327
diff
changeset
|
3132 seconds); |
9c9ee53868b9
patch 8.1.0308: a quick undo shows "1 seconds ago"
Christian Brabandt <cb@256bit.org>
parents:
14327
diff
changeset
|
3133 } |
772 | 3134 } |
3135 | |
3136 /* | |
697 | 3137 * ":undojoin": continue adding to the last entry list |
3138 */ | |
3139 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3140 ex_undojoin(exarg_T *eap UNUSED) |
697 | 3141 { |
839 | 3142 if (curbuf->b_u_newhead == NULL) |
3143 return; /* nothing changed before */ | |
3144 if (curbuf->b_u_curhead != NULL) | |
3145 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
3146 emsg(_("E790: undojoin is not allowed after undo")); |
839 | 3147 return; |
3148 } | |
697 | 3149 if (!curbuf->b_u_synced) |
3150 return; /* already unsynced */ | |
5446 | 3151 if (get_undolevel() < 0) |
697 | 3152 return; /* no entries, nothing to do */ |
3153 else | |
10631
cbf17371627c
patch 8.0.0205: wrong behavior after :undojoin
Christian Brabandt <cb@256bit.org>
parents:
10518
diff
changeset
|
3154 /* Append next change to the last entry */ |
cbf17371627c
patch 8.0.0205: wrong behavior after :undojoin
Christian Brabandt <cb@256bit.org>
parents:
10518
diff
changeset
|
3155 curbuf->b_u_synced = FALSE; |
697 | 3156 } |
3157 | |
3158 /* | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
3159 * Called after writing or reloading the file and setting b_changed to FALSE. |
7 | 3160 * Now an undo means that the buffer is modified. |
3161 */ | |
3162 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3163 u_unchanged(buf_T *buf) |
7 | 3164 { |
758 | 3165 u_unch_branch(buf->b_u_oldhead); |
3166 buf->b_did_warn = FALSE; | |
3167 } | |
3168 | |
2281
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
3169 /* |
2482
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3170 * After reloading a buffer which was saved for 'undoreload': Find the first |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3171 * line that was changed and set the cursor there. |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3172 */ |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3173 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3174 u_find_first_changed(void) |
2482
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3175 { |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3176 u_header_T *uhp = curbuf->b_u_newhead; |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3177 u_entry_T *uep; |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3178 linenr_T lnum; |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3179 |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3180 if (curbuf->b_u_curhead != NULL || uhp == NULL) |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3181 return; /* undid something in an autocmd? */ |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3182 |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3183 /* Check that the last undo block was for the whole file. */ |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3184 uep = uhp->uh_entry; |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3185 if (uep->ue_top != 0 || uep->ue_bot != 0) |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3186 return; |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3187 |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3188 for (lnum = 1; lnum < curbuf->b_ml.ml_line_count |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3189 && lnum <= uep->ue_size; ++lnum) |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3190 { |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3191 char_u *p = ml_get_buf(curbuf, lnum, FALSE); |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3192 |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3193 if (uep->ue_array[lnum - 1].ul_len != curbuf->b_ml.ml_line_len |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3194 || memcmp(p, uep->ue_array[lnum - 1].ul_line, uep->ue_array[lnum - 1].ul_len) != 0) |
2482
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3195 { |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10978
diff
changeset
|
3196 CLEAR_POS(&(uhp->uh_cursor)); |
2482
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3197 uhp->uh_cursor.lnum = lnum; |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3198 return; |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3199 } |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3200 } |
2482
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3201 if (curbuf->b_ml.ml_line_count != uep->ue_size) |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3202 { |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3203 /* lines added or deleted at the end, put the cursor there */ |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10978
diff
changeset
|
3204 CLEAR_POS(&(uhp->uh_cursor)); |
2482
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3205 uhp->uh_cursor.lnum = lnum; |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3206 } |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3207 } |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3208 |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
3209 /* |
2281
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
3210 * Increase the write count, store it in the last undo header, what would be |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
3211 * used for "u". |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
3212 */ |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
3213 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3214 u_update_save_nr(buf_T *buf) |
2281
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
3215 { |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
3216 u_header_T *uhp; |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
3217 |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
3218 ++buf->b_u_save_nr_last; |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
3219 buf->b_u_save_nr_cur = buf->b_u_save_nr_last; |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
3220 uhp = buf->b_u_curhead; |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
3221 if (uhp != NULL) |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
3222 uhp = uhp->uh_next.ptr; |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
3223 else |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
3224 uhp = buf->b_u_newhead; |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
3225 if (uhp != NULL) |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
3226 uhp->uh_save_nr = buf->b_u_save_nr_last; |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
3227 } |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
3228 |
758 | 3229 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3230 u_unch_branch(u_header_T *uhp) |
758 | 3231 { |
753 | 3232 u_header_T *uh; |
7 | 3233 |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3234 for (uh = uhp; uh != NULL; uh = uh->uh_prev.ptr) |
758 | 3235 { |
7 | 3236 uh->uh_flags |= UH_CHANGED; |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3237 if (uh->uh_alt_next.ptr != NULL) |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3238 u_unch_branch(uh->uh_alt_next.ptr); /* recursive */ |
758 | 3239 } |
7 | 3240 } |
3241 | |
3242 /* | |
3243 * Get pointer to last added entry. | |
3244 * If it's not valid, give an error message and return NULL. | |
3245 */ | |
3246 static u_entry_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3247 u_get_headentry(void) |
7 | 3248 { |
3249 if (curbuf->b_u_newhead == NULL || curbuf->b_u_newhead->uh_entry == NULL) | |
3250 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
3251 iemsg(_("E439: undo list corrupt")); |
7 | 3252 return NULL; |
3253 } | |
3254 return curbuf->b_u_newhead->uh_entry; | |
3255 } | |
3256 | |
3257 /* | |
3258 * u_getbot(): compute the line number of the previous u_save | |
3259 * It is called only when b_u_synced is FALSE. | |
3260 */ | |
3261 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3262 u_getbot(void) |
7 | 3263 { |
3264 u_entry_T *uep; | |
3265 linenr_T extra; | |
3266 | |
3267 uep = u_get_headentry(); /* check for corrupt undo list */ | |
3268 if (uep == NULL) | |
3269 return; | |
3270 | |
3271 uep = curbuf->b_u_newhead->uh_getbot_entry; | |
3272 if (uep != NULL) | |
3273 { | |
3274 /* | |
3275 * the new ue_bot is computed from the number of lines that has been | |
3276 * inserted (0 - deleted) since calling u_save. This is equal to the | |
3277 * old line count subtracted from the current line count. | |
3278 */ | |
3279 extra = curbuf->b_ml.ml_line_count - uep->ue_lcount; | |
3280 uep->ue_bot = uep->ue_top + uep->ue_size + 1 + extra; | |
3281 if (uep->ue_bot < 1 || uep->ue_bot > curbuf->b_ml.ml_line_count) | |
3282 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15390
diff
changeset
|
3283 iemsg(_("E440: undo line missing")); |
7 | 3284 uep->ue_bot = uep->ue_top + 1; /* assume all lines deleted, will |
3285 * get all the old lines back | |
3286 * without deleting the current | |
3287 * ones */ | |
3288 } | |
3289 | |
3290 curbuf->b_u_newhead->uh_getbot_entry = NULL; | |
3291 } | |
3292 | |
3293 curbuf->b_u_synced = TRUE; | |
3294 } | |
3295 | |
3296 /* | |
1415 | 3297 * Free one header "uhp" and its entry list and adjust the pointers. |
7 | 3298 */ |
3299 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3300 u_freeheader( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3301 buf_T *buf, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3302 u_header_T *uhp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3303 u_header_T **uhpp) /* if not NULL reset when freeing this header */ |
7 | 3304 { |
1415 | 3305 u_header_T *uhap; |
3306 | |
753 | 3307 /* When there is an alternate redo list free that branch completely, |
3308 * because we can never go there. */ | |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3309 if (uhp->uh_alt_next.ptr != NULL) |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3310 u_freebranch(buf, uhp->uh_alt_next.ptr, uhpp); |
7 | 3311 |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3312 if (uhp->uh_alt_prev.ptr != NULL) |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3313 uhp->uh_alt_prev.ptr->uh_alt_next.ptr = NULL; |
7 | 3314 |
753 | 3315 /* Update the links in the list to remove the header. */ |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3316 if (uhp->uh_next.ptr == NULL) |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3317 buf->b_u_oldhead = uhp->uh_prev.ptr; |
7 | 3318 else |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3319 uhp->uh_next.ptr->uh_prev.ptr = uhp->uh_prev.ptr; |
7 | 3320 |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3321 if (uhp->uh_prev.ptr == NULL) |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3322 buf->b_u_newhead = uhp->uh_next.ptr; |
7 | 3323 else |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3324 for (uhap = uhp->uh_prev.ptr; uhap != NULL; |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3325 uhap = uhap->uh_alt_next.ptr) |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3326 uhap->uh_next.ptr = uhp->uh_next.ptr; |
7 | 3327 |
753 | 3328 u_freeentries(buf, uhp, uhpp); |
3329 } | |
3330 | |
3331 /* | |
758 | 3332 * Free an alternate branch and any following alternate branches. |
753 | 3333 */ |
3334 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3335 u_freebranch( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3336 buf_T *buf, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3337 u_header_T *uhp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3338 u_header_T **uhpp) /* if not NULL reset when freeing this header */ |
753 | 3339 { |
3340 u_header_T *tofree, *next; | |
3341 | |
1440 | 3342 /* If this is the top branch we may need to use u_freeheader() to update |
3343 * all the pointers. */ | |
3344 if (uhp == buf->b_u_oldhead) | |
3345 { | |
5448 | 3346 while (buf->b_u_oldhead != NULL) |
3347 u_freeheader(buf, buf->b_u_oldhead, uhpp); | |
1440 | 3348 return; |
3349 } | |
3350 | |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3351 if (uhp->uh_alt_prev.ptr != NULL) |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3352 uhp->uh_alt_prev.ptr->uh_alt_next.ptr = NULL; |
753 | 3353 |
3354 next = uhp; | |
3355 while (next != NULL) | |
3356 { | |
3357 tofree = next; | |
2242
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3358 if (tofree->uh_alt_next.ptr != NULL) |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3359 u_freebranch(buf, tofree->uh_alt_next.ptr, uhpp); /* recursive */ |
bc4685345719
Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
3360 next = tofree->uh_prev.ptr; |
753 | 3361 u_freeentries(buf, tofree, uhpp); |
3362 } | |
3363 } | |
3364 | |
3365 /* | |
3366 * Free all the undo entries for one header and the header itself. | |
3367 * This means that "uhp" is invalid when returning. | |
3368 */ | |
3369 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3370 u_freeentries( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3371 buf_T *buf, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3372 u_header_T *uhp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3373 u_header_T **uhpp) /* if not NULL reset when freeing this header */ |
753 | 3374 { |
3375 u_entry_T *uep, *nuep; | |
3376 | |
3377 /* Check for pointers to the header that become invalid now. */ | |
3378 if (buf->b_u_curhead == uhp) | |
3379 buf->b_u_curhead = NULL; | |
1415 | 3380 if (buf->b_u_newhead == uhp) |
3381 buf->b_u_newhead = NULL; /* freeing the newest entry */ | |
753 | 3382 if (uhpp != NULL && uhp == *uhpp) |
3383 *uhpp = NULL; | |
3384 | |
3385 for (uep = uhp->uh_entry; uep != NULL; uep = nuep) | |
3386 { | |
3387 nuep = uep->ue_next; | |
3388 u_freeentry(uep, uep->ue_size); | |
3389 } | |
3390 | |
1415 | 3391 #ifdef U_DEBUG |
3392 uhp->uh_magic = 0; | |
3393 #endif | |
2230
290ee42cae85
Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3394 vim_free((char_u *)uhp); |
168 | 3395 --buf->b_u_numhead; |
7 | 3396 } |
3397 | |
3398 /* | |
3399 * free entry 'uep' and 'n' lines in uep->ue_array[] | |
3400 */ | |
3401 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3402 u_freeentry(u_entry_T *uep, long n) |
7 | 3403 { |
414 | 3404 while (n > 0) |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3405 vim_free(uep->ue_array[--n].ul_line); |
2230
290ee42cae85
Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3406 vim_free((char_u *)uep->ue_array); |
1415 | 3407 #ifdef U_DEBUG |
3408 uep->ue_magic = 0; | |
3409 #endif | |
2230
290ee42cae85
Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3410 vim_free((char_u *)uep); |
7 | 3411 } |
3412 | |
3413 /* | |
3414 * invalidate the undo buffer; called when storage has already been released | |
3415 */ | |
3416 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3417 u_clearall(buf_T *buf) |
7 | 3418 { |
3419 buf->b_u_newhead = buf->b_u_oldhead = buf->b_u_curhead = NULL; | |
3420 buf->b_u_synced = TRUE; | |
3421 buf->b_u_numhead = 0; | |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3422 buf->b_u_line_ptr.ul_line = NULL; |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3423 buf->b_u_line_ptr.ul_len = 0; |
7 | 3424 buf->b_u_line_lnum = 0; |
3425 } | |
3426 | |
3427 /* | |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3428 * Save the line "lnum" for the "U" command. |
7 | 3429 */ |
3430 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3431 u_saveline(linenr_T lnum) |
7 | 3432 { |
3433 if (lnum == curbuf->b_u_line_lnum) /* line is already saved */ | |
3434 return; | |
356 | 3435 if (lnum < 1 || lnum > curbuf->b_ml.ml_line_count) /* should never happen */ |
7 | 3436 return; |
3437 u_clearline(); | |
3438 curbuf->b_u_line_lnum = lnum; | |
3439 if (curwin->w_cursor.lnum == lnum) | |
3440 curbuf->b_u_line_colnr = curwin->w_cursor.col; | |
3441 else | |
3442 curbuf->b_u_line_colnr = 0; | |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3443 if (u_save_line(&curbuf->b_u_line_ptr, lnum) == FAIL) |
7 | 3444 do_outofmem_msg((long_u)0); |
3445 } | |
3446 | |
3447 /* | |
3448 * clear the line saved for the "U" command | |
3449 * (this is used externally for crossing a line while in insert mode) | |
3450 */ | |
3451 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3452 u_clearline(void) |
7 | 3453 { |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3454 if (curbuf->b_u_line_ptr.ul_line != NULL) |
7 | 3455 { |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3456 VIM_CLEAR(curbuf->b_u_line_ptr.ul_line); |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3457 curbuf->b_u_line_ptr.ul_len = 0; |
7 | 3458 curbuf->b_u_line_lnum = 0; |
3459 } | |
3460 } | |
3461 | |
3462 /* | |
3463 * Implementation of the "U" command. | |
3464 * Differentiation from vi: "U" can be undone with the next "U". | |
3465 * We also allow the cursor to be in another line. | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2288
diff
changeset
|
3466 * Careful: may trigger autocommands that reload the buffer. |
7 | 3467 */ |
3468 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3469 u_undoline(void) |
7 | 3470 { |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3471 colnr_T t; |
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3472 undoline_T oldp; |
7 | 3473 |
3474 if (undo_off) | |
3475 return; | |
3476 | |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3477 if (curbuf->b_u_line_ptr.ul_line == NULL |
1534 | 3478 || curbuf->b_u_line_lnum > curbuf->b_ml.ml_line_count) |
7 | 3479 { |
3480 beep_flush(); | |
3481 return; | |
3482 } | |
1534 | 3483 |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3484 // first save the line for the 'u' command |
7 | 3485 if (u_savecommon(curbuf->b_u_line_lnum - 1, |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
3486 curbuf->b_u_line_lnum + 1, (linenr_T)0, FALSE) == FAIL) |
7 | 3487 return; |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3488 if (u_save_line(&oldp, curbuf->b_u_line_lnum) == FAIL) |
7 | 3489 { |
3490 do_outofmem_msg((long_u)0); | |
3491 return; | |
3492 } | |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3493 ml_replace_len(curbuf->b_u_line_lnum, curbuf->b_u_line_ptr.ul_line, curbuf->b_u_line_ptr.ul_len, TRUE, FALSE); |
7 | 3494 changed_bytes(curbuf->b_u_line_lnum, 0); |
3495 curbuf->b_u_line_ptr = oldp; | |
3496 | |
3497 t = curbuf->b_u_line_colnr; | |
3498 if (curwin->w_cursor.lnum == curbuf->b_u_line_lnum) | |
3499 curbuf->b_u_line_colnr = curwin->w_cursor.col; | |
3500 curwin->w_cursor.col = t; | |
3501 curwin->w_cursor.lnum = curbuf->b_u_line_lnum; | |
1534 | 3502 check_cursor_col(); |
7 | 3503 } |
3504 | |
3505 /* | |
168 | 3506 * Free all allocated memory blocks for the buffer 'buf'. |
3507 */ | |
3508 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3509 u_blockfree(buf_T *buf) |
168 | 3510 { |
753 | 3511 while (buf->b_u_oldhead != NULL) |
758 | 3512 u_freeheader(buf, buf->b_u_oldhead, NULL); |
15361
58b125df3e9b
patch 8.1.0688: text properties are not restored by undo
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3513 vim_free(buf->b_u_line_ptr.ul_line); |
7 | 3514 } |
3515 | |
3516 /* | |
3517 * Check if the 'modified' flag is set, or 'ff' has changed (only need to | |
3518 * check the first character, because it can only be "dos", "unix" or "mac"). | |
3519 * "nofile" and "scratch" type buffers are considered to always be unchanged. | |
13012
8d5b451d7bab
patch 8.0.1382: get "no write since last change" message if terminal is open
Christian Brabandt <cb@256bit.org>
parents:
12827
diff
changeset
|
3520 * Also considers a buffer changed when a terminal window contains a running |
8d5b451d7bab
patch 8.0.1382: get "no write since last change" message if terminal is open
Christian Brabandt <cb@256bit.org>
parents:
12827
diff
changeset
|
3521 * job. |
7 | 3522 */ |
3523 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3524 bufIsChanged(buf_T *buf) |
7 | 3525 { |
11957
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11836
diff
changeset
|
3526 #ifdef FEAT_TERMINAL |
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11836
diff
changeset
|
3527 if (term_job_running(buf->b_term)) |
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11836
diff
changeset
|
3528 return TRUE; |
7 | 3529 #endif |
13012
8d5b451d7bab
patch 8.0.1382: get "no write since last change" message if terminal is open
Christian Brabandt <cb@256bit.org>
parents:
12827
diff
changeset
|
3530 return bufIsChangedNotTerm(buf); |
8d5b451d7bab
patch 8.0.1382: get "no write since last change" message if terminal is open
Christian Brabandt <cb@256bit.org>
parents:
12827
diff
changeset
|
3531 } |
8d5b451d7bab
patch 8.0.1382: get "no write since last change" message if terminal is open
Christian Brabandt <cb@256bit.org>
parents:
12827
diff
changeset
|
3532 |
8d5b451d7bab
patch 8.0.1382: get "no write since last change" message if terminal is open
Christian Brabandt <cb@256bit.org>
parents:
12827
diff
changeset
|
3533 /* |
16089
4411c38f3d16
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3534 * Return TRUE if any buffer has changes. Also buffers that are not written. |
4411c38f3d16
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3535 */ |
4411c38f3d16
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3536 int |
4411c38f3d16
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3537 anyBufIsChanged(void) |
4411c38f3d16
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3538 { |
4411c38f3d16
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3539 buf_T *buf; |
4411c38f3d16
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3540 |
4411c38f3d16
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3541 FOR_ALL_BUFFERS(buf) |
4411c38f3d16
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3542 if (bufIsChanged(buf)) |
4411c38f3d16
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3543 return TRUE; |
16097
d45e42b45470
patch 8.1.1053: warning for missing return statement
Bram Moolenaar <Bram@vim.org>
parents:
16089
diff
changeset
|
3544 return FALSE; |
16089
4411c38f3d16
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3545 } |
4411c38f3d16
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3546 |
4411c38f3d16
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
3547 /* |
13012
8d5b451d7bab
patch 8.0.1382: get "no write since last change" message if terminal is open
Christian Brabandt <cb@256bit.org>
parents:
12827
diff
changeset
|
3548 * Like bufIsChanged() but ignoring a terminal window. |
8d5b451d7bab
patch 8.0.1382: get "no write since last change" message if terminal is open
Christian Brabandt <cb@256bit.org>
parents:
12827
diff
changeset
|
3549 */ |
8d5b451d7bab
patch 8.0.1382: get "no write since last change" message if terminal is open
Christian Brabandt <cb@256bit.org>
parents:
12827
diff
changeset
|
3550 int |
8d5b451d7bab
patch 8.0.1382: get "no write since last change" message if terminal is open
Christian Brabandt <cb@256bit.org>
parents:
12827
diff
changeset
|
3551 bufIsChangedNotTerm(buf_T *buf) |
8d5b451d7bab
patch 8.0.1382: get "no write since last change" message if terminal is open
Christian Brabandt <cb@256bit.org>
parents:
12827
diff
changeset
|
3552 { |
14147
de75c249723d
patch 8.1.0091: MS-Windows: Cannot interrupt gdb when program is running
Christian Brabandt <cb@256bit.org>
parents:
13610
diff
changeset
|
3553 // In a "prompt" buffer we do respect 'modified', so that we can control |
de75c249723d
patch 8.1.0091: MS-Windows: Cannot interrupt gdb when program is running
Christian Brabandt <cb@256bit.org>
parents:
13610
diff
changeset
|
3554 // closing the window by setting or resetting that option. |
de75c249723d
patch 8.1.0091: MS-Windows: Cannot interrupt gdb when program is running
Christian Brabandt <cb@256bit.org>
parents:
13610
diff
changeset
|
3555 return (!bt_dontwrite(buf) || bt_prompt(buf)) |
11957
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11836
diff
changeset
|
3556 && (buf->b_changed || file_ff_differs(buf, TRUE)); |
7 | 3557 } |
3558 | |
3559 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3560 curbufIsChanged(void) |
7 | 3561 { |
11957
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11836
diff
changeset
|
3562 return bufIsChanged(curbuf); |
7 | 3563 } |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3564 |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3565 #if defined(FEAT_EVAL) || defined(PROTO) |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3566 /* |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3567 * For undotree(): Append the list of undo blocks at "first_uhp" to "list". |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3568 * Recursive. |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3569 */ |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3570 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3571 u_eval_tree(u_header_T *first_uhp, list_T *list) |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3572 { |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3573 u_header_T *uhp = first_uhp; |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3574 dict_T *dict; |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3575 |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3576 while (uhp != NULL) |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3577 { |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3578 dict = dict_alloc(); |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3579 if (dict == NULL) |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3580 return; |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14237
diff
changeset
|
3581 dict_add_number(dict, "seq", uhp->uh_seq); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14237
diff
changeset
|
3582 dict_add_number(dict, "time", (long)uhp->uh_time); |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3583 if (uhp == curbuf->b_u_newhead) |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14237
diff
changeset
|
3584 dict_add_number(dict, "newhead", 1); |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3585 if (uhp == curbuf->b_u_curhead) |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14237
diff
changeset
|
3586 dict_add_number(dict, "curhead", 1); |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3587 if (uhp->uh_save_nr > 0) |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14237
diff
changeset
|
3588 dict_add_number(dict, "save", uhp->uh_save_nr); |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3589 |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3590 if (uhp->uh_alt_next.ptr != NULL) |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3591 { |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3592 list_T *alt_list = list_alloc(); |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3593 |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3594 if (alt_list != NULL) |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3595 { |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3596 /* Recursive call to add alternate undo tree. */ |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3597 u_eval_tree(uhp->uh_alt_next.ptr, alt_list); |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3598 dict_add_list(dict, "alt", alt_list); |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3599 } |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3600 } |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3601 |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3602 list_append_dict(list, dict); |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3603 uhp = uhp->uh_prev.ptr; |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3604 } |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3605 } |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2271
diff
changeset
|
3606 #endif |