diff options
Diffstat (limited to 'src/cmds.c')
| -rw-r--r-- | src/cmds.c | 147 |
1 files changed, 34 insertions, 113 deletions
diff --git a/src/cmds.c b/src/cmds.c index ba89c532be8..f306ede7ca5 100644 --- a/src/cmds.c +++ b/src/cmds.c | |||
| @@ -37,19 +37,11 @@ Lisp_Object Qkill_forward_chars, Qkill_backward_chars, Vblink_paren_function; | |||
| 37 | /* A possible value for a buffer's overwrite-mode variable. */ | 37 | /* A possible value for a buffer's overwrite-mode variable. */ |
| 38 | Lisp_Object Qoverwrite_mode_binary; | 38 | Lisp_Object Qoverwrite_mode_binary; |
| 39 | 39 | ||
| 40 | /* Non-nil means put this face on the next self-inserting character. */ | 40 | static int internal_self_insert (int, int); |
| 41 | Lisp_Object Vself_insert_face; | ||
| 42 | |||
| 43 | /* This is the command that set up Vself_insert_face. */ | ||
| 44 | Lisp_Object Vself_insert_face_command; | ||
| 45 | |||
| 46 | extern Lisp_Object Qface; | ||
| 47 | extern Lisp_Object Vtranslation_table_for_input; | ||
| 48 | 41 | ||
| 49 | DEFUN ("forward-point", Fforward_point, Sforward_point, 1, 1, 0, | 42 | DEFUN ("forward-point", Fforward_point, Sforward_point, 1, 1, 0, |
| 50 | doc: /* Return buffer position N characters after (before if N negative) point. */) | 43 | doc: /* Return buffer position N characters after (before if N negative) point. */) |
| 51 | (n) | 44 | (Lisp_Object n) |
| 52 | Lisp_Object n; | ||
| 53 | { | 45 | { |
| 54 | CHECK_NUMBER (n); | 46 | CHECK_NUMBER (n); |
| 55 | 47 | ||
| @@ -63,8 +55,7 @@ On reaching end or beginning of buffer, stop and signal error. | |||
| 63 | Depending on the bidirectional context, the movement may be to the | 55 | Depending on the bidirectional context, the movement may be to the |
| 64 | right or to the left on the screen. This is in contrast with | 56 | right or to the left on the screen. This is in contrast with |
| 65 | \\[right-char], which see. */) | 57 | \\[right-char], which see. */) |
| 66 | (n) | 58 | (Lisp_Object n) |
| 67 | Lisp_Object n; | ||
| 68 | { | 59 | { |
| 69 | if (NILP (n)) | 60 | if (NILP (n)) |
| 70 | XSETFASTINT (n, 1); | 61 | XSETFASTINT (n, 1); |
| @@ -103,8 +94,7 @@ On attempt to pass beginning or end of buffer, stop and signal error. | |||
| 103 | Depending on the bidirectional context, the movement may be to the | 94 | Depending on the bidirectional context, the movement may be to the |
| 104 | right or to the left on the screen. This is in contrast with | 95 | right or to the left on the screen. This is in contrast with |
| 105 | \\[left-char], which see. */) | 96 | \\[left-char], which see. */) |
| 106 | (n) | 97 | (Lisp_Object n) |
| 107 | Lisp_Object n; | ||
| 108 | { | 98 | { |
| 109 | if (NILP (n)) | 99 | if (NILP (n)) |
| 110 | XSETFASTINT (n, 1); | 100 | XSETFASTINT (n, 1); |
| @@ -117,14 +107,14 @@ right or to the left on the screen. This is in contrast with | |||
| 117 | 107 | ||
| 118 | DEFUN ("forward-line", Fforward_line, Sforward_line, 0, 1, "^p", | 108 | DEFUN ("forward-line", Fforward_line, Sforward_line, 0, 1, "^p", |
| 119 | doc: /* Move N lines forward (backward if N is negative). | 109 | doc: /* Move N lines forward (backward if N is negative). |
| 120 | Precisely, if point is on line I, move to the start of line I + N. | 110 | Precisely, if point is on line I, move to the start of line I + N |
| 111 | \("start of line" in the logical order). | ||
| 121 | If there isn't room, go as far as possible (no error). | 112 | If there isn't room, go as far as possible (no error). |
| 122 | Returns the count of lines left to move. If moving forward, | 113 | Returns the count of lines left to move. If moving forward, |
| 123 | that is N - number of lines moved; if backward, N + number moved. | 114 | that is N - number of lines moved; if backward, N + number moved. |
| 124 | With positive N, a non-empty line at the end counts as one line | 115 | With positive N, a non-empty line at the end counts as one line |
| 125 | successfully moved (for the return value). */) | 116 | successfully moved (for the return value). */) |
| 126 | (n) | 117 | (Lisp_Object n) |
| 127 | Lisp_Object n; | ||
| 128 | { | 118 | { |
| 129 | int opoint = PT, opoint_byte = PT_BYTE; | 119 | int opoint = PT, opoint_byte = PT_BYTE; |
| 130 | int pos, pos_byte; | 120 | int pos, pos_byte; |
| @@ -162,7 +152,7 @@ successfully moved (for the return value). */) | |||
| 162 | } | 152 | } |
| 163 | 153 | ||
| 164 | DEFUN ("beginning-of-line", Fbeginning_of_line, Sbeginning_of_line, 0, 1, "^p", | 154 | DEFUN ("beginning-of-line", Fbeginning_of_line, Sbeginning_of_line, 0, 1, "^p", |
| 165 | doc: /* Move point to beginning of current line. | 155 | doc: /* Move point to beginning of current line (in the logical order). |
| 166 | With argument N not nil or 1, move forward N - 1 lines first. | 156 | With argument N not nil or 1, move forward N - 1 lines first. |
| 167 | If point reaches the beginning or end of buffer, it stops there. | 157 | If point reaches the beginning or end of buffer, it stops there. |
| 168 | 158 | ||
| @@ -173,8 +163,7 @@ does not move. To ignore field boundaries bind | |||
| 173 | `inhibit-field-text-motion' to t, or use the `forward-line' function | 163 | `inhibit-field-text-motion' to t, or use the `forward-line' function |
| 174 | instead. For instance, `(forward-line 0)' does the same thing as | 164 | instead. For instance, `(forward-line 0)' does the same thing as |
| 175 | `(beginning-of-line)', except that it ignores field boundaries. */) | 165 | `(beginning-of-line)', except that it ignores field boundaries. */) |
| 176 | (n) | 166 | (Lisp_Object n) |
| 177 | Lisp_Object n; | ||
| 178 | { | 167 | { |
| 179 | if (NILP (n)) | 168 | if (NILP (n)) |
| 180 | XSETFASTINT (n, 1); | 169 | XSETFASTINT (n, 1); |
| @@ -187,7 +176,7 @@ instead. For instance, `(forward-line 0)' does the same thing as | |||
| 187 | } | 176 | } |
| 188 | 177 | ||
| 189 | DEFUN ("end-of-line", Fend_of_line, Send_of_line, 0, 1, "^p", | 178 | DEFUN ("end-of-line", Fend_of_line, Send_of_line, 0, 1, "^p", |
| 190 | doc: /* Move point to end of current line. | 179 | doc: /* Move point to end of current line (in the logical order). |
| 191 | With argument N not nil or 1, move forward N - 1 lines first. | 180 | With argument N not nil or 1, move forward N - 1 lines first. |
| 192 | If point reaches the beginning or end of buffer, it stops there. | 181 | If point reaches the beginning or end of buffer, it stops there. |
| 193 | To ignore intangibility, bind `inhibit-point-motion-hooks' to t. | 182 | To ignore intangibility, bind `inhibit-point-motion-hooks' to t. |
| @@ -197,8 +186,7 @@ point to a different line than the original, unconstrained result. If | |||
| 197 | N is nil or 1, and a rear-sticky field ends at point, the point does | 186 | N is nil or 1, and a rear-sticky field ends at point, the point does |
| 198 | not move. To ignore field boundaries bind `inhibit-field-text-motion' | 187 | not move. To ignore field boundaries bind `inhibit-field-text-motion' |
| 199 | to t. */) | 188 | to t. */) |
| 200 | (n) | 189 | (Lisp_Object n) |
| 201 | Lisp_Object n; | ||
| 202 | { | 190 | { |
| 203 | int newpos; | 191 | int newpos; |
| 204 | 192 | ||
| @@ -240,9 +228,10 @@ DEFUN ("delete-char", Fdelete_char, Sdelete_char, 1, 2, "p\nP", | |||
| 240 | doc: /* Delete the following N characters (previous if N is negative). | 228 | doc: /* Delete the following N characters (previous if N is negative). |
| 241 | Optional second arg KILLFLAG non-nil means kill instead (save in kill ring). | 229 | Optional second arg KILLFLAG non-nil means kill instead (save in kill ring). |
| 242 | Interactively, N is the prefix arg, and KILLFLAG is set if | 230 | Interactively, N is the prefix arg, and KILLFLAG is set if |
| 243 | N was explicitly specified. */) | 231 | N was explicitly specified. |
| 244 | (n, killflag) | 232 | |
| 245 | Lisp_Object n, killflag; | 233 | The command `delete-forward' is preferable for interactive use. */) |
| 234 | (Lisp_Object n, Lisp_Object killflag) | ||
| 246 | { | 235 | { |
| 247 | int pos; | 236 | int pos; |
| 248 | 237 | ||
| @@ -273,60 +262,6 @@ N was explicitly specified. */) | |||
| 273 | return Qnil; | 262 | return Qnil; |
| 274 | } | 263 | } |
| 275 | 264 | ||
| 276 | DEFUN ("delete-backward-char", Fdelete_backward_char, Sdelete_backward_char, | ||
| 277 | 1, 2, "p\nP", | ||
| 278 | doc: /* Delete the previous N characters (following if N is negative). | ||
| 279 | Optional second arg KILLFLAG non-nil means kill instead (save in kill ring). | ||
| 280 | Interactively, N is the prefix arg, and KILLFLAG is set if | ||
| 281 | N was explicitly specified. | ||
| 282 | This is meant for interactive use only; from Lisp, better use `delete-char' | ||
| 283 | with a negated argument. */) | ||
| 284 | (n, killflag) | ||
| 285 | Lisp_Object n, killflag; | ||
| 286 | { | ||
| 287 | Lisp_Object value; | ||
| 288 | int deleted_special = 0; | ||
| 289 | int pos, pos_byte, i; | ||
| 290 | |||
| 291 | CHECK_NUMBER (n); | ||
| 292 | |||
| 293 | /* See if we are about to delete a tab or newline backwards. */ | ||
| 294 | pos = PT; | ||
| 295 | pos_byte = PT_BYTE; | ||
| 296 | for (i = 0; i < XINT (n) && pos_byte > BEGV_BYTE; i++) | ||
| 297 | { | ||
| 298 | int c; | ||
| 299 | |||
| 300 | DEC_BOTH (pos, pos_byte); | ||
| 301 | c = FETCH_BYTE (pos_byte); | ||
| 302 | if (c == '\t' || c == '\n') | ||
| 303 | { | ||
| 304 | deleted_special = 1; | ||
| 305 | break; | ||
| 306 | } | ||
| 307 | } | ||
| 308 | |||
| 309 | /* In overwrite mode, back over columns while clearing them out, | ||
| 310 | unless at end of line. */ | ||
| 311 | if (XINT (n) > 0 | ||
| 312 | && ! NILP (current_buffer->overwrite_mode) | ||
| 313 | && ! deleted_special | ||
| 314 | && ! (PT == ZV || FETCH_BYTE (PT_BYTE) == '\n')) | ||
| 315 | { | ||
| 316 | int column = (int) current_column (); /* iftc */ | ||
| 317 | |||
| 318 | value = Fdelete_char (make_number (-XINT (n)), killflag); | ||
| 319 | i = column - (int) current_column (); /* iftc */ | ||
| 320 | Finsert_char (make_number (' '), make_number (i), Qnil); | ||
| 321 | /* Whitespace chars are ASCII chars, so we can simply subtract. */ | ||
| 322 | SET_PT_BOTH (PT - i, PT_BYTE - i); | ||
| 323 | } | ||
| 324 | else | ||
| 325 | value = Fdelete_char (make_number (-XINT (n)), killflag); | ||
| 326 | |||
| 327 | return value; | ||
| 328 | } | ||
| 329 | |||
| 330 | static int nonundocount; | 265 | static int nonundocount; |
| 331 | 266 | ||
| 332 | /* Note that there's code in command_loop_1 which typically avoids | 267 | /* Note that there's code in command_loop_1 which typically avoids |
| @@ -338,8 +273,7 @@ Before insertion, `expand-abbrev' is executed if the inserted character does | |||
| 338 | not have word syntax and the previous character in the buffer does. | 273 | not have word syntax and the previous character in the buffer does. |
| 339 | After insertion, the value of `auto-fill-function' is called if the | 274 | After insertion, the value of `auto-fill-function' is called if the |
| 340 | `auto-fill-chars' table has a non-nil value for the inserted character. */) | 275 | `auto-fill-chars' table has a non-nil value for the inserted character. */) |
| 341 | (n) | 276 | (Lisp_Object n) |
| 342 | Lisp_Object n; | ||
| 343 | { | 277 | { |
| 344 | int remove_boundary = 1; | 278 | int remove_boundary = 1; |
| 345 | CHECK_NUMBER (n); | 279 | CHECK_NUMBER (n); |
| @@ -406,11 +340,10 @@ After insertion, the value of `auto-fill-function' is called if the | |||
| 406 | A value of 2 means this did things that call for an undo boundary. */ | 340 | A value of 2 means this did things that call for an undo boundary. */ |
| 407 | 341 | ||
| 408 | static Lisp_Object Qexpand_abbrev; | 342 | static Lisp_Object Qexpand_abbrev; |
| 343 | static Lisp_Object Qpost_self_insert_hook, Vpost_self_insert_hook; | ||
| 409 | 344 | ||
| 410 | int | 345 | static int |
| 411 | internal_self_insert (c, noautofill) | 346 | internal_self_insert (int c, int noautofill) |
| 412 | int c; | ||
| 413 | int noautofill; | ||
| 414 | { | 347 | { |
| 415 | int hairy = 0; | 348 | int hairy = 0; |
| 416 | Lisp_Object tem; | 349 | Lisp_Object tem; |
| @@ -513,10 +446,10 @@ internal_self_insert (c, noautofill) | |||
| 513 | && synt != Sword | 446 | && synt != Sword |
| 514 | && NILP (current_buffer->read_only) | 447 | && NILP (current_buffer->read_only) |
| 515 | && PT > BEGV | 448 | && PT > BEGV |
| 516 | && (!NILP (current_buffer->enable_multibyte_characters) | 449 | && (SYNTAX (!NILP (current_buffer->enable_multibyte_characters) |
| 517 | ? SYNTAX (XFASTINT (Fprevious_char ())) == Sword | 450 | ? XFASTINT (Fprevious_char ()) |
| 518 | : (SYNTAX (UNIBYTE_TO_CHAR (XFASTINT (Fprevious_char ()))) | 451 | : UNIBYTE_TO_CHAR (XFASTINT (Fprevious_char ()))) |
| 519 | == Sword))) | 452 | == Sword)) |
| 520 | { | 453 | { |
| 521 | int modiff = MODIFF; | 454 | int modiff = MODIFF; |
| 522 | Lisp_Object sym; | 455 | Lisp_Object sym; |
| @@ -576,15 +509,6 @@ internal_self_insert (c, noautofill) | |||
| 576 | hairy = 2; | 509 | hairy = 2; |
| 577 | } | 510 | } |
| 578 | 511 | ||
| 579 | /* If previous command specified a face to use, use it. */ | ||
| 580 | if (!NILP (Vself_insert_face) | ||
| 581 | && EQ (current_kboard->Vlast_command, Vself_insert_face_command)) | ||
| 582 | { | ||
| 583 | Fput_text_property (make_number (PT - 1), make_number (PT), | ||
| 584 | Qface, Vself_insert_face, Qnil); | ||
| 585 | Vself_insert_face = Qnil; | ||
| 586 | } | ||
| 587 | |||
| 588 | if ((synt == Sclose || synt == Smath) | 512 | if ((synt == Sclose || synt == Smath) |
| 589 | && !NILP (Vblink_paren_function) && INTERACTIVE | 513 | && !NILP (Vblink_paren_function) && INTERACTIVE |
| 590 | && !noautofill) | 514 | && !noautofill) |
| @@ -592,13 +516,16 @@ internal_self_insert (c, noautofill) | |||
| 592 | call0 (Vblink_paren_function); | 516 | call0 (Vblink_paren_function); |
| 593 | hairy = 2; | 517 | hairy = 2; |
| 594 | } | 518 | } |
| 519 | /* Run hooks for electric keys. */ | ||
| 520 | call1 (Vrun_hooks, Qpost_self_insert_hook); | ||
| 521 | |||
| 595 | return hairy; | 522 | return hairy; |
| 596 | } | 523 | } |
| 597 | 524 | ||
| 598 | /* module initialization */ | 525 | /* module initialization */ |
| 599 | 526 | ||
| 600 | void | 527 | void |
| 601 | syms_of_cmds () | 528 | syms_of_cmds (void) |
| 602 | { | 529 | { |
| 603 | Qkill_backward_chars = intern_c_string ("kill-backward-chars"); | 530 | Qkill_backward_chars = intern_c_string ("kill-backward-chars"); |
| 604 | staticpro (&Qkill_backward_chars); | 531 | staticpro (&Qkill_backward_chars); |
| @@ -612,15 +539,13 @@ syms_of_cmds () | |||
| 612 | Qexpand_abbrev = intern_c_string ("expand-abbrev"); | 539 | Qexpand_abbrev = intern_c_string ("expand-abbrev"); |
| 613 | staticpro (&Qexpand_abbrev); | 540 | staticpro (&Qexpand_abbrev); |
| 614 | 541 | ||
| 615 | DEFVAR_LISP ("self-insert-face", &Vself_insert_face, | 542 | Qpost_self_insert_hook = intern_c_string ("post-self-insert-hook"); |
| 616 | doc: /* If non-nil, set the face of the next self-inserting character to this. | 543 | staticpro (&Qpost_self_insert_hook); |
| 617 | See also `self-insert-face-command'. */); | ||
| 618 | Vself_insert_face = Qnil; | ||
| 619 | 544 | ||
| 620 | DEFVAR_LISP ("self-insert-face-command", &Vself_insert_face_command, | 545 | DEFVAR_LISP ("post-self-insert-hook", &Vpost_self_insert_hook, |
| 621 | doc: /* This is the command that set up `self-insert-face'. | 546 | doc: /* Hook run at the end of `self-insert-command'. |
| 622 | If `last-command' does not equal this value, we ignore `self-insert-face'. */); | 547 | This run is run after inserting the charater. */); |
| 623 | Vself_insert_face_command = Qnil; | 548 | Vpost_self_insert_hook = Qnil; |
| 624 | 549 | ||
| 625 | DEFVAR_LISP ("blink-paren-function", &Vblink_paren_function, | 550 | DEFVAR_LISP ("blink-paren-function", &Vblink_paren_function, |
| 626 | doc: /* Function called, if non-nil, whenever a close parenthesis is inserted. | 551 | doc: /* Function called, if non-nil, whenever a close parenthesis is inserted. |
| @@ -635,13 +560,11 @@ More precisely, a char with closeparen syntax is self-inserted. */); | |||
| 635 | defsubr (&Send_of_line); | 560 | defsubr (&Send_of_line); |
| 636 | 561 | ||
| 637 | defsubr (&Sdelete_char); | 562 | defsubr (&Sdelete_char); |
| 638 | defsubr (&Sdelete_backward_char); | ||
| 639 | |||
| 640 | defsubr (&Sself_insert_command); | 563 | defsubr (&Sself_insert_command); |
| 641 | } | 564 | } |
| 642 | 565 | ||
| 643 | void | 566 | void |
| 644 | keys_of_cmds () | 567 | keys_of_cmds (void) |
| 645 | { | 568 | { |
| 646 | int n; | 569 | int n; |
| 647 | 570 | ||
| @@ -658,10 +581,8 @@ keys_of_cmds () | |||
| 658 | 581 | ||
| 659 | initial_define_key (global_map, Ctl ('A'), "beginning-of-line"); | 582 | initial_define_key (global_map, Ctl ('A'), "beginning-of-line"); |
| 660 | initial_define_key (global_map, Ctl ('B'), "backward-char"); | 583 | initial_define_key (global_map, Ctl ('B'), "backward-char"); |
| 661 | initial_define_key (global_map, Ctl ('D'), "delete-char"); | ||
| 662 | initial_define_key (global_map, Ctl ('E'), "end-of-line"); | 584 | initial_define_key (global_map, Ctl ('E'), "end-of-line"); |
| 663 | initial_define_key (global_map, Ctl ('F'), "forward-char"); | 585 | initial_define_key (global_map, Ctl ('F'), "forward-char"); |
| 664 | initial_define_key (global_map, 0177, "delete-backward-char"); | ||
| 665 | } | 586 | } |
| 666 | 587 | ||
| 667 | /* arch-tag: 022ba3cd-67f9-4978-9c5d-7d2b18d8644e | 588 | /* arch-tag: 022ba3cd-67f9-4978-9c5d-7d2b18d8644e |