diff options
| author | Richard M. Stallman | 1998-01-01 02:42:48 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-01-01 02:42:48 +0000 |
| commit | 049749e656cd39de872599afbd1b41e5b26ba886 (patch) | |
| tree | 921829d7cf50c1698ee34c3e33ab786a99478db6 /src/cmds.c | |
| parent | ac98710ceff486bf36c5872ddaedee1b81f8a220 (diff) | |
| download | emacs-049749e656cd39de872599afbd1b41e5b26ba886.tar.gz emacs-049749e656cd39de872599afbd1b41e5b26ba886.zip | |
(forward_point): Function deleted.
(Fforward_point): Just add.
(Fforward_char): Don't call forward_point, just add.
(Fforward_line): Use scan_newline.
(Fdelete_char): No need for forward_point, just add.
(Fdelete_backward_char): Handle bytes and chars.
(internal_self_insert): Handle bytes and chars.
Diffstat (limited to 'src/cmds.c')
| -rw-r--r-- | src/cmds.c | 110 |
1 files changed, 47 insertions, 63 deletions
diff --git a/src/cmds.c b/src/cmds.c index 70dfbceb7f0..11e484921b6 100644 --- a/src/cmds.c +++ b/src/cmds.c | |||
| @@ -44,35 +44,6 @@ int nonascii_insert_offset; | |||
| 44 | 44 | ||
| 45 | extern Lisp_Object Qface; | 45 | extern Lisp_Object Qface; |
| 46 | 46 | ||
| 47 | /* Return buffer position which is N characters after `point'. */ | ||
| 48 | int | ||
| 49 | forward_point (n) | ||
| 50 | int n; | ||
| 51 | { | ||
| 52 | int pos = PT, c; | ||
| 53 | |||
| 54 | if (!NILP (current_buffer->enable_multibyte_characters)) | ||
| 55 | { | ||
| 56 | /* Simply adding N to `point' doesn't work because of multi-byte | ||
| 57 | form. We had better not use INC_POS and DEC_POS because they | ||
| 58 | check the gap position every time. But, for the moment, we | ||
| 59 | need working code. */ | ||
| 60 | if (n > 0) | ||
| 61 | { | ||
| 62 | while (pos < ZV && n--) INC_POS (pos); | ||
| 63 | if (pos < ZV) n++; | ||
| 64 | } | ||
| 65 | else | ||
| 66 | { | ||
| 67 | while (pos > BEGV && n++) DEC_POS (pos); | ||
| 68 | if (pos > BEGV) n--; | ||
| 69 | } | ||
| 70 | } | ||
| 71 | pos += n; | ||
| 72 | |||
| 73 | return pos; | ||
| 74 | } | ||
| 75 | |||
| 76 | DEFUN ("forward-point", Fforward_point, Sforward_point, 1, 1, 0, | 47 | DEFUN ("forward-point", Fforward_point, Sforward_point, 1, 1, 0, |
| 77 | "Return buffer position N characters after (before if N negative) point.") | 48 | "Return buffer position N characters after (before if N negative) point.") |
| 78 | (n) | 49 | (n) |
| @@ -80,7 +51,7 @@ DEFUN ("forward-point", Fforward_point, Sforward_point, 1, 1, 0, | |||
| 80 | { | 51 | { |
| 81 | CHECK_NUMBER (n, 0); | 52 | CHECK_NUMBER (n, 0); |
| 82 | 53 | ||
| 83 | return make_number (forward_point (XINT (n))); | 54 | return make_number (PT + XINT (n)); |
| 84 | } | 55 | } |
| 85 | 56 | ||
| 86 | DEFUN ("forward-char", Fforward_char, Sforward_char, 0, 1, "p", | 57 | DEFUN ("forward-char", Fforward_char, Sforward_char, 0, 1, "p", |
| @@ -100,7 +71,7 @@ On reaching end of buffer, stop and signal error.") | |||
| 100 | hooks, etcetera), that's not a good approach. So we validate the | 71 | hooks, etcetera), that's not a good approach. So we validate the |
| 101 | proposed position, then set point. */ | 72 | proposed position, then set point. */ |
| 102 | { | 73 | { |
| 103 | int new_point = forward_point (XINT (n)); | 74 | int new_point = PT + XINT (n); |
| 104 | 75 | ||
| 105 | if (new_point < BEGV) | 76 | if (new_point < BEGV) |
| 106 | { | 77 | { |
| @@ -145,9 +116,10 @@ With positive N, a non-empty line at the end counts as one line\n\ | |||
| 145 | (n) | 116 | (n) |
| 146 | Lisp_Object n; | 117 | Lisp_Object n; |
| 147 | { | 118 | { |
| 148 | int pos2 = PT; | 119 | int opoint = PT, opoint_byte = PT_BYTE; |
| 149 | int pos; | 120 | int pos, pos_byte; |
| 150 | int count, shortage, negp; | 121 | int count, shortage; |
| 122 | int temp; | ||
| 151 | 123 | ||
| 152 | if (NILP (n)) | 124 | if (NILP (n)) |
| 153 | count = 1; | 125 | count = 1; |
| @@ -157,16 +129,27 @@ With positive N, a non-empty line at the end counts as one line\n\ | |||
| 157 | count = XINT (n); | 129 | count = XINT (n); |
| 158 | } | 130 | } |
| 159 | 131 | ||
| 160 | negp = count <= 0; | 132 | if (count <= 0) |
| 161 | pos = scan_buffer ('\n', pos2, 0, count - negp, &shortage, 1); | 133 | shortage = scan_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, count - 1, 1); |
| 134 | else | ||
| 135 | shortage = scan_newline (PT, PT_BYTE, ZV, ZV_BYTE, count, 1); | ||
| 136 | |||
| 137 | /* Since scan_newline does TEMP_SET_PT_BOTH, | ||
| 138 | and we want to set PT "for real", | ||
| 139 | go back to the old point and then come back here. */ | ||
| 140 | pos = PT; | ||
| 141 | pos_byte = PT_BYTE; | ||
| 142 | TEMP_SET_PT_BOTH (opoint, opoint_byte); | ||
| 143 | SET_PT_BOTH (pos, pos_byte); | ||
| 144 | |||
| 162 | if (shortage > 0 | 145 | if (shortage > 0 |
| 163 | && (negp | 146 | && (count <= 0 |
| 164 | || (ZV > BEGV | 147 | || (ZV > BEGV |
| 165 | && pos != pos2 | 148 | && PT != opoint |
| 166 | && FETCH_BYTE (pos - 1) != '\n'))) | 149 | && (FETCH_BYTE (PT_BYTE - 1) != '\n')))) |
| 167 | shortage--; | 150 | shortage--; |
| 168 | SET_PT (pos); | 151 | |
| 169 | return make_number (negp ? - shortage : shortage); | 152 | return make_number (count <= 0 ? - shortage : shortage); |
| 170 | } | 153 | } |
| 171 | 154 | ||
| 172 | DEFUN ("beginning-of-line", Fbeginning_of_line, Sbeginning_of_line, | 155 | DEFUN ("beginning-of-line", Fbeginning_of_line, Sbeginning_of_line, |
| @@ -219,7 +202,7 @@ N was explicitly specified.") | |||
| 219 | 202 | ||
| 220 | CHECK_NUMBER (n, 0); | 203 | CHECK_NUMBER (n, 0); |
| 221 | 204 | ||
| 222 | pos = forward_point (XINT (n)); | 205 | pos = PT + XINT (n); |
| 223 | if (NILP (killflag)) | 206 | if (NILP (killflag)) |
| 224 | { | 207 | { |
| 225 | if (XINT (n) < 0) | 208 | if (XINT (n) < 0) |
| @@ -260,8 +243,8 @@ N was explicitly specified.") | |||
| 260 | CHECK_NUMBER (n, 0); | 243 | CHECK_NUMBER (n, 0); |
| 261 | 244 | ||
| 262 | /* See if we are about to delete a tab or newline backwards. */ | 245 | /* See if we are about to delete a tab or newline backwards. */ |
| 263 | pos = PT; | 246 | pos = PT_BYTE; |
| 264 | for (i = 0; i < XINT (n) && pos > BEGV; i++) | 247 | for (i = 0; i < XINT (n) && pos > BEGV_BYTE; i++) |
| 265 | { | 248 | { |
| 266 | int c; | 249 | int c; |
| 267 | 250 | ||
| @@ -279,14 +262,15 @@ N was explicitly specified.") | |||
| 279 | if (XINT (n) > 0 | 262 | if (XINT (n) > 0 |
| 280 | && ! NILP (current_buffer->overwrite_mode) | 263 | && ! NILP (current_buffer->overwrite_mode) |
| 281 | && ! deleted_special | 264 | && ! deleted_special |
| 282 | && ! (PT == ZV || FETCH_BYTE (PT) == '\n')) | 265 | && ! (PT == ZV || FETCH_BYTE (PT_BYTE) == '\n')) |
| 283 | { | 266 | { |
| 284 | int column = current_column (); | 267 | int column = current_column (); |
| 285 | 268 | ||
| 286 | value = Fdelete_char (make_number (-XINT (n)), killflag); | 269 | value = Fdelete_char (make_number (-XINT (n)), killflag); |
| 287 | i = column - current_column (); | 270 | i = column - current_column (); |
| 288 | Finsert_char (make_number (' '), make_number (i), Qnil); | 271 | Finsert_char (make_number (' '), make_number (i), Qnil); |
| 289 | SET_PT (PT - i); | 272 | /* Whitespace chars are ASCII chars, so we can simply subtract. */ |
| 273 | SET_PT_BOTH (PT - i, PT_BYTE - i); | ||
| 290 | } | 274 | } |
| 291 | else | 275 | else |
| 292 | value = Fdelete_char (make_number (-XINT (n)), killflag); | 276 | value = Fdelete_char (make_number (-XINT (n)), killflag); |
| @@ -358,7 +342,7 @@ internal_self_insert (c, noautofill) | |||
| 358 | int len; | 342 | int len; |
| 359 | /* Working buffer and pointer for multi-byte form of C. */ | 343 | /* Working buffer and pointer for multi-byte form of C. */ |
| 360 | unsigned char workbuf[4], *str; | 344 | unsigned char workbuf[4], *str; |
| 361 | int number_to_delete = 0; | 345 | int chars_to_delete = 0; |
| 362 | int spaces_to_insert = 0; | 346 | int spaces_to_insert = 0; |
| 363 | 347 | ||
| 364 | if (c >= 0200 && c <= 0377 | 348 | if (c >= 0200 && c <= 0377 |
| @@ -391,7 +375,7 @@ internal_self_insert (c, noautofill) | |||
| 391 | /* A code at `point'. Since this is checked only against | 375 | /* A code at `point'. Since this is checked only against |
| 392 | NEWLINE and TAB, we don't need a character code but only the | 376 | NEWLINE and TAB, we don't need a character code but only the |
| 393 | first byte of multi-byte form. */ | 377 | first byte of multi-byte form. */ |
| 394 | unsigned char c2 = FETCH_BYTE (PT); | 378 | unsigned char c2 = FETCH_BYTE (PT_BYTE); |
| 395 | /* A column the cursor should be placed at after this insertion. | 379 | /* A column the cursor should be placed at after this insertion. |
| 396 | The correct value should be calculated only when necessary. */ | 380 | The correct value should be calculated only when necessary. */ |
| 397 | int target_clm = 0; | 381 | int target_clm = 0; |
| @@ -413,9 +397,10 @@ internal_self_insert (c, noautofill) | |||
| 413 | target_clm % XFASTINT (current_buffer->tab_width))))) | 397 | target_clm % XFASTINT (current_buffer->tab_width))))) |
| 414 | { | 398 | { |
| 415 | int pos = PT; | 399 | int pos = PT; |
| 400 | int pos_byte = PT_BYTE; | ||
| 416 | 401 | ||
| 417 | if (target_clm == 0) | 402 | if (target_clm == 0) |
| 418 | number_to_delete = forward_point (1) - PT; | 403 | chars_to_delete = 1; |
| 419 | else | 404 | else |
| 420 | { | 405 | { |
| 421 | /* The actual cursor position after the trial of moving | 406 | /* The actual cursor position after the trial of moving |
| @@ -426,7 +411,7 @@ internal_self_insert (c, noautofill) | |||
| 426 | int actual_clm | 411 | int actual_clm |
| 427 | = XFASTINT (Fmove_to_column (make_number (target_clm), Qnil)); | 412 | = XFASTINT (Fmove_to_column (make_number (target_clm), Qnil)); |
| 428 | 413 | ||
| 429 | number_to_delete = PT - pos; | 414 | chars_to_delete = PT - pos; |
| 430 | 415 | ||
| 431 | if (actual_clm > target_clm) | 416 | if (actual_clm > target_clm) |
| 432 | { | 417 | { |
| @@ -435,7 +420,7 @@ internal_self_insert (c, noautofill) | |||
| 435 | spaces_to_insert = actual_clm - target_clm; | 420 | spaces_to_insert = actual_clm - target_clm; |
| 436 | } | 421 | } |
| 437 | } | 422 | } |
| 438 | SET_PT (pos); | 423 | SET_PT_BOTH (pos, pos_byte); |
| 439 | hairy = 2; | 424 | hairy = 2; |
| 440 | } | 425 | } |
| 441 | hairy = 2; | 426 | hairy = 2; |
| @@ -466,7 +451,7 @@ internal_self_insert (c, noautofill) | |||
| 466 | hairy = 2; | 451 | hairy = 2; |
| 467 | } | 452 | } |
| 468 | 453 | ||
| 469 | if (number_to_delete) | 454 | if (chars_to_delete) |
| 470 | { | 455 | { |
| 471 | string = make_string (str, len); | 456 | string = make_string (str, len); |
| 472 | if (spaces_to_insert) | 457 | if (spaces_to_insert) |
| @@ -476,8 +461,9 @@ internal_self_insert (c, noautofill) | |||
| 476 | string = concat2 (tem, string); | 461 | string = concat2 (tem, string); |
| 477 | } | 462 | } |
| 478 | 463 | ||
| 479 | replace_range (PT, PT + number_to_delete, string, 1, 1); | 464 | replace_range (PT, PT + chars_to_delete, string, 1, 1); |
| 480 | SET_PT (PT + XSTRING (string)->size); | 465 | SET_PT_BOTH (PT + 1 + spaces_to_insert, |
| 466 | PT_BYTE + XSTRING (string)->size); | ||
| 481 | } | 467 | } |
| 482 | else | 468 | else |
| 483 | insert_and_inherit (str, len); | 469 | insert_and_inherit (str, len); |
| @@ -489,13 +475,13 @@ internal_self_insert (c, noautofill) | |||
| 489 | Lisp_Object tem; | 475 | Lisp_Object tem; |
| 490 | 476 | ||
| 491 | if (c == '\n') | 477 | if (c == '\n') |
| 492 | /* After inserting a newline, move to previous line and fill */ | 478 | /* After inserting a newline, move to previous line and fill |
| 493 | /* that. Must have the newline in place already so filling and */ | 479 | that. Must have the newline in place already so filling and |
| 494 | /* justification, if any, know where the end is going to be. */ | 480 | justification, if any, know where the end is going to be. */ |
| 495 | SET_PT (PT - 1); | 481 | SET_PT_BOTH (PT - 1, PT_BYTE - 1); |
| 496 | tem = call0 (current_buffer->auto_fill_function); | 482 | tem = call0 (current_buffer->auto_fill_function); |
| 497 | if (c == '\n') | 483 | if (c == '\n') |
| 498 | SET_PT (PT + 1); | 484 | SET_PT_BOTH (PT + 1, PT_BYTE + 1); |
| 499 | if (!NILP (tem)) | 485 | if (!NILP (tem)) |
| 500 | hairy = 2; | 486 | hairy = 2; |
| 501 | } | 487 | } |
| @@ -505,10 +491,8 @@ internal_self_insert (c, noautofill) | |||
| 505 | if (!NILP (Vself_insert_face) | 491 | if (!NILP (Vself_insert_face) |
| 506 | && EQ (current_kboard->Vlast_command, Vself_insert_face_command)) | 492 | && EQ (current_kboard->Vlast_command, Vself_insert_face_command)) |
| 507 | { | 493 | { |
| 508 | Lisp_Object before, after; | 494 | Fput_text_property (make_number (PT - 1), make_number (PT), |
| 509 | XSETINT (before, PT - len); | 495 | Qface, Vself_insert_face, Qnil); |
| 510 | XSETINT (after, PT); | ||
| 511 | Fput_text_property (before, after, Qface, Vself_insert_face, Qnil); | ||
| 512 | Vself_insert_face = Qnil; | 496 | Vself_insert_face = Qnil; |
| 513 | } | 497 | } |
| 514 | #endif | 498 | #endif |