Changeset 1490 for branches/GNU/src/cmds.c
- Timestamp:
- 02/17/98 01:45:05 (11 years ago)
- Files:
-
- branches/GNU/src/cmds.c (modified) (27 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/GNU/src/cmds.c
r1488 r1490 1 1 /* Simple built-in editing commands. 2 Copyright (C) 1985, 93, 94, 95, 96, 97, 1998Free Software Foundation, Inc.2 Copyright (C) 1985, 93, 94, 95, 96, 1997 Free Software Foundation, Inc. 3 3 4 4 This file is part of GNU Emacs. … … 28 28 #include "window.h" 29 29 #include "keyboard.h" 30 #include "dispextern.h"31 30 32 31 Lisp_Object Qkill_forward_chars, Qkill_backward_chars, Vblink_paren_function; … … 41 40 Lisp_Object Vself_insert_face_command; 42 41 42 /* Offset to add to a non-ASCII value when inserting it. */ 43 int nonascii_insert_offset; 44 43 45 extern Lisp_Object Qface; 44 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 45 76 DEFUN ("forward-point", Fforward_point, Sforward_point, 1, 1, 0, 46 77 "Return buffer position N characters after (before if N negative) point.") … … 50 81 CHECK_NUMBER (n, 0); 51 82 52 return make_number ( PT + XINT (n));83 return make_number (forward_point (XINT (n))); 53 84 } 54 85 … … 70 101 proposed position, then set point. */ 71 102 { 72 int new_point = PT + XINT (n);103 int new_point = forward_point (XINT (n)); 73 104 74 105 if (new_point < BEGV) … … 115 146 Lisp_Object n; 116 147 { 117 int opoint = PT, opoint_byte = PT_BYTE; 118 int pos, pos_byte; 119 int count, shortage; 120 int temp; 148 int pos2 = PT; 149 int pos; 150 int count, shortage, negp; 121 151 122 152 if (NILP (n)) … … 128 158 } 129 159 130 if (count <= 0) 131 shortage = scan_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, count - 1, 1); 132 else 133 shortage = scan_newline (PT, PT_BYTE, ZV, ZV_BYTE, count, 1); 134 135 /* Since scan_newline does TEMP_SET_PT_BOTH, 136 and we want to set PT "for real", 137 go back to the old point and then come back here. */ 138 pos = PT; 139 pos_byte = PT_BYTE; 140 TEMP_SET_PT_BOTH (opoint, opoint_byte); 141 SET_PT_BOTH (pos, pos_byte); 142 160 negp = count <= 0; 161 pos = scan_buffer ('\n', pos2, 0, count - negp, &shortage, 1); 143 162 if (shortage > 0 144 && ( count <= 0163 && (negp 145 164 || (ZV > BEGV 146 && PT != opoint147 && (FETCH_BYTE (PT_BYTE - 1) != '\n'))))165 && pos != pos2 166 && FETCH_BYTE (pos - 1) != '\n'))) 148 167 shortage--; 149 150 return make_number ( count <= 0? - shortage : shortage);168 SET_PT (pos); 169 return make_number (negp ? - shortage : shortage); 151 170 } 152 171 … … 201 220 CHECK_NUMBER (n, 0); 202 221 203 pos = PT + XINT (n);222 pos = forward_point (XINT (n)); 204 223 if (NILP (killflag)) 205 224 { … … 237 256 Lisp_Object value; 238 257 int deleted_special = 0; 239 int pos, pos_byte,i;258 int pos, i; 240 259 241 260 CHECK_NUMBER (n, 0); … … 243 262 /* See if we are about to delete a tab or newline backwards. */ 244 263 pos = PT; 245 pos_byte = PT_BYTE; 246 for (i = 0; i < XINT (n) && pos_byte > BEGV_BYTE; i++) 264 for (i = 0; i < XINT (n) && pos > BEGV; i++) 247 265 { 248 266 int c; 249 267 250 DEC_ BOTH (pos, pos_byte);251 c = FETCH_BYTE (pos _byte);268 DEC_POS (pos); 269 c = FETCH_BYTE (pos); 252 270 if (c == '\t' || c == '\n') 253 271 { … … 262 280 && ! NILP (current_buffer->overwrite_mode) 263 281 && ! deleted_special 264 && ! (PT == ZV || FETCH_BYTE (PT _BYTE) == '\n'))282 && ! (PT == ZV || FETCH_BYTE (PT) == '\n')) 265 283 { 266 284 int column = current_column (); … … 269 287 i = column - current_column (); 270 288 Finsert_char (make_number (' '), make_number (i), Qnil); 271 /* Whitespace chars are ASCII chars, so we can simply subtract. */ 272 SET_PT_BOTH (PT - i, PT_BYTE - i); 289 SET_PT (PT - i); 273 290 } 274 291 else … … 297 314 We pass internal_self_insert the unmodified character 298 315 because it itself does this offsetting. */ 299 if (! NILP (current_buffer->enable_multibyte_characters)) 300 modified_char = unibyte_char_to_multibyte (modified_char); 316 if (modified_char >= 0200 && modified_char <= 0377 317 && ! NILP (current_buffer->enable_multibyte_characters)) 318 modified_char += nonascii_insert_offset; 301 319 302 320 XSETFASTINT (n, XFASTINT (n) - 2); … … 328 346 A value of 2 means this did things that call for an undo boundary. */ 329 347 330 int331 348 internal_self_insert (c, noautofill) 332 349 int c; … … 342 359 /* Working buffer and pointer for multi-byte form of C. */ 343 360 unsigned char workbuf[4], *str; 344 int chars_to_delete = 0;361 int number_to_delete = 0; 345 362 int spaces_to_insert = 0; 363 364 if (c >= 0200 && c <= 0377 365 && ! NILP (current_buffer->enable_multibyte_characters)) 366 c += nonascii_insert_offset; 346 367 347 368 overwrite = current_buffer->overwrite_mode; … … 352 373 /* At first, get multi-byte form of C in STR. */ 353 374 if (!NILP (current_buffer->enable_multibyte_characters)) 354 { 355 c = unibyte_char_to_multibyte (c); 356 len = CHAR_STRING (c, workbuf, str); 357 } 358 else 359 { 360 workbuf[0] = (SINGLE_BYTE_CHAR_P (c) 361 ? c 362 : multibyte_char_to_unibyte (c, Qnil)); 363 str = workbuf; 364 len = 1; 365 } 375 len = CHAR_STRING (c, workbuf, str); 376 else 377 workbuf[0] = c, str = workbuf, len = 1; 378 366 379 if (!NILP (overwrite) 367 380 && PT < ZV) … … 376 389 C2 and several characters following C2. */ 377 390 378 /* This is the character after point. */ 379 int c2 = FETCH_CHAR (PT_BYTE); 380 381 /* Column the cursor should be placed at after this insertion. 391 /* A code at `point'. Since this is checked only against 392 NEWLINE and TAB, we don't need a character code but only the 393 first byte of multi-byte form. */ 394 unsigned char c2 = FETCH_BYTE (PT); 395 /* A column the cursor should be placed at after this insertion. 382 396 The correct value should be calculated only when necessary. */ 383 397 int target_clm = 0; … … 394 408 && XINT (current_buffer->tab_width) > 0 395 409 && XFASTINT (current_buffer->tab_width) < 20 396 && (target_clm = (current_column () 397 + XINT (Fchar_width (make_number (c2)))), 410 && ((NILP (current_buffer->enable_multibyte_characters) 411 ? (target_clm = current_column () + 1) 412 : (target_clm = current_column () + WIDTH_BY_CHAR_HEAD (str[0]))), 398 413 target_clm % XFASTINT (current_buffer->tab_width))))) 399 414 { 400 415 int pos = PT; 401 int pos_byte = PT_BYTE;402 416 403 417 if (target_clm == 0) 404 chars_to_delete = 1;418 number_to_delete = forward_point (1) - PT; 405 419 else 406 420 { … … 413 427 = XFASTINT (Fmove_to_column (make_number (target_clm), Qnil)); 414 428 415 chars_to_delete = PT - pos;429 number_to_delete = PT - pos; 416 430 417 431 if (actual_clm > target_clm) … … 422 436 } 423 437 } 424 SET_PT _BOTH (pos, pos_byte);438 SET_PT (pos); 425 439 hairy = 2; 426 440 } … … 453 467 } 454 468 455 if ( chars_to_delete)456 { 457 string = make_string _from_bytes (str, 1, len);469 if (number_to_delete) 470 { 471 string = make_string (str, len); 458 472 if (spaces_to_insert) 459 473 { … … 463 477 } 464 478 465 replace_range (PT, PT + chars_to_delete, string, 1, 1, 1);466 Fforward_char (make_number (1 + spaces_to_insert));479 replace_range (PT, PT + number_to_delete, string, 1, 1); 480 SET_PT (PT + XSTRING (string)->size); 467 481 } 468 482 else … … 476 490 477 491 if (c == '\n') 478 /* After inserting a newline, move to previous line and fill 479 that. Must have the newline in place already so filling and480 justification, if any, know where the end is going to be.*/481 SET_PT _BOTH (PT - 1, PT_BYTE- 1);492 /* After inserting a newline, move to previous line and fill */ 493 /* that. Must have the newline in place already so filling and */ 494 /* justification, if any, know where the end is going to be. */ 495 SET_PT (PT - 1); 482 496 tem = call0 (current_buffer->auto_fill_function); 483 497 if (c == '\n') 484 SET_PT _BOTH (PT + 1, PT_BYTE+ 1);498 SET_PT (PT + 1); 485 499 if (!NILP (tem)) 486 500 hairy = 2; … … 492 506 && EQ (current_kboard->Vlast_command, Vself_insert_face_command)) 493 507 { 494 Fput_text_property (make_number (PT - 1), make_number (PT), 495 Qface, Vself_insert_face, Qnil); 508 Lisp_Object before, after; 509 XSETINT (before, PT - len); 510 XSETINT (after, PT); 511 Fput_text_property (before, after, Qface, Vself_insert_face, Qnil); 496 512 Vself_insert_face = Qnil; 497 513 } … … 511 527 /* module initialization */ 512 528 513 void514 529 syms_of_cmds () 515 530 { … … 537 552 More precisely, a char with closeparen syntax is self-inserted."); 538 553 Vblink_paren_function = Qnil; 554 555 DEFVAR_INT ("nonascii-insert-offset", &nonascii_insert_offset, 556 "Offset to add to a non-ascii code 0200...0377 when inserting it.\n\ 557 This applies only when multibyte characters are enabled, and it serves\n\ 558 to convert a Latin-1 or similar 8-bit character code to the corresponding\n\ 559 Emacs character code."); 560 nonascii_insert_offset = 0; 539 561 540 562 defsubr (&Sforward_point); … … 551 573 } 552 574 553 void554 575 keys_of_cmds () 555 576 {
