diff options
Diffstat (limited to 'src/cmds.c')
| -rw-r--r-- | src/cmds.c | 85 |
1 files changed, 44 insertions, 41 deletions
diff --git a/src/cmds.c b/src/cmds.c index ce05b19e1c2..5dc4d2bfe30 100644 --- a/src/cmds.c +++ b/src/cmds.c | |||
| @@ -31,10 +31,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 31 | #include "dispextern.h" | 31 | #include "dispextern.h" |
| 32 | #include "frame.h" | 32 | #include "frame.h" |
| 33 | 33 | ||
| 34 | Lisp_Object Qkill_forward_chars, Qkill_backward_chars; | 34 | static Lisp_Object Qkill_forward_chars, Qkill_backward_chars; |
| 35 | 35 | ||
| 36 | /* A possible value for a buffer's overwrite-mode variable. */ | 36 | /* A possible value for a buffer's overwrite-mode variable. */ |
| 37 | Lisp_Object Qoverwrite_mode_binary; | 37 | static Lisp_Object Qoverwrite_mode_binary; |
| 38 | 38 | ||
| 39 | static int internal_self_insert (int, EMACS_INT); | 39 | static int internal_self_insert (int, EMACS_INT); |
| 40 | 40 | ||
| @@ -277,7 +277,7 @@ After insertion, the value of `auto-fill-function' is called if the | |||
| 277 | int remove_boundary = 1; | 277 | int remove_boundary = 1; |
| 278 | CHECK_NATNUM (n); | 278 | CHECK_NATNUM (n); |
| 279 | 279 | ||
| 280 | if (!EQ (Vthis_command, current_kboard->Vlast_command)) | 280 | if (!EQ (Vthis_command, KVAR (current_kboard, Vlast_command))) |
| 281 | nonundocount = 0; | 281 | nonundocount = 0; |
| 282 | 282 | ||
| 283 | if (NILP (Vexecuting_kbd_macro) | 283 | if (NILP (Vexecuting_kbd_macro) |
| @@ -292,10 +292,10 @@ After insertion, the value of `auto-fill-function' is called if the | |||
| 292 | } | 292 | } |
| 293 | 293 | ||
| 294 | if (remove_boundary | 294 | if (remove_boundary |
| 295 | && CONSP (current_buffer->undo_list) | 295 | && CONSP (BVAR (current_buffer, undo_list)) |
| 296 | && NILP (XCAR (current_buffer->undo_list))) | 296 | && NILP (XCAR (BVAR (current_buffer, undo_list)))) |
| 297 | /* Remove the undo_boundary that was just pushed. */ | 297 | /* Remove the undo_boundary that was just pushed. */ |
| 298 | current_buffer->undo_list = XCDR (current_buffer->undo_list); | 298 | BVAR (current_buffer, undo_list) = XCDR (BVAR (current_buffer, undo_list)); |
| 299 | 299 | ||
| 300 | /* Barf if the key that invoked this was not a character. */ | 300 | /* Barf if the key that invoked this was not a character. */ |
| 301 | if (!CHARACTERP (last_command_event)) | 301 | if (!CHARACTERP (last_command_event)) |
| @@ -335,12 +335,12 @@ internal_self_insert (int c, EMACS_INT n) | |||
| 335 | EMACS_INT chars_to_delete = 0; | 335 | EMACS_INT chars_to_delete = 0; |
| 336 | EMACS_INT spaces_to_insert = 0; | 336 | EMACS_INT spaces_to_insert = 0; |
| 337 | 337 | ||
| 338 | overwrite = current_buffer->overwrite_mode; | 338 | overwrite = BVAR (current_buffer, overwrite_mode); |
| 339 | if (!NILP (Vbefore_change_functions) || !NILP (Vafter_change_functions)) | 339 | if (!NILP (Vbefore_change_functions) || !NILP (Vafter_change_functions)) |
| 340 | hairy = 1; | 340 | hairy = 1; |
| 341 | 341 | ||
| 342 | /* At first, get multi-byte form of C in STR. */ | 342 | /* At first, get multi-byte form of C in STR. */ |
| 343 | if (!NILP (current_buffer->enable_multibyte_characters)) | 343 | if (!NILP (BVAR (current_buffer, enable_multibyte_characters))) |
| 344 | { | 344 | { |
| 345 | len = CHAR_STRING (c, str); | 345 | len = CHAR_STRING (c, str); |
| 346 | if (len == 1) | 346 | if (len == 1) |
| @@ -352,7 +352,7 @@ internal_self_insert (int c, EMACS_INT n) | |||
| 352 | { | 352 | { |
| 353 | str[0] = (SINGLE_BYTE_CHAR_P (c) | 353 | str[0] = (SINGLE_BYTE_CHAR_P (c) |
| 354 | ? c | 354 | ? c |
| 355 | : multibyte_char_to_unibyte (c, Qnil)); | 355 | : multibyte_char_to_unibyte (c)); |
| 356 | len = 1; | 356 | len = 1; |
| 357 | } | 357 | } |
| 358 | if (!NILP (overwrite) | 358 | if (!NILP (overwrite) |
| @@ -381,33 +381,37 @@ internal_self_insert (int c, EMACS_INT n) | |||
| 381 | { | 381 | { |
| 382 | EMACS_INT pos = PT; | 382 | EMACS_INT pos = PT; |
| 383 | EMACS_INT pos_byte = PT_BYTE; | 383 | EMACS_INT pos_byte = PT_BYTE; |
| 384 | |||
| 385 | /* FIXME: Check for integer overflow when calculating | ||
| 386 | target_clm and actual_clm. */ | ||
| 387 | |||
| 384 | /* Column the cursor should be placed at after this insertion. | 388 | /* Column the cursor should be placed at after this insertion. |
| 385 | The correct value should be calculated only when necessary. */ | 389 | The correct value should be calculated only when necessary. */ |
| 386 | int target_clm = ((int) current_column () /* iftc */ | 390 | EMACS_INT target_clm = (current_column () |
| 387 | + n * (int) XINT (Fchar_width (make_number (c)))); | 391 | + n * XINT (Fchar_width (make_number (c)))); |
| 388 | 392 | ||
| 389 | /* The actual cursor position after the trial of moving | 393 | /* The actual cursor position after the trial of moving |
| 390 | to column TARGET_CLM. It is greater than TARGET_CLM | 394 | to column TARGET_CLM. It is greater than TARGET_CLM |
| 391 | if the TARGET_CLM is middle of multi-column | 395 | if the TARGET_CLM is middle of multi-column |
| 392 | character. In that case, the new point is set after | 396 | character. In that case, the new point is set after |
| 393 | that character. */ | 397 | that character. */ |
| 394 | int actual_clm | 398 | EMACS_INT actual_clm |
| 395 | = (int) XFASTINT (Fmove_to_column (make_number (target_clm), | 399 | = XFASTINT (Fmove_to_column (make_number (target_clm), Qnil)); |
| 396 | Qnil)); | 400 | |
| 397 | 401 | chars_to_delete = PT - pos; | |
| 398 | chars_to_delete = PT - pos; | 402 | |
| 399 | 403 | if (actual_clm > target_clm) | |
| 400 | if (actual_clm > target_clm) | 404 | { |
| 401 | { /* We will delete too many columns. Let's fill columns | 405 | /* We will delete too many columns. Let's fill columns |
| 402 | by spaces so that the remaining text won't move. */ | 406 | by spaces so that the remaining text won't move. */ |
| 403 | EMACS_INT actual = PT_BYTE; | 407 | EMACS_INT actual = PT_BYTE; |
| 404 | DEC_POS (actual); | 408 | DEC_POS (actual); |
| 405 | if (FETCH_CHAR (actual) == '\t') | 409 | if (FETCH_CHAR (actual) == '\t') |
| 406 | /* Rather than add spaces, let's just keep the tab. */ | 410 | /* Rather than add spaces, let's just keep the tab. */ |
| 407 | chars_to_delete--; | 411 | chars_to_delete--; |
| 408 | else | 412 | else |
| 409 | spaces_to_insert = actual_clm - target_clm; | 413 | spaces_to_insert = actual_clm - target_clm; |
| 410 | } | 414 | } |
| 411 | 415 | ||
| 412 | SET_PT_BOTH (pos, pos_byte); | 416 | SET_PT_BOTH (pos, pos_byte); |
| 413 | } | 417 | } |
| @@ -416,11 +420,11 @@ internal_self_insert (int c, EMACS_INT n) | |||
| 416 | 420 | ||
| 417 | synt = SYNTAX (c); | 421 | synt = SYNTAX (c); |
| 418 | 422 | ||
| 419 | if (!NILP (current_buffer->abbrev_mode) | 423 | if (!NILP (BVAR (current_buffer, abbrev_mode)) |
| 420 | && synt != Sword | 424 | && synt != Sword |
| 421 | && NILP (current_buffer->read_only) | 425 | && NILP (BVAR (current_buffer, read_only)) |
| 422 | && PT > BEGV | 426 | && PT > BEGV |
| 423 | && (SYNTAX (!NILP (current_buffer->enable_multibyte_characters) | 427 | && (SYNTAX (!NILP (BVAR (current_buffer, enable_multibyte_characters)) |
| 424 | ? XFASTINT (Fprevious_char ()) | 428 | ? XFASTINT (Fprevious_char ()) |
| 425 | : UNIBYTE_TO_CHAR (XFASTINT (Fprevious_char ()))) | 429 | : UNIBYTE_TO_CHAR (XFASTINT (Fprevious_char ()))) |
| 426 | == Sword)) | 430 | == Sword)) |
| @@ -448,7 +452,7 @@ internal_self_insert (int c, EMACS_INT n) | |||
| 448 | 452 | ||
| 449 | if (chars_to_delete) | 453 | if (chars_to_delete) |
| 450 | { | 454 | { |
| 451 | int mc = ((NILP (current_buffer->enable_multibyte_characters) | 455 | int mc = ((NILP (BVAR (current_buffer, enable_multibyte_characters)) |
| 452 | && SINGLE_BYTE_CHAR_P (c)) | 456 | && SINGLE_BYTE_CHAR_P (c)) |
| 453 | ? UNIBYTE_TO_CHAR (c) : c); | 457 | ? UNIBYTE_TO_CHAR (c) : c); |
| 454 | Lisp_Object string = Fmake_string (make_number (n), make_number (mc)); | 458 | Lisp_Object string = Fmake_string (make_number (n), make_number (mc)); |
| @@ -466,38 +470,38 @@ internal_self_insert (int c, EMACS_INT n) | |||
| 466 | else if (n > 1) | 470 | else if (n > 1) |
| 467 | { | 471 | { |
| 468 | USE_SAFE_ALLOCA; | 472 | USE_SAFE_ALLOCA; |
| 469 | unsigned char *strn, *p; | 473 | char *strn, *p; |
| 470 | SAFE_ALLOCA (strn, unsigned char*, n * len); | 474 | SAFE_ALLOCA (strn, char *, n * len); |
| 471 | for (p = strn; n > 0; n--, p += len) | 475 | for (p = strn; n > 0; n--, p += len) |
| 472 | memcpy (p, str, len); | 476 | memcpy (p, str, len); |
| 473 | insert_and_inherit (strn, p - strn); | 477 | insert_and_inherit (strn, p - strn); |
| 474 | SAFE_FREE (); | 478 | SAFE_FREE (); |
| 475 | } | 479 | } |
| 476 | else if (n > 0) | 480 | else if (n > 0) |
| 477 | insert_and_inherit (str, len); | 481 | insert_and_inherit ((char *) str, len); |
| 478 | 482 | ||
| 479 | if ((CHAR_TABLE_P (Vauto_fill_chars) | 483 | if ((CHAR_TABLE_P (Vauto_fill_chars) |
| 480 | ? !NILP (CHAR_TABLE_REF (Vauto_fill_chars, c)) | 484 | ? !NILP (CHAR_TABLE_REF (Vauto_fill_chars, c)) |
| 481 | : (c == ' ' || c == '\n')) | 485 | : (c == ' ' || c == '\n')) |
| 482 | && !NILP (current_buffer->auto_fill_function)) | 486 | && !NILP (BVAR (current_buffer, auto_fill_function))) |
| 483 | { | 487 | { |
| 484 | Lisp_Object tem; | 488 | Lisp_Object auto_fill_result; |
| 485 | 489 | ||
| 486 | if (c == '\n') | 490 | if (c == '\n') |
| 487 | /* After inserting a newline, move to previous line and fill | 491 | /* After inserting a newline, move to previous line and fill |
| 488 | that. Must have the newline in place already so filling and | 492 | that. Must have the newline in place already so filling and |
| 489 | justification, if any, know where the end is going to be. */ | 493 | justification, if any, know where the end is going to be. */ |
| 490 | SET_PT_BOTH (PT - 1, PT_BYTE - 1); | 494 | SET_PT_BOTH (PT - 1, PT_BYTE - 1); |
| 491 | tem = call0 (current_buffer->auto_fill_function); | 495 | auto_fill_result = call0 (BVAR (current_buffer, auto_fill_function)); |
| 492 | /* Test PT < ZV in case the auto-fill-function is strange. */ | 496 | /* Test PT < ZV in case the auto-fill-function is strange. */ |
| 493 | if (c == '\n' && PT < ZV) | 497 | if (c == '\n' && PT < ZV) |
| 494 | SET_PT_BOTH (PT + 1, PT_BYTE + 1); | 498 | SET_PT_BOTH (PT + 1, PT_BYTE + 1); |
| 495 | if (!NILP (tem)) | 499 | if (!NILP (auto_fill_result)) |
| 496 | hairy = 2; | 500 | hairy = 2; |
| 497 | } | 501 | } |
| 498 | 502 | ||
| 499 | /* Run hooks for electric keys. */ | 503 | /* Run hooks for electric keys. */ |
| 500 | call1 (Vrun_hooks, Qpost_self_insert_hook); | 504 | Frun_hooks (1, &Qpost_self_insert_hook); |
| 501 | 505 | ||
| 502 | return hairy; | 506 | return hairy; |
| 503 | } | 507 | } |
| @@ -559,4 +563,3 @@ keys_of_cmds (void) | |||
| 559 | initial_define_key (global_map, Ctl ('E'), "end-of-line"); | 563 | initial_define_key (global_map, Ctl ('E'), "end-of-line"); |
| 560 | initial_define_key (global_map, Ctl ('F'), "forward-char"); | 564 | initial_define_key (global_map, Ctl ('F'), "forward-char"); |
| 561 | } | 565 | } |
| 562 | |||