diff options
| author | Stefan Monnier | 2008-04-04 16:59:52 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2008-04-04 16:59:52 +0000 |
| commit | 4591d6cbefecb9b967c87be2997e55a9c073a207 (patch) | |
| tree | 62152b1d19c7c8b7ade99e99230809c83bdbf784 /src/undo.c | |
| parent | 7c3733579278b666bb56b3dc48c6d50d4cdd86c3 (diff) | |
| download | emacs-4591d6cbefecb9b967c87be2997e55a9c073a207.tar.gz emacs-4591d6cbefecb9b967c87be2997e55a9c073a207.zip | |
(last_boundary_buffer, last_boundary_position): New vars.
(Fundo_boundary): Set them.
(syms_of_undo): Initialize them.
(record_point): Use them instead of last_point_position*.
(last_undo_buffer): Change type.
Diffstat (limited to 'src/undo.c')
| -rw-r--r-- | src/undo.c | 63 |
1 files changed, 29 insertions, 34 deletions
diff --git a/src/undo.c b/src/undo.c index 77590e4ace8..22ebc143355 100644 --- a/src/undo.c +++ b/src/undo.c | |||
| @@ -38,7 +38,12 @@ Lisp_Object Vundo_outer_limit; | |||
| 38 | Lisp_Object Vundo_outer_limit_function; | 38 | Lisp_Object Vundo_outer_limit_function; |
| 39 | 39 | ||
| 40 | /* Last buffer for which undo information was recorded. */ | 40 | /* Last buffer for which undo information was recorded. */ |
| 41 | Lisp_Object last_undo_buffer; | 41 | /* BEWARE: This is not traced by the GC, so never dereference it! */ |
| 42 | struct buffer *last_undo_buffer; | ||
| 43 | |||
| 44 | /* Position of point last time we inserted a boundary. */ | ||
| 45 | struct buffer *last_boundary_buffer; | ||
| 46 | EMACS_INT last_boundary_position; | ||
| 42 | 47 | ||
| 43 | Lisp_Object Qinhibit_read_only; | 48 | Lisp_Object Qinhibit_read_only; |
| 44 | 49 | ||
| @@ -68,11 +73,7 @@ record_point (pt) | |||
| 68 | { | 73 | { |
| 69 | int at_boundary; | 74 | int at_boundary; |
| 70 | 75 | ||
| 71 | /* Don't record position of pt when undo_inhibit_record_point holds. | 76 | /* Don't record position of pt when undo_inhibit_record_point holds. */ |
| 72 | Needed to avoid inserting a position record in buffer-undo-list | ||
| 73 | when last_point_position has not been set up correctly by | ||
| 74 | command_loop_1, for example, when running a repeat-repeat-char | ||
| 75 | event. */ | ||
| 76 | if (undo_inhibit_record_point) | 77 | if (undo_inhibit_record_point) |
| 77 | return; | 78 | return; |
| 78 | 79 | ||
| @@ -80,10 +81,9 @@ record_point (pt) | |||
| 80 | if (NILP (pending_boundary)) | 81 | if (NILP (pending_boundary)) |
| 81 | pending_boundary = Fcons (Qnil, Qnil); | 82 | pending_boundary = Fcons (Qnil, Qnil); |
| 82 | 83 | ||
| 83 | if (!BUFFERP (last_undo_buffer) | 84 | if (current_buffer != last_undo_buffer) |
| 84 | || current_buffer != XBUFFER (last_undo_buffer)) | ||
| 85 | Fundo_boundary (); | 85 | Fundo_boundary (); |
| 86 | XSETBUFFER (last_undo_buffer, current_buffer); | 86 | last_undo_buffer = current_buffer; |
| 87 | 87 | ||
| 88 | if (CONSP (current_buffer->undo_list)) | 88 | if (CONSP (current_buffer->undo_list)) |
| 89 | { | 89 | { |
| @@ -113,19 +113,10 @@ record_point (pt) | |||
| 113 | /* If we are just after an undo boundary, and | 113 | /* If we are just after an undo boundary, and |
| 114 | point wasn't at start of deleted range, record where it was. */ | 114 | point wasn't at start of deleted range, record where it was. */ |
| 115 | if (at_boundary | 115 | if (at_boundary |
| 116 | && BUFFERP (last_point_position_buffer) | 116 | && current_buffer == last_boundary_buffer |
| 117 | /* If we're called from batch mode, this could be nil. */ | 117 | && last_boundary_position != pt) |
| 118 | && current_buffer == XBUFFER (last_point_position_buffer)) | 118 | current_buffer->undo_list |
| 119 | { | 119 | = Fcons (make_number (last_boundary_position), current_buffer->undo_list); |
| 120 | /* If we have switched windows, use the point value | ||
| 121 | from the window we are in. */ | ||
| 122 | if (! EQ (last_point_position_window, selected_window)) | ||
| 123 | last_point_position = marker_position (XWINDOW (selected_window)->pointm); | ||
| 124 | |||
| 125 | if (last_point_position != pt) | ||
| 126 | current_buffer->undo_list | ||
| 127 | = Fcons (make_number (last_point_position), current_buffer->undo_list); | ||
| 128 | } | ||
| 129 | } | 120 | } |
| 130 | 121 | ||
| 131 | /* Record an insertion that just happened or is about to happen, | 122 | /* Record an insertion that just happened or is about to happen, |
| @@ -211,10 +202,9 @@ record_marker_adjustment (marker, adjustment) | |||
| 211 | if (NILP (pending_boundary)) | 202 | if (NILP (pending_boundary)) |
| 212 | pending_boundary = Fcons (Qnil, Qnil); | 203 | pending_boundary = Fcons (Qnil, Qnil); |
| 213 | 204 | ||
| 214 | if (!BUFFERP (last_undo_buffer) | 205 | if (current_buffer != last_undo_buffer) |
| 215 | || current_buffer != XBUFFER (last_undo_buffer)) | ||
| 216 | Fundo_boundary (); | 206 | Fundo_boundary (); |
| 217 | XSETBUFFER (last_undo_buffer, current_buffer); | 207 | last_undo_buffer = current_buffer; |
| 218 | 208 | ||
| 219 | current_buffer->undo_list | 209 | current_buffer->undo_list |
| 220 | = Fcons (Fcons (marker, make_number (adjustment)), | 210 | = Fcons (Fcons (marker, make_number (adjustment)), |
| @@ -246,10 +236,9 @@ record_first_change () | |||
| 246 | if (EQ (current_buffer->undo_list, Qt)) | 236 | if (EQ (current_buffer->undo_list, Qt)) |
| 247 | return; | 237 | return; |
| 248 | 238 | ||
| 249 | if (!BUFFERP (last_undo_buffer) | 239 | if (current_buffer != last_undo_buffer) |
| 250 | || current_buffer != XBUFFER (last_undo_buffer)) | ||
| 251 | Fundo_boundary (); | 240 | Fundo_boundary (); |
| 252 | XSETBUFFER (last_undo_buffer, current_buffer); | 241 | last_undo_buffer = current_buffer; |
| 253 | 242 | ||
| 254 | if (base_buffer->base_buffer) | 243 | if (base_buffer->base_buffer) |
| 255 | base_buffer = base_buffer->base_buffer; | 244 | base_buffer = base_buffer->base_buffer; |
| @@ -268,22 +257,22 @@ record_property_change (beg, length, prop, value, buffer) | |||
| 268 | Lisp_Object prop, value, buffer; | 257 | Lisp_Object prop, value, buffer; |
| 269 | { | 258 | { |
| 270 | Lisp_Object lbeg, lend, entry; | 259 | Lisp_Object lbeg, lend, entry; |
| 271 | struct buffer *obuf = current_buffer; | 260 | struct buffer *obuf = current_buffer, *buf = XBUFFER (buffer); |
| 272 | int boundary = 0; | 261 | int boundary = 0; |
| 273 | 262 | ||
| 274 | if (EQ (XBUFFER (buffer)->undo_list, Qt)) | 263 | if (EQ (buf->undo_list, Qt)) |
| 275 | return; | 264 | return; |
| 276 | 265 | ||
| 277 | /* Allocate a cons cell to be the undo boundary after this command. */ | 266 | /* Allocate a cons cell to be the undo boundary after this command. */ |
| 278 | if (NILP (pending_boundary)) | 267 | if (NILP (pending_boundary)) |
| 279 | pending_boundary = Fcons (Qnil, Qnil); | 268 | pending_boundary = Fcons (Qnil, Qnil); |
| 280 | 269 | ||
| 281 | if (!EQ (buffer, last_undo_buffer)) | 270 | if (buf != last_undo_buffer) |
| 282 | boundary = 1; | 271 | boundary = 1; |
| 283 | last_undo_buffer = buffer; | 272 | last_undo_buffer = buf; |
| 284 | 273 | ||
| 285 | /* Switch temporarily to the buffer that was changed. */ | 274 | /* Switch temporarily to the buffer that was changed. */ |
| 286 | current_buffer = XBUFFER (buffer); | 275 | current_buffer = buf; |
| 287 | 276 | ||
| 288 | if (boundary) | 277 | if (boundary) |
| 289 | Fundo_boundary (); | 278 | Fundo_boundary (); |
| @@ -323,6 +312,8 @@ but another undo command will undo to the previous boundary. */) | |||
| 323 | else | 312 | else |
| 324 | current_buffer->undo_list = Fcons (Qnil, current_buffer->undo_list); | 313 | current_buffer->undo_list = Fcons (Qnil, current_buffer->undo_list); |
| 325 | } | 314 | } |
| 315 | last_boundary_position = PT; | ||
| 316 | last_boundary_buffer = current_buffer; | ||
| 326 | return Qnil; | 317 | return Qnil; |
| 327 | } | 318 | } |
| 328 | 319 | ||
| @@ -398,7 +389,8 @@ truncate_undo_list (b) | |||
| 398 | && size_so_far > XINT (Vundo_outer_limit) | 389 | && size_so_far > XINT (Vundo_outer_limit) |
| 399 | && !NILP (Vundo_outer_limit_function)) | 390 | && !NILP (Vundo_outer_limit_function)) |
| 400 | { | 391 | { |
| 401 | Lisp_Object temp = last_undo_buffer, tem; | 392 | Lisp_Object tem; |
| 393 | struct buffer *temp = last_undo_buffer; | ||
| 402 | 394 | ||
| 403 | /* Normally the function this calls is undo-outer-limit-truncate. */ | 395 | /* Normally the function this calls is undo-outer-limit-truncate. */ |
| 404 | tem = call1 (Vundo_outer_limit_function, make_number (size_so_far)); | 396 | tem = call1 (Vundo_outer_limit_function, make_number (size_so_far)); |
| @@ -679,6 +671,9 @@ syms_of_undo () | |||
| 679 | pending_boundary = Qnil; | 671 | pending_boundary = Qnil; |
| 680 | staticpro (&pending_boundary); | 672 | staticpro (&pending_boundary); |
| 681 | 673 | ||
| 674 | last_undo_buffer = NULL; | ||
| 675 | last_boundary_buffer = NULL; | ||
| 676 | |||
| 682 | defsubr (&Sprimitive_undo); | 677 | defsubr (&Sprimitive_undo); |
| 683 | defsubr (&Sundo_boundary); | 678 | defsubr (&Sundo_boundary); |
| 684 | 679 | ||