223
|
1 /* undo handling for GNU Emacs.
|
34169
|
2 Copyright (C) 1990, 1993, 1994, 2000 Free Software Foundation, Inc.
|
223
|
3
|
|
4 This file is part of GNU Emacs.
|
|
5
|
14186
|
6 GNU Emacs is free software; you can redistribute it and/or modify
|
|
7 it under the terms of the GNU General Public License as published by
|
|
8 the Free Software Foundation; either version 2, or (at your option)
|
|
9 any later version.
|
223
|
10
|
14186
|
11 GNU Emacs is distributed in the hope that it will be useful,
|
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 GNU General Public License for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with GNU Emacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
223
|
20
|
|
21
|
4696
|
22 #include <config.h>
|
223
|
23 #include "lisp.h"
|
|
24 #include "buffer.h"
|
6180
d369907be635
(record_delete): Save last_point_position in the undo record, rather than the
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
25 #include "commands.h"
|
223
|
26
|
|
27 /* Last buffer for which undo information was recorded. */
|
|
28 Lisp_Object last_undo_buffer;
|
|
29
|
3696
|
30 Lisp_Object Qinhibit_read_only;
|
|
31
|
6254
|
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
|
44391
|
39 /* Record point as it was at beginning of this command (if necessary)
|
|
40 And prepare the undo info for recording a change.
|
|
41 PT is the position of point that will naturally occur as a result of the
|
|
42 undo record that will be added just after this command terminates. */
|
|
43
|
|
44 static void
|
|
45 record_point (pt)
|
|
46 {
|
|
47 int at_boundary;
|
|
48
|
|
49 /* Allocate a cons cell to be the undo boundary after this command. */
|
|
50 if (NILP (pending_boundary))
|
|
51 pending_boundary = Fcons (Qnil, Qnil);
|
|
52
|
|
53 if (!BUFFERP (last_undo_buffer)
|
|
54 || current_buffer != XBUFFER (last_undo_buffer))
|
|
55 Fundo_boundary ();
|
|
56 XSETBUFFER (last_undo_buffer, current_buffer);
|
|
57
|
|
58 if (CONSP (current_buffer->undo_list))
|
|
59 {
|
|
60 /* Set AT_BOUNDARY to 1 only when we have nothing other than
|
|
61 marker adjustment before undo boundary. */
|
|
62
|
|
63 Lisp_Object tail = current_buffer->undo_list, elt;
|
|
64
|
|
65 while (1)
|
|
66 {
|
|
67 if (NILP (tail))
|
|
68 elt = Qnil;
|
|
69 else
|
|
70 elt = XCAR (tail);
|
|
71 if (NILP (elt) || ! (CONSP (elt) && MARKERP (XCAR (elt))))
|
|
72 break;
|
|
73 tail = XCDR (tail);
|
|
74 }
|
|
75 at_boundary = NILP (elt);
|
|
76 }
|
|
77 else
|
|
78 at_boundary = 1;
|
|
79
|
|
80 if (MODIFF <= SAVE_MODIFF)
|
|
81 record_first_change ();
|
|
82
|
|
83 /* If we are just after an undo boundary, and
|
|
84 point wasn't at start of deleted range, record where it was. */
|
|
85 if (at_boundary
|
|
86 && last_point_position != pt
|
|
87 /* If we're called from batch mode, this could be nil. */
|
|
88 && BUFFERP (last_point_position_buffer)
|
|
89 && current_buffer == XBUFFER (last_point_position_buffer))
|
|
90 current_buffer->undo_list
|
|
91 = Fcons (make_number (last_point_position), current_buffer->undo_list);
|
|
92 }
|
|
93
|
223
|
94 /* Record an insertion that just happened or is about to happen,
|
|
95 for LENGTH characters at position BEG.
|
|
96 (It is possible to record an insertion before or after the fact
|
|
97 because we don't need to record the contents.) */
|
|
98
|
20372
|
99 void
|
223
|
100 record_insert (beg, length)
|
12088
|
101 int beg, length;
|
223
|
102 {
|
|
103 Lisp_Object lbeg, lend;
|
|
104
|
2194
|
105 if (EQ (current_buffer->undo_list, Qt))
|
|
106 return;
|
|
107
|
44391
|
108 record_point (beg);
|
223
|
109
|
|
110 /* If this is following another insertion and consecutive with it
|
|
111 in the buffer, combine the two. */
|
9108
c0287cefc0f8
(record_insert, truncate_undo_list, Fprimitive_undo): Use type test macros.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
112 if (CONSP (current_buffer->undo_list))
|
223
|
113 {
|
|
114 Lisp_Object elt;
|
25663
|
115 elt = XCAR (current_buffer->undo_list);
|
9108
c0287cefc0f8
(record_insert, truncate_undo_list, Fprimitive_undo): Use type test macros.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
116 if (CONSP (elt)
|
25663
|
117 && INTEGERP (XCAR (elt))
|
|
118 && INTEGERP (XCDR (elt))
|
|
119 && XINT (XCDR (elt)) == beg)
|
223
|
120 {
|
39973
579177964efa
Avoid (most) uses of XCAR/XCDR as lvalues, for flexibility in experimenting
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
121 XSETCDR (elt, make_number (beg + length));
|
223
|
122 return;
|
|
123 }
|
|
124 }
|
|
125
|
12088
|
126 XSETFASTINT (lbeg, beg);
|
|
127 XSETINT (lend, beg + length);
|
1524
|
128 current_buffer->undo_list = Fcons (Fcons (lbeg, lend),
|
|
129 current_buffer->undo_list);
|
223
|
130 }
|
|
131
|
|
132 /* Record that a deletion is about to take place,
|
21237
|
133 of the characters in STRING, at location BEG. */
|
223
|
134
|
20373
|
135 void
|
21237
|
136 record_delete (beg, string)
|
|
137 int beg;
|
|
138 Lisp_Object string;
|
223
|
139 {
|
21237
|
140 Lisp_Object sbeg;
|
223
|
141
|
2194
|
142 if (EQ (current_buffer->undo_list, Qt))
|
|
143 return;
|
|
144
|
44391
|
145 if (PT == beg + XSTRING (string)->size)
|
21272
|
146 {
|
44391
|
147 XSETINT (sbeg, -beg);
|
|
148 record_point (PT);
|
21272
|
149 }
|
|
150 else
|
44391
|
151 {
|
|
152 XSETFASTINT (sbeg, beg);
|
|
153 record_point (beg);
|
|
154 }
|
1248
|
155
|
223
|
156 current_buffer->undo_list
|
21237
|
157 = Fcons (Fcons (string, sbeg), current_buffer->undo_list);
|
223
|
158 }
|
|
159
|
14480
|
160 /* Record the fact that MARKER is about to be adjusted by ADJUSTMENT.
|
|
161 This is done only when a marker points within text being deleted,
|
|
162 because that's the only case where an automatic marker adjustment
|
|
163 won't be inverted automatically by undoing the buffer modification. */
|
|
164
|
20373
|
165 void
|
14480
|
166 record_marker_adjustment (marker, adjustment)
|
|
167 Lisp_Object marker;
|
|
168 int adjustment;
|
|
169 {
|
|
170 if (EQ (current_buffer->undo_list, Qt))
|
|
171 return;
|
|
172
|
|
173 /* Allocate a cons cell to be the undo boundary after this command. */
|
|
174 if (NILP (pending_boundary))
|
|
175 pending_boundary = Fcons (Qnil, Qnil);
|
|
176
|
30961
|
177 if (!BUFFERP (last_undo_buffer)
|
|
178 || current_buffer != XBUFFER (last_undo_buffer))
|
14480
|
179 Fundo_boundary ();
|
|
180 XSETBUFFER (last_undo_buffer, current_buffer);
|
|
181
|
|
182 current_buffer->undo_list
|
|
183 = Fcons (Fcons (marker, make_number (adjustment)),
|
|
184 current_buffer->undo_list);
|
|
185 }
|
|
186
|
223
|
187 /* Record that a replacement is about to take place,
|
|
188 for LENGTH characters at location BEG.
|
21237
|
189 The replacement must not change the number of characters. */
|
223
|
190
|
20373
|
191 void
|
223
|
192 record_change (beg, length)
|
|
193 int beg, length;
|
|
194 {
|
21237
|
195 record_delete (beg, make_buffer_string (beg, beg + length, 1));
|
223
|
196 record_insert (beg, length);
|
|
197 }
|
|
198
|
|
199 /* Record that an unmodified buffer is about to be changed.
|
|
200 Record the file modification date so that when undoing this entry
|
|
201 we can tell whether it is obsolete because the file was saved again. */
|
|
202
|
20372
|
203 void
|
223
|
204 record_first_change ()
|
|
205 {
|
|
206 Lisp_Object high, low;
|
10300
|
207 struct buffer *base_buffer = current_buffer;
|
5762
|
208
|
|
209 if (EQ (current_buffer->undo_list, Qt))
|
|
210 return;
|
|
211
|
30961
|
212 if (!BUFFERP (last_undo_buffer)
|
|
213 || current_buffer != XBUFFER (last_undo_buffer))
|
5762
|
214 Fundo_boundary ();
|
9281
05b2bd5d5559
(record_insert, record_delete, record_first_change, record_property_change):
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
215 XSETBUFFER (last_undo_buffer, current_buffer);
|
5762
|
216
|
10300
|
217 if (base_buffer->base_buffer)
|
|
218 base_buffer = base_buffer->base_buffer;
|
|
219
|
|
220 XSETFASTINT (high, (base_buffer->modtime >> 16) & 0xffff);
|
|
221 XSETFASTINT (low, base_buffer->modtime & 0xffff);
|
223
|
222 current_buffer->undo_list = Fcons (Fcons (Qt, Fcons (high, low)), current_buffer->undo_list);
|
|
223 }
|
|
224
|
1968
|
225 /* Record a change in property PROP (whose old value was VAL)
|
|
226 for LENGTH characters starting at position BEG in BUFFER. */
|
|
227
|
20372
|
228 void
|
1968
|
229 record_property_change (beg, length, prop, value, buffer)
|
|
230 int beg, length;
|
|
231 Lisp_Object prop, value, buffer;
|
|
232 {
|
|
233 Lisp_Object lbeg, lend, entry;
|
|
234 struct buffer *obuf = current_buffer;
|
|
235 int boundary = 0;
|
|
236
|
5762
|
237 if (EQ (XBUFFER (buffer)->undo_list, Qt))
|
2194
|
238 return;
|
|
239
|
6254
|
240 /* Allocate a cons cell to be the undo boundary after this command. */
|
|
241 if (NILP (pending_boundary))
|
|
242 pending_boundary = Fcons (Qnil, Qnil);
|
|
243
|
1968
|
244 if (!EQ (buffer, last_undo_buffer))
|
|
245 boundary = 1;
|
|
246 last_undo_buffer = buffer;
|
|
247
|
|
248 /* Switch temporarily to the buffer that was changed. */
|
|
249 current_buffer = XBUFFER (buffer);
|
|
250
|
|
251 if (boundary)
|
|
252 Fundo_boundary ();
|
|
253
|
10300
|
254 if (MODIFF <= SAVE_MODIFF)
|
1968
|
255 record_first_change ();
|
|
256
|
9281
05b2bd5d5559
(record_insert, record_delete, record_first_change, record_property_change):
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
257 XSETINT (lbeg, beg);
|
05b2bd5d5559
(record_insert, record_delete, record_first_change, record_property_change):
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
258 XSETINT (lend, beg + length);
|
1968
|
259 entry = Fcons (Qnil, Fcons (prop, Fcons (value, Fcons (lbeg, lend))));
|
|
260 current_buffer->undo_list = Fcons (entry, current_buffer->undo_list);
|
|
261
|
|
262 current_buffer = obuf;
|
|
263 }
|
|
264
|
223
|
265 DEFUN ("undo-boundary", Fundo_boundary, Sundo_boundary, 0, 0, 0,
|
40123
|
266 doc: /* Mark a boundary between units of undo.
|
|
267 An undo command will stop at this point,
|
|
268 but another undo command will undo to the previous boundary. */)
|
|
269 ()
|
223
|
270 {
|
|
271 Lisp_Object tem;
|
|
272 if (EQ (current_buffer->undo_list, Qt))
|
|
273 return Qnil;
|
|
274 tem = Fcar (current_buffer->undo_list);
|
485
|
275 if (!NILP (tem))
|
6254
|
276 {
|
|
277 /* One way or another, cons nil onto the front of the undo list. */
|
|
278 if (!NILP (pending_boundary))
|
|
279 {
|
|
280 /* If we have preallocated the cons cell to use here,
|
|
281 use that one. */
|
39973
579177964efa
Avoid (most) uses of XCAR/XCDR as lvalues, for flexibility in experimenting
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
282 XSETCDR (pending_boundary, current_buffer->undo_list);
|
6254
|
283 current_buffer->undo_list = pending_boundary;
|
|
284 pending_boundary = Qnil;
|
|
285 }
|
|
286 else
|
|
287 current_buffer->undo_list = Fcons (Qnil, current_buffer->undo_list);
|
|
288 }
|
223
|
289 return Qnil;
|
|
290 }
|
|
291
|
|
292 /* At garbage collection time, make an undo list shorter at the end,
|
|
293 returning the truncated list.
|
|
294 MINSIZE and MAXSIZE are the limits on size allowed, as described below.
|
761
|
295 In practice, these are the values of undo-limit and
|
|
296 undo-strong-limit. */
|
223
|
297
|
|
298 Lisp_Object
|
|
299 truncate_undo_list (list, minsize, maxsize)
|
|
300 Lisp_Object list;
|
|
301 int minsize, maxsize;
|
|
302 {
|
|
303 Lisp_Object prev, next, last_boundary;
|
|
304 int size_so_far = 0;
|
|
305
|
|
306 prev = Qnil;
|
|
307 next = list;
|
|
308 last_boundary = Qnil;
|
|
309
|
|
310 /* Always preserve at least the most recent undo record.
|
241
|
311 If the first element is an undo boundary, skip past it.
|
|
312
|
|
313 Skip, skip, skip the undo, skip, skip, skip the undo,
|
970
|
314 Skip, skip, skip the undo, skip to the undo bound'ry.
|
|
315 (Get it? "Skip to my Loo?") */
|
25663
|
316 if (CONSP (next) && NILP (XCAR (next)))
|
223
|
317 {
|
|
318 /* Add in the space occupied by this element and its chain link. */
|
|
319 size_so_far += sizeof (struct Lisp_Cons);
|
|
320
|
|
321 /* Advance to next element. */
|
|
322 prev = next;
|
25663
|
323 next = XCDR (next);
|
223
|
324 }
|
25663
|
325 while (CONSP (next) && ! NILP (XCAR (next)))
|
223
|
326 {
|
|
327 Lisp_Object elt;
|
25663
|
328 elt = XCAR (next);
|
223
|
329
|
|
330 /* Add in the space occupied by this element and its chain link. */
|
|
331 size_so_far += sizeof (struct Lisp_Cons);
|
9108
c0287cefc0f8
(record_insert, truncate_undo_list, Fprimitive_undo): Use type test macros.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
332 if (CONSP (elt))
|
223
|
333 {
|
|
334 size_so_far += sizeof (struct Lisp_Cons);
|
25663
|
335 if (STRINGP (XCAR (elt)))
|
223
|
336 size_so_far += (sizeof (struct Lisp_String) - 1
|
25663
|
337 + XSTRING (XCAR (elt))->size);
|
223
|
338 }
|
|
339
|
|
340 /* Advance to next element. */
|
|
341 prev = next;
|
25663
|
342 next = XCDR (next);
|
223
|
343 }
|
9108
c0287cefc0f8
(record_insert, truncate_undo_list, Fprimitive_undo): Use type test macros.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
344 if (CONSP (next))
|
223
|
345 last_boundary = prev;
|
|
346
|
9108
c0287cefc0f8
(record_insert, truncate_undo_list, Fprimitive_undo): Use type test macros.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
347 while (CONSP (next))
|
223
|
348 {
|
|
349 Lisp_Object elt;
|
25663
|
350 elt = XCAR (next);
|
223
|
351
|
|
352 /* When we get to a boundary, decide whether to truncate
|
|
353 either before or after it. The lower threshold, MINSIZE,
|
|
354 tells us to truncate after it. If its size pushes past
|
|
355 the higher threshold MAXSIZE as well, we truncate before it. */
|
485
|
356 if (NILP (elt))
|
223
|
357 {
|
|
358 if (size_so_far > maxsize)
|
|
359 break;
|
|
360 last_boundary = prev;
|
|
361 if (size_so_far > minsize)
|
|
362 break;
|
|
363 }
|
|
364
|
|
365 /* Add in the space occupied by this element and its chain link. */
|
|
366 size_so_far += sizeof (struct Lisp_Cons);
|
9108
c0287cefc0f8
(record_insert, truncate_undo_list, Fprimitive_undo): Use type test macros.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
367 if (CONSP (elt))
|
223
|
368 {
|
|
369 size_so_far += sizeof (struct Lisp_Cons);
|
25663
|
370 if (STRINGP (XCAR (elt)))
|
223
|
371 size_so_far += (sizeof (struct Lisp_String) - 1
|
25663
|
372 + XSTRING (XCAR (elt))->size);
|
223
|
373 }
|
|
374
|
|
375 /* Advance to next element. */
|
|
376 prev = next;
|
25663
|
377 next = XCDR (next);
|
223
|
378 }
|
|
379
|
|
380 /* If we scanned the whole list, it is short enough; don't change it. */
|
485
|
381 if (NILP (next))
|
223
|
382 return list;
|
|
383
|
|
384 /* Truncate at the boundary where we decided to truncate. */
|
485
|
385 if (!NILP (last_boundary))
|
223
|
386 {
|
39973
579177964efa
Avoid (most) uses of XCAR/XCDR as lvalues, for flexibility in experimenting
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
387 XSETCDR (last_boundary, Qnil);
|
223
|
388 return list;
|
|
389 }
|
|
390 else
|
|
391 return Qnil;
|
|
392 }
|
|
393
|
|
394 DEFUN ("primitive-undo", Fprimitive_undo, Sprimitive_undo, 2, 2, 0,
|
40123
|
395 doc: /* Undo N records from the front of the list LIST.
|
|
396 Return what remains of the list. */)
|
|
397 (n, list)
|
3719
|
398 Lisp_Object n, list;
|
223
|
399 {
|
7671
|
400 struct gcpro gcpro1, gcpro2;
|
|
401 Lisp_Object next;
|
34794
|
402 int count = BINDING_STACK_SIZE ();
|
7671
|
403 register int arg;
|
34794
|
404
|
223
|
405 #if 0 /* This is a good feature, but would make undo-start
|
|
406 unable to do what is expected. */
|
|
407 Lisp_Object tem;
|
|
408
|
|
409 /* If the head of the list is a boundary, it is the boundary
|
|
410 preceding this command. Get rid of it and don't count it. */
|
|
411 tem = Fcar (list);
|
485
|
412 if (NILP (tem))
|
223
|
413 list = Fcdr (list);
|
|
414 #endif
|
|
415
|
40656
|
416 CHECK_NUMBER (n);
|
7671
|
417 arg = XINT (n);
|
|
418 next = Qnil;
|
|
419 GCPRO2 (next, list);
|
|
420
|
37527
|
421 /* In a writable buffer, enable undoing read-only text that is so
|
|
422 because of text properties. */
|
|
423 if (NILP (current_buffer->read_only))
|
3696
|
424 specbind (Qinhibit_read_only, Qt);
|
|
425
|
34794
|
426 /* Don't let `intangible' properties interfere with undo. */
|
|
427 specbind (Qinhibit_point_motion_hooks, Qt);
|
|
428
|
223
|
429 while (arg > 0)
|
|
430 {
|
39798
|
431 while (CONSP (list))
|
223
|
432 {
|
39798
|
433 next = XCAR (list);
|
|
434 list = XCDR (list);
|
1248
|
435 /* Exit inner loop at undo boundary. */
|
485
|
436 if (NILP (next))
|
223
|
437 break;
|
1248
|
438 /* Handle an integer by setting point to that value. */
|
9108
c0287cefc0f8
(record_insert, truncate_undo_list, Fprimitive_undo): Use type test macros.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
439 if (INTEGERP (next))
|
1248
|
440 SET_PT (clip_to_bounds (BEGV, XINT (next), ZV));
|
9108
c0287cefc0f8
(record_insert, truncate_undo_list, Fprimitive_undo): Use type test macros.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
441 else if (CONSP (next))
|
223
|
442 {
|
1248
|
443 Lisp_Object car, cdr;
|
|
444
|
39798
|
445 car = XCAR (next);
|
|
446 cdr = XCDR (next);
|
1248
|
447 if (EQ (car, Qt))
|
223
|
448 {
|
1248
|
449 /* Element (t high . low) records previous modtime. */
|
|
450 Lisp_Object high, low;
|
|
451 int mod_time;
|
10300
|
452 struct buffer *base_buffer = current_buffer;
|
1248
|
453
|
|
454 high = Fcar (cdr);
|
|
455 low = Fcdr (cdr);
|
3687
|
456 mod_time = (XFASTINT (high) << 16) + XFASTINT (low);
|
10300
|
457
|
|
458 if (current_buffer->base_buffer)
|
|
459 base_buffer = current_buffer->base_buffer;
|
|
460
|
1248
|
461 /* If this records an obsolete save
|
|
462 (not matching the actual disk file)
|
|
463 then don't mark unmodified. */
|
10300
|
464 if (mod_time != base_buffer->modtime)
|
12649
|
465 continue;
|
1598
|
466 #ifdef CLASH_DETECTION
|
1248
|
467 Funlock_buffer ();
|
1598
|
468 #endif /* CLASH_DETECTION */
|
1248
|
469 Fset_buffer_modified_p (Qnil);
|
|
470 }
|
3687
|
471 else if (EQ (car, Qnil))
|
1968
|
472 {
|
3687
|
473 /* Element (nil prop val beg . end) is property change. */
|
1968
|
474 Lisp_Object beg, end, prop, val;
|
|
475
|
|
476 prop = Fcar (cdr);
|
|
477 cdr = Fcdr (cdr);
|
|
478 val = Fcar (cdr);
|
|
479 cdr = Fcdr (cdr);
|
|
480 beg = Fcar (cdr);
|
|
481 end = Fcdr (cdr);
|
|
482
|
|
483 Fput_text_property (beg, end, prop, val, Qnil);
|
|
484 }
|
9108
c0287cefc0f8
(record_insert, truncate_undo_list, Fprimitive_undo): Use type test macros.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
485 else if (INTEGERP (car) && INTEGERP (cdr))
|
1248
|
486 {
|
|
487 /* Element (BEG . END) means range was inserted. */
|
|
488
|
|
489 if (XINT (car) < BEGV
|
|
490 || XINT (cdr) > ZV)
|
223
|
491 error ("Changes to be undone are outside visible portion of buffer");
|
1320
c45c4e0cae7d
(Fprimitive_undo): When undoing an insert, move point and then delete.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
492 /* Set point first thing, so that undoing this undo
|
c45c4e0cae7d
(Fprimitive_undo): When undoing an insert, move point and then delete.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
493 does not send point back to where it is now. */
|
c45c4e0cae7d
(Fprimitive_undo): When undoing an insert, move point and then delete.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
494 Fgoto_char (car);
|
1248
|
495 Fdelete_region (car, cdr);
|
223
|
496 }
|
9108
c0287cefc0f8
(record_insert, truncate_undo_list, Fprimitive_undo): Use type test macros.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
497 else if (STRINGP (car) && INTEGERP (cdr))
|
223
|
498 {
|
1248
|
499 /* Element (STRING . POS) means STRING was deleted. */
|
|
500 Lisp_Object membuf;
|
|
501 int pos = XINT (cdr);
|
544
|
502
|
1248
|
503 membuf = car;
|
|
504 if (pos < 0)
|
|
505 {
|
|
506 if (-pos < BEGV || -pos > ZV)
|
|
507 error ("Changes to be undone are outside visible portion of buffer");
|
|
508 SET_PT (-pos);
|
|
509 Finsert (1, &membuf);
|
|
510 }
|
|
511 else
|
|
512 {
|
|
513 if (pos < BEGV || pos > ZV)
|
|
514 error ("Changes to be undone are outside visible portion of buffer");
|
|
515 SET_PT (pos);
|
|
516
|
17447
|
517 /* Now that we record marker adjustments
|
|
518 (caused by deletion) for undo,
|
|
519 we should always insert after markers,
|
|
520 so that undoing the marker adjustments
|
|
521 put the markers back in the right place. */
|
|
522 Finsert (1, &membuf);
|
1248
|
523 SET_PT (pos);
|
|
524 }
|
223
|
525 }
|
14480
|
526 else if (MARKERP (car) && INTEGERP (cdr))
|
|
527 {
|
|
528 /* (MARKER . INTEGER) means a marker MARKER
|
|
529 was adjusted by INTEGER. */
|
|
530 if (XMARKER (car)->buffer)
|
|
531 Fset_marker (car,
|
|
532 make_number (marker_position (car) - XINT (cdr)),
|
|
533 Fmarker_buffer (car));
|
|
534 }
|
223
|
535 }
|
|
536 }
|
|
537 arg--;
|
|
538 }
|
|
539
|
7671
|
540 UNGCPRO;
|
3696
|
541 return unbind_to (count, list);
|
223
|
542 }
|
|
543
|
21514
|
544 void
|
223
|
545 syms_of_undo ()
|
|
546 {
|
3696
|
547 Qinhibit_read_only = intern ("inhibit-read-only");
|
|
548 staticpro (&Qinhibit_read_only);
|
|
549
|
6254
|
550 pending_boundary = Qnil;
|
|
551 staticpro (&pending_boundary);
|
|
552
|
223
|
553 defsubr (&Sprimitive_undo);
|
|
554 defsubr (&Sundo_boundary);
|
|
555 }
|