comparison src/undo.c @ 6254:a147d798ed0d

(syms_of_undo): staticpro pending_boundary. (pending_boundary): New variable. (syms_of_undo): Initialize it. (Fundo_boundary): Use pending_boundary. (record_insert, record_delete, record_property_change): Set pending_boundary.
author Richard M. Stallman <rms@gnu.org>
date Tue, 08 Mar 1994 16:33:28 +0000
parents d369907be635
children cd81dba38a49
comparison
equal deleted inserted replaced
6253:42914264b095 6254:a147d798ed0d
27 /* Last buffer for which undo information was recorded. */ 27 /* Last buffer for which undo information was recorded. */
28 Lisp_Object last_undo_buffer; 28 Lisp_Object last_undo_buffer;
29 29
30 Lisp_Object Qinhibit_read_only; 30 Lisp_Object Qinhibit_read_only;
31 31
32 /* The first time a command records something for undo.
33 it also allocates the undo-boundary object
34 which will be added to the list at the end of the command.
35 This ensures we can't run out of space while trying to make
36 an undo-boundary. */
37 Lisp_Object pending_boundary;
38
32 /* Record an insertion that just happened or is about to happen, 39 /* Record an insertion that just happened or is about to happen,
33 for LENGTH characters at position BEG. 40 for LENGTH characters at position BEG.
34 (It is possible to record an insertion before or after the fact 41 (It is possible to record an insertion before or after the fact
35 because we don't need to record the contents.) */ 42 because we don't need to record the contents.) */
36 43
39 { 46 {
40 Lisp_Object lbeg, lend; 47 Lisp_Object lbeg, lend;
41 48
42 if (EQ (current_buffer->undo_list, Qt)) 49 if (EQ (current_buffer->undo_list, Qt))
43 return; 50 return;
51
52 /* Allocate a cons cell to be the undo boundary after this command. */
53 if (NILP (pending_boundary))
54 pending_boundary = Fcons (Qnil, Qnil);
44 55
45 if (current_buffer != XBUFFER (last_undo_buffer)) 56 if (current_buffer != XBUFFER (last_undo_buffer))
46 Fundo_boundary (); 57 Fundo_boundary ();
47 XSET (last_undo_buffer, Lisp_Buffer, current_buffer); 58 XSET (last_undo_buffer, Lisp_Buffer, current_buffer);
48 59
80 Lisp_Object lbeg, lend, sbeg; 91 Lisp_Object lbeg, lend, sbeg;
81 92
82 if (EQ (current_buffer->undo_list, Qt)) 93 if (EQ (current_buffer->undo_list, Qt))
83 return; 94 return;
84 95
96 /* Allocate a cons cell to be the undo boundary after this command. */
97 if (NILP (pending_boundary))
98 pending_boundary = Fcons (Qnil, Qnil);
99
85 if (current_buffer != XBUFFER (last_undo_buffer)) 100 if (current_buffer != XBUFFER (last_undo_buffer))
86 Fundo_boundary (); 101 Fundo_boundary ();
87 XSET (last_undo_buffer, Lisp_Buffer, current_buffer); 102 XSET (last_undo_buffer, Lisp_Buffer, current_buffer);
88 103
89 if (MODIFF <= current_buffer->save_modified) 104 if (MODIFF <= current_buffer->save_modified)
149 int boundary = 0; 164 int boundary = 0;
150 165
151 if (EQ (XBUFFER (buffer)->undo_list, Qt)) 166 if (EQ (XBUFFER (buffer)->undo_list, Qt))
152 return; 167 return;
153 168
169 /* Allocate a cons cell to be the undo boundary after this command. */
170 if (NILP (pending_boundary))
171 pending_boundary = Fcons (Qnil, Qnil);
172
154 if (!EQ (buffer, last_undo_buffer)) 173 if (!EQ (buffer, last_undo_buffer))
155 boundary = 1; 174 boundary = 1;
156 last_undo_buffer = buffer; 175 last_undo_buffer = buffer;
157 176
158 /* Switch temporarily to the buffer that was changed. */ 177 /* Switch temporarily to the buffer that was changed. */
181 Lisp_Object tem; 200 Lisp_Object tem;
182 if (EQ (current_buffer->undo_list, Qt)) 201 if (EQ (current_buffer->undo_list, Qt))
183 return Qnil; 202 return Qnil;
184 tem = Fcar (current_buffer->undo_list); 203 tem = Fcar (current_buffer->undo_list);
185 if (!NILP (tem)) 204 if (!NILP (tem))
186 current_buffer->undo_list = Fcons (Qnil, current_buffer->undo_list); 205 {
206 /* One way or another, cons nil onto the front of the undo list. */
207 if (!NILP (pending_boundary))
208 {
209 /* If we have preallocated the cons cell to use here,
210 use that one. */
211 XCONS (pending_boundary)->cdr = current_buffer->undo_list;
212 current_buffer->undo_list = pending_boundary;
213 pending_boundary = Qnil;
214 }
215 else
216 current_buffer->undo_list = Fcons (Qnil, current_buffer->undo_list);
217 }
187 return Qnil; 218 return Qnil;
188 } 219 }
189 220
190 /* At garbage collection time, make an undo list shorter at the end, 221 /* At garbage collection time, make an undo list shorter at the end,
191 returning the truncated list. 222 returning the truncated list.
423 syms_of_undo () 454 syms_of_undo ()
424 { 455 {
425 Qinhibit_read_only = intern ("inhibit-read-only"); 456 Qinhibit_read_only = intern ("inhibit-read-only");
426 staticpro (&Qinhibit_read_only); 457 staticpro (&Qinhibit_read_only);
427 458
459 pending_boundary = Qnil;
460 staticpro (&pending_boundary);
461
428 defsubr (&Sprimitive_undo); 462 defsubr (&Sprimitive_undo);
429 defsubr (&Sundo_boundary); 463 defsubr (&Sundo_boundary);
430 } 464 }