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