aboutsummaryrefslogtreecommitdiffstats
path: root/src/cmds.c
diff options
context:
space:
mode:
authorPhillip Lord2015-08-06 21:33:58 +0100
committerPhillip Lord2015-11-12 21:06:05 +0000
commit44dfa86b7d382b84564d68472da1448d08f48129 (patch)
tree778e2228ec90a4401b2be6cd7b258ee44a212b26 /src/cmds.c
parent0aec2aaccd8b745fa7214f3edd453c04a04bfba4 (diff)
downloademacs-44dfa86b7d382b84564d68472da1448d08f48129.tar.gz
emacs-44dfa86b7d382b84564d68472da1448d08f48129.zip
The heuristic that Emacs uses to add an `undo-boundary' has been
reworked, as it interacts poorly with functions on `post-command-hook' or `after-change-functions'. * lisp/simple.el: New section added. * src/cmds.c (remove_excessive_undo_boundaries): Now in lisp. (self_insert_command): Calls simple.el to amalgamate. (delete_char): Calls simple.el to amalgamate. * src/keyboard.c (last_undo_boundary): Removed. * src/undo.c (run_undoable_change): New function.
Diffstat (limited to 'src/cmds.c')
-rw-r--r--src/cmds.c41
1 files changed, 7 insertions, 34 deletions
diff --git a/src/cmds.c b/src/cmds.c
index a975a8ed4e0..6f19a046893 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -220,36 +220,6 @@ to t. */)
220 return Qnil; 220 return Qnil;
221} 221}
222 222
223static int nonundocount;
224
225static void
226remove_excessive_undo_boundaries (void)
227{
228 bool remove_boundary = true;
229
230 if (!EQ (Vthis_command, KVAR (current_kboard, Vlast_command)))
231 nonundocount = 0;
232
233 if (NILP (Vexecuting_kbd_macro))
234 {
235 if (nonundocount <= 0 || nonundocount >= 20)
236 {
237 remove_boundary = false;
238 nonundocount = 0;
239 }
240 nonundocount++;
241 }
242
243 if (remove_boundary
244 && CONSP (BVAR (current_buffer, undo_list))
245 && NILP (XCAR (BVAR (current_buffer, undo_list)))
246 /* Only remove auto-added boundaries, not boundaries
247 added by explicit calls to undo-boundary. */
248 && EQ (BVAR (current_buffer, undo_list), last_undo_boundary))
249 /* Remove the undo_boundary that was just pushed. */
250 bset_undo_list (current_buffer, XCDR (BVAR (current_buffer, undo_list)));
251}
252
253DEFUN ("delete-char", Fdelete_char, Sdelete_char, 1, 2, "p\nP", 223DEFUN ("delete-char", Fdelete_char, Sdelete_char, 1, 2, "p\nP",
254 doc: /* Delete the following N characters (previous if N is negative). 224 doc: /* Delete the following N characters (previous if N is negative).
255Optional second arg KILLFLAG non-nil means kill instead (save in kill ring). 225Optional second arg KILLFLAG non-nil means kill instead (save in kill ring).
@@ -265,7 +235,7 @@ because it respects values of `delete-active-region' and `overwrite-mode'. */)
265 CHECK_NUMBER (n); 235 CHECK_NUMBER (n);
266 236
267 if (abs (XINT (n)) < 2) 237 if (abs (XINT (n)) < 2)
268 remove_excessive_undo_boundaries (); 238 call0 (Qundo_auto__amalgamate);
269 239
270 pos = PT + XINT (n); 240 pos = PT + XINT (n);
271 if (NILP (killflag)) 241 if (NILP (killflag))
@@ -311,7 +281,7 @@ At the end, it runs `post-self-insert-hook'. */)
311 error ("Negative repetition argument %"pI"d", XFASTINT (n)); 281 error ("Negative repetition argument %"pI"d", XFASTINT (n));
312 282
313 if (XFASTINT (n) < 2) 283 if (XFASTINT (n) < 2)
314 remove_excessive_undo_boundaries (); 284 call0 (Qundo_auto__amalgamate);
315 285
316 /* Barf if the key that invoked this was not a character. */ 286 /* Barf if the key that invoked this was not a character. */
317 if (!CHARACTERP (last_command_event)) 287 if (!CHARACTERP (last_command_event))
@@ -321,7 +291,7 @@ At the end, it runs `post-self-insert-hook'. */)
321 XINT (last_command_event)); 291 XINT (last_command_event));
322 int val = internal_self_insert (character, XFASTINT (n)); 292 int val = internal_self_insert (character, XFASTINT (n));
323 if (val == 2) 293 if (val == 2)
324 nonundocount = 0; 294 Fset (Qundo_auto__this_command_amalgamating, Qnil);
325 frame_make_pointer_invisible (SELECTED_FRAME ()); 295 frame_make_pointer_invisible (SELECTED_FRAME ());
326 } 296 }
327 297
@@ -526,6 +496,10 @@ internal_self_insert (int c, EMACS_INT n)
526void 496void
527syms_of_cmds (void) 497syms_of_cmds (void)
528{ 498{
499 DEFSYM (Qundo_auto__amalgamate, "undo-auto--amalgamate");
500 DEFSYM (Qundo_auto__this_command_amalgamating,
501 "undo-auto--this-command-amalgamating");
502
529 DEFSYM (Qkill_forward_chars, "kill-forward-chars"); 503 DEFSYM (Qkill_forward_chars, "kill-forward-chars");
530 504
531 /* A possible value for a buffer's overwrite-mode variable. */ 505 /* A possible value for a buffer's overwrite-mode variable. */
@@ -555,7 +529,6 @@ keys_of_cmds (void)
555{ 529{
556 int n; 530 int n;
557 531
558 nonundocount = 0;
559 initial_define_key (global_map, Ctl ('I'), "self-insert-command"); 532 initial_define_key (global_map, Ctl ('I'), "self-insert-command");
560 for (n = 040; n < 0177; n++) 533 for (n = 040; n < 0177; n++)
561 initial_define_key (global_map, n, "self-insert-command"); 534 initial_define_key (global_map, n, "self-insert-command");