diff options
| author | Stefan Monnier | 2015-04-13 14:05:09 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2015-04-13 14:05:09 -0400 |
| commit | 5729f459d1dbb28bc405a142860a99e1329f388a (patch) | |
| tree | fd47406fdfe5c37382edb1808b0d690ee77f47fa /src/cmds.c | |
| parent | 5d9432e6491f63fe4859a46737516c9510643626 (diff) | |
| download | emacs-5729f459d1dbb28bc405a142860a99e1329f388a.tar.gz emacs-5729f459d1dbb28bc405a142860a99e1329f388a.zip | |
Collapse successive char deletions in the undo log
* src/cmds.c (remove_excessive_undo_boundaries): New function,
extracted from Fself_insert_command.
(Fdelete_char, Fself_insert_command): Use it.
* src/fileio.c (Fmake_symbolic_link): Rename arg to `target'.
* src/keyboard.c (syms_of_keyboard): `top-level' shouldn't be special.
Diffstat (limited to 'src/cmds.c')
| -rw-r--r-- | src/cmds.c | 60 |
1 files changed, 35 insertions, 25 deletions
diff --git a/src/cmds.c b/src/cmds.c index 270fc39cabc..168ce8355ed 100644 --- a/src/cmds.c +++ b/src/cmds.c | |||
| @@ -213,6 +213,36 @@ to t. */) | |||
| 213 | return Qnil; | 213 | return Qnil; |
| 214 | } | 214 | } |
| 215 | 215 | ||
| 216 | static int nonundocount; | ||
| 217 | |||
| 218 | static void | ||
| 219 | remove_excessive_undo_boundaries (void) | ||
| 220 | { | ||
| 221 | bool remove_boundary = true; | ||
| 222 | |||
| 223 | if (!EQ (Vthis_command, KVAR (current_kboard, Vlast_command))) | ||
| 224 | nonundocount = 0; | ||
| 225 | |||
| 226 | if (NILP (Vexecuting_kbd_macro)) | ||
| 227 | { | ||
| 228 | if (nonundocount <= 0 || nonundocount >= 20) | ||
| 229 | { | ||
| 230 | remove_boundary = false; | ||
| 231 | nonundocount = 0; | ||
| 232 | } | ||
| 233 | nonundocount++; | ||
| 234 | } | ||
| 235 | |||
| 236 | if (remove_boundary | ||
| 237 | && CONSP (BVAR (current_buffer, undo_list)) | ||
| 238 | && NILP (XCAR (BVAR (current_buffer, undo_list))) | ||
| 239 | /* Only remove auto-added boundaries, not boundaries | ||
| 240 | added by explicit calls to undo-boundary. */ | ||
| 241 | && EQ (BVAR (current_buffer, undo_list), last_undo_boundary)) | ||
| 242 | /* Remove the undo_boundary that was just pushed. */ | ||
| 243 | bset_undo_list (current_buffer, XCDR (BVAR (current_buffer, undo_list))); | ||
| 244 | } | ||
| 245 | |||
| 216 | DEFUN ("delete-char", Fdelete_char, Sdelete_char, 1, 2, "p\nP", | 246 | DEFUN ("delete-char", Fdelete_char, Sdelete_char, 1, 2, "p\nP", |
| 217 | doc: /* Delete the following N characters (previous if N is negative). | 247 | doc: /* Delete the following N characters (previous if N is negative). |
| 218 | Optional second arg KILLFLAG non-nil means kill instead (save in kill ring). | 248 | Optional second arg KILLFLAG non-nil means kill instead (save in kill ring). |
| @@ -227,6 +257,9 @@ because it respects values of `delete-active-region' and `overwrite-mode'. */) | |||
| 227 | 257 | ||
| 228 | CHECK_NUMBER (n); | 258 | CHECK_NUMBER (n); |
| 229 | 259 | ||
| 260 | if (abs (XINT (n)) < 2) | ||
| 261 | remove_excessive_undo_boundaries (); | ||
| 262 | |||
| 230 | pos = PT + XINT (n); | 263 | pos = PT + XINT (n); |
| 231 | if (NILP (killflag)) | 264 | if (NILP (killflag)) |
| 232 | { | 265 | { |
| @@ -252,8 +285,6 @@ because it respects values of `delete-active-region' and `overwrite-mode'. */) | |||
| 252 | return Qnil; | 285 | return Qnil; |
| 253 | } | 286 | } |
| 254 | 287 | ||
| 255 | static int nonundocount; | ||
| 256 | |||
| 257 | /* Note that there's code in command_loop_1 which typically avoids | 288 | /* Note that there's code in command_loop_1 which typically avoids |
| 258 | calling this. */ | 289 | calling this. */ |
| 259 | DEFUN ("self-insert-command", Fself_insert_command, Sself_insert_command, 1, 1, "p", | 290 | DEFUN ("self-insert-command", Fself_insert_command, Sself_insert_command, 1, 1, "p", |
| @@ -267,34 +298,13 @@ After insertion, the value of `auto-fill-function' is called if the | |||
| 267 | At the end, it runs `post-self-insert-hook'. */) | 298 | At the end, it runs `post-self-insert-hook'. */) |
| 268 | (Lisp_Object n) | 299 | (Lisp_Object n) |
| 269 | { | 300 | { |
| 270 | bool remove_boundary = 1; | ||
| 271 | CHECK_NUMBER (n); | 301 | CHECK_NUMBER (n); |
| 272 | 302 | ||
| 273 | if (XFASTINT (n) < 0) | 303 | if (XFASTINT (n) < 0) |
| 274 | error ("Negative repetition argument %"pI"d", XFASTINT (n)); | 304 | error ("Negative repetition argument %"pI"d", XFASTINT (n)); |
| 275 | 305 | ||
| 276 | if (!EQ (Vthis_command, KVAR (current_kboard, Vlast_command))) | 306 | if (XFASTINT (n) < 2) |
| 277 | nonundocount = 0; | 307 | remove_excessive_undo_boundaries (); |
| 278 | |||
| 279 | if (NILP (Vexecuting_kbd_macro) | ||
| 280 | && !EQ (minibuf_window, selected_window)) | ||
| 281 | { | ||
| 282 | if (nonundocount <= 0 || nonundocount >= 20) | ||
| 283 | { | ||
| 284 | remove_boundary = 0; | ||
| 285 | nonundocount = 0; | ||
| 286 | } | ||
| 287 | nonundocount++; | ||
| 288 | } | ||
| 289 | |||
| 290 | if (remove_boundary | ||
| 291 | && CONSP (BVAR (current_buffer, undo_list)) | ||
| 292 | && NILP (XCAR (BVAR (current_buffer, undo_list))) | ||
| 293 | /* Only remove auto-added boundaries, not boundaries | ||
| 294 | added be explicit calls to undo-boundary. */ | ||
| 295 | && EQ (BVAR (current_buffer, undo_list), last_undo_boundary)) | ||
| 296 | /* Remove the undo_boundary that was just pushed. */ | ||
| 297 | bset_undo_list (current_buffer, XCDR (BVAR (current_buffer, undo_list))); | ||
| 298 | 308 | ||
| 299 | /* Barf if the key that invoked this was not a character. */ | 309 | /* Barf if the key that invoked this was not a character. */ |
| 300 | if (!CHARACTERP (last_command_event)) | 310 | if (!CHARACTERP (last_command_event)) |