aboutsummaryrefslogtreecommitdiffstats
path: root/src/undo.c
diff options
context:
space:
mode:
authorPhillip Lord2015-11-12 22:01:22 +0000
committerPhillip Lord2015-11-12 22:01:22 +0000
commit20aa42e8204f8f0139ba3880cb32ddf88acc9bf4 (patch)
treef77644c920b0f6a5a2f5849a064c6828c17530b1 /src/undo.c
parentd2f73db50bec29724cb1324910350ad24420b174 (diff)
parent44dfa86b7d382b84564d68472da1448d08f48129 (diff)
downloademacs-20aa42e8204f8f0139ba3880cb32ddf88acc9bf4.tar.gz
emacs-20aa42e8204f8f0139ba3880cb32ddf88acc9bf4.zip
; Merge branch 'fix/no-undo-boundary-on-secondary-buffer-change'
Conflicts: src/cmds.c src/keyboard.c
Diffstat (limited to 'src/undo.c')
-rw-r--r--src/undo.c51
1 files changed, 17 insertions, 34 deletions
diff --git a/src/undo.c b/src/undo.c
index e0924b2b989..009ebc0f959 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -23,10 +23,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
23#include "lisp.h" 23#include "lisp.h"
24#include "buffer.h" 24#include "buffer.h"
25 25
26/* Last buffer for which undo information was recorded. */
27/* BEWARE: This is not traced by the GC, so never dereference it! */
28static struct buffer *last_undo_buffer;
29
30/* Position of point last time we inserted a boundary. */ 26/* Position of point last time we inserted a boundary. */
31static struct buffer *last_boundary_buffer; 27static struct buffer *last_boundary_buffer;
32static ptrdiff_t last_boundary_position; 28static ptrdiff_t last_boundary_position;
@@ -38,6 +34,12 @@ static ptrdiff_t last_boundary_position;
38 an undo-boundary. */ 34 an undo-boundary. */
39static Lisp_Object pending_boundary; 35static Lisp_Object pending_boundary;
40 36
37void
38run_undoable_change ()
39{
40 call0 (Qundo_auto__undoable_change);
41}
42
41/* Record point as it was at beginning of this command (if necessary) 43/* Record point as it was at beginning of this command (if necessary)
42 and prepare the undo info for recording a change. 44 and prepare the undo info for recording a change.
43 PT is the position of point that will naturally occur as a result of the 45 PT is the position of point that will naturally occur as a result of the
@@ -56,15 +58,7 @@ record_point (ptrdiff_t pt)
56 if (NILP (pending_boundary)) 58 if (NILP (pending_boundary))
57 pending_boundary = Fcons (Qnil, Qnil); 59 pending_boundary = Fcons (Qnil, Qnil);
58 60
59 if ((current_buffer != last_undo_buffer) 61 run_undoable_change ();
60 /* Don't call Fundo_boundary for the first change. Otherwise we
61 risk overwriting last_boundary_position in Fundo_boundary with
62 PT of the current buffer and as a consequence not insert an
63 undo boundary because last_boundary_position will equal pt in
64 the test at the end of the present function (Bug#731). */
65 && (MODIFF > SAVE_MODIFF))
66 Fundo_boundary ();
67 last_undo_buffer = current_buffer;
68 62
69 at_boundary = ! CONSP (BVAR (current_buffer, undo_list)) 63 at_boundary = ! CONSP (BVAR (current_buffer, undo_list))
70 || NILP (XCAR (BVAR (current_buffer, undo_list))); 64 || NILP (XCAR (BVAR (current_buffer, undo_list)));
@@ -136,9 +130,7 @@ record_marker_adjustments (ptrdiff_t from, ptrdiff_t to)
136 if (NILP (pending_boundary)) 130 if (NILP (pending_boundary))
137 pending_boundary = Fcons (Qnil, Qnil); 131 pending_boundary = Fcons (Qnil, Qnil);
138 132
139 if (current_buffer != last_undo_buffer) 133 run_undoable_change ();
140 Fundo_boundary ();
141 last_undo_buffer = current_buffer;
142 134
143 for (m = BUF_MARKERS (current_buffer); m; m = m->next) 135 for (m = BUF_MARKERS (current_buffer); m; m = m->next)
144 { 136 {
@@ -225,10 +217,6 @@ record_first_change (void)
225 if (EQ (BVAR (current_buffer, undo_list), Qt)) 217 if (EQ (BVAR (current_buffer, undo_list), Qt))
226 return; 218 return;
227 219
228 if (current_buffer != last_undo_buffer)
229 Fundo_boundary ();
230 last_undo_buffer = current_buffer;
231
232 if (base_buffer->base_buffer) 220 if (base_buffer->base_buffer)
233 base_buffer = base_buffer->base_buffer; 221 base_buffer = base_buffer->base_buffer;
234 222
@@ -256,15 +244,10 @@ record_property_change (ptrdiff_t beg, ptrdiff_t length,
256 if (NILP (pending_boundary)) 244 if (NILP (pending_boundary))
257 pending_boundary = Fcons (Qnil, Qnil); 245 pending_boundary = Fcons (Qnil, Qnil);
258 246
259 if (buf != last_undo_buffer)
260 boundary = true;
261 last_undo_buffer = buf;
262
263 /* Switch temporarily to the buffer that was changed. */ 247 /* Switch temporarily to the buffer that was changed. */
264 current_buffer = buf; 248 set_buffer_internal (buf);
265 249
266 if (boundary) 250 run_undoable_change ();
267 Fundo_boundary ();
268 251
269 if (MODIFF <= SAVE_MODIFF) 252 if (MODIFF <= SAVE_MODIFF)
270 record_first_change (); 253 record_first_change ();
@@ -275,7 +258,8 @@ record_property_change (ptrdiff_t beg, ptrdiff_t length,
275 bset_undo_list (current_buffer, 258 bset_undo_list (current_buffer,
276 Fcons (entry, BVAR (current_buffer, undo_list))); 259 Fcons (entry, BVAR (current_buffer, undo_list)));
277 260
278 current_buffer = obuf; 261 /* Reset the buffer */
262 set_buffer_internal (obuf);
279} 263}
280 264
281DEFUN ("undo-boundary", Fundo_boundary, Sundo_boundary, 0, 0, 0, 265DEFUN ("undo-boundary", Fundo_boundary, Sundo_boundary, 0, 0, 0,
@@ -305,6 +289,8 @@ but another undo command will undo to the previous boundary. */)
305 } 289 }
306 last_boundary_position = PT; 290 last_boundary_position = PT;
307 last_boundary_buffer = current_buffer; 291 last_boundary_buffer = current_buffer;
292
293 Fset (Qundo_auto__last_boundary_cause, Qexplicit);
308 return Qnil; 294 return Qnil;
309} 295}
310 296
@@ -380,7 +366,6 @@ truncate_undo_list (struct buffer *b)
380 && !NILP (Vundo_outer_limit_function)) 366 && !NILP (Vundo_outer_limit_function))
381 { 367 {
382 Lisp_Object tem; 368 Lisp_Object tem;
383 struct buffer *temp = last_undo_buffer;
384 369
385 /* Normally the function this calls is undo-outer-limit-truncate. */ 370 /* Normally the function this calls is undo-outer-limit-truncate. */
386 tem = call1 (Vundo_outer_limit_function, make_number (size_so_far)); 371 tem = call1 (Vundo_outer_limit_function, make_number (size_so_far));
@@ -391,10 +376,6 @@ truncate_undo_list (struct buffer *b)
391 unbind_to (count, Qnil); 376 unbind_to (count, Qnil);
392 return; 377 return;
393 } 378 }
394 /* That function probably used the minibuffer, and if so, that
395 changed last_undo_buffer. Change it back so that we don't
396 force next change to make an undo boundary here. */
397 last_undo_buffer = temp;
398 } 379 }
399 380
400 if (CONSP (next)) 381 if (CONSP (next))
@@ -452,6 +433,9 @@ void
452syms_of_undo (void) 433syms_of_undo (void)
453{ 434{
454 DEFSYM (Qinhibit_read_only, "inhibit-read-only"); 435 DEFSYM (Qinhibit_read_only, "inhibit-read-only");
436 DEFSYM (Qundo_auto__undoable_change, "undo-auto--undoable-change");
437 DEFSYM (Qundo_auto__last_boundary_cause, "undo-auto--last-boundary-cause");
438 DEFSYM (Qexplicit, "explicit");
455 439
456 /* Marker for function call undo list elements. */ 440 /* Marker for function call undo list elements. */
457 DEFSYM (Qapply, "apply"); 441 DEFSYM (Qapply, "apply");
@@ -459,7 +443,6 @@ syms_of_undo (void)
459 pending_boundary = Qnil; 443 pending_boundary = Qnil;
460 staticpro (&pending_boundary); 444 staticpro (&pending_boundary);
461 445
462 last_undo_buffer = NULL;
463 last_boundary_buffer = NULL; 446 last_boundary_buffer = NULL;
464 447
465 defsubr (&Sundo_boundary); 448 defsubr (&Sundo_boundary);