annotate src/undo.c @ 15390:00aa76a735e7 v8.1.0703

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