Mercurial > vim
comparison src/undo.c @ 632:b6632d553df3 v7.0182
updated for version 7.0182
author | vimboss |
---|---|
date | Thu, 19 Jan 2006 22:16:24 +0000 |
parents | 66080ac5dab7 |
children | 1c586ee8dd45 |
comparison
equal
deleted
inserted
replaced
631:68a196b7504d | 632:b6632d553df3 |
---|---|
50 /* See below: use malloc()/free() for memory management. */ | 50 /* See below: use malloc()/free() for memory management. */ |
51 #define U_USE_MALLOC 1 | 51 #define U_USE_MALLOC 1 |
52 | 52 |
53 static u_entry_T *u_get_headentry __ARGS((void)); | 53 static u_entry_T *u_get_headentry __ARGS((void)); |
54 static void u_getbot __ARGS((void)); | 54 static void u_getbot __ARGS((void)); |
55 static int undo_allowed __ARGS((void)); | |
55 static int u_savecommon __ARGS((linenr_T, linenr_T, linenr_T)); | 56 static int u_savecommon __ARGS((linenr_T, linenr_T, linenr_T)); |
56 static void u_doit __ARGS((int count)); | 57 static void u_doit __ARGS((int count)); |
57 static void u_undoredo __ARGS((void)); | 58 static void u_undoredo __ARGS((void)); |
58 static void u_undo_end __ARGS((void)); | 59 static void u_undo_end __ARGS((void)); |
59 static void u_freelist __ARGS((buf_T *buf, struct u_header *)); | 60 static void u_freelist __ARGS((buf_T *buf, struct u_header *)); |
154 | 155 |
155 return (u_savecommon(lnum - 1, lnum + nlines, | 156 return (u_savecommon(lnum - 1, lnum + nlines, |
156 nlines == curbuf->b_ml.ml_line_count ? 2 : lnum)); | 157 nlines == curbuf->b_ml.ml_line_count ? 2 : lnum)); |
157 } | 158 } |
158 | 159 |
160 /* | |
161 * Return TRUE when undo is allowed. Otherwise give an error message and | |
162 * return FALSE. | |
163 */ | |
164 static int | |
165 undo_allowed() | |
166 { | |
167 /* Don't allow changes when 'modifiable' is off. */ | |
168 if (!curbuf->b_p_ma) | |
169 { | |
170 EMSG(_(e_modifiable)); | |
171 return FALSE; | |
172 } | |
173 | |
174 #ifdef HAVE_SANDBOX | |
175 /* In the sandbox it's not allowed to change the text. */ | |
176 if (sandbox != 0) | |
177 { | |
178 EMSG(_(e_sandbox)); | |
179 return FALSE; | |
180 } | |
181 #endif | |
182 | |
183 /* Don't allow changes in the buffer while editing the cmdline. The | |
184 * caller of getcmdline() may get confused. */ | |
185 if (cmdline_busy) | |
186 { | |
187 EMSG(_(e_secure)); | |
188 return FALSE; | |
189 } | |
190 | |
191 return TRUE; | |
192 } | |
193 | |
159 static int | 194 static int |
160 u_savecommon(top, bot, newbot) | 195 u_savecommon(top, bot, newbot) |
161 linenr_T top, bot; | 196 linenr_T top, bot; |
162 linenr_T newbot; | 197 linenr_T newbot; |
163 { | 198 { |
166 struct u_header *uhp; | 201 struct u_header *uhp; |
167 u_entry_T *uep; | 202 u_entry_T *uep; |
168 u_entry_T *prev_uep; | 203 u_entry_T *prev_uep; |
169 long size; | 204 long size; |
170 | 205 |
171 /* | 206 /* When making changes is not allowed return FAIL. It's a crude way to |
172 * Don't allow changes when 'modifiable' is off. Letting the | 207 * make all change commands fail. */ |
173 * undo fail is a crude way to make all change commands fail. | 208 if (!undo_allowed()) |
174 */ | |
175 if (!curbuf->b_p_ma) | |
176 { | |
177 EMSG(_(e_modifiable)); | |
178 return FAIL; | 209 return FAIL; |
179 } | |
180 | |
181 #ifdef HAVE_SANDBOX | |
182 /* | |
183 * In the sandbox it's not allowed to change the text. Letting the | |
184 * undo fail is a crude way to make all change commands fail. | |
185 */ | |
186 if (sandbox != 0) | |
187 { | |
188 EMSG(_(e_sandbox)); | |
189 return FAIL; | |
190 } | |
191 #endif | |
192 | 210 |
193 #ifdef FEAT_NETBEANS_INTG | 211 #ifdef FEAT_NETBEANS_INTG |
194 /* | 212 /* |
195 * Netbeans defines areas that cannot be modified. Bail out here when | 213 * Netbeans defines areas that cannot be modified. Bail out here when |
196 * trying to change text in a guarded area. | 214 * trying to change text in a guarded area. |
482 */ | 500 */ |
483 static void | 501 static void |
484 u_doit(count) | 502 u_doit(count) |
485 int count; | 503 int count; |
486 { | 504 { |
487 /* Don't allow changes when 'modifiable' is off. */ | 505 if (!undo_allowed()) |
488 if (!curbuf->b_p_ma) | |
489 { | |
490 EMSG(_(e_modifiable)); | |
491 return; | 506 return; |
492 } | |
493 #ifdef HAVE_SANDBOX | |
494 /* In the sandbox it's not allowed to change the text. */ | |
495 if (sandbox != 0) | |
496 { | |
497 EMSG(_(e_sandbox)); | |
498 return; | |
499 } | |
500 #endif | |
501 | 507 |
502 u_newcount = 0; | 508 u_newcount = 0; |
503 u_oldcount = 0; | 509 u_oldcount = 0; |
504 if (curbuf->b_ml.ml_flags & ML_EMPTY) | 510 if (curbuf->b_ml.ml_flags & ML_EMPTY) |
505 u_oldcount = -1; | 511 u_oldcount = -1; |