diff options
| author | Karl Heuer | 1994-10-22 04:45:57 +0000 |
|---|---|---|
| committer | Karl Heuer | 1994-10-22 04:45:57 +0000 |
| commit | ef29f21354a97b0dff93100a7153d33bae94e7c9 (patch) | |
| tree | a34a1cf60b5f05d5bfe3e2524ce7ef16cb46ac7f | |
| parent | 579dd4beeb8eda9f2de607fcbd88b582bd5ac1b8 (diff) | |
| download | emacs-ef29f21354a97b0dff93100a7153d33bae94e7c9.tar.gz emacs-ef29f21354a97b0dff93100a7153d33bae94e7c9.zip | |
(insert_from_buffer, insert_from_buffer_1): New functions.
| -rw-r--r-- | src/insdel.c | 76 |
1 files changed, 74 insertions, 2 deletions
diff --git a/src/insdel.c b/src/insdel.c index 2c17f4aa6f8..7b1e6b124b0 100644 --- a/src/insdel.c +++ b/src/insdel.c | |||
| @@ -27,6 +27,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |||
| 27 | 27 | ||
| 28 | static void insert_1 (); | 28 | static void insert_1 (); |
| 29 | static void insert_from_string_1 (); | 29 | static void insert_from_string_1 (); |
| 30 | static void insert_from_buffer_1 (); | ||
| 30 | static void gap_left (); | 31 | static void gap_left (); |
| 31 | static void gap_right (); | 32 | static void gap_right (); |
| 32 | static void adjust_markers (); | 33 | static void adjust_markers (); |
| @@ -305,8 +306,8 @@ make_gap (increment) | |||
| 305 | } | 306 | } |
| 306 | 307 | ||
| 307 | /* Insert a string of specified length before point. | 308 | /* Insert a string of specified length before point. |
| 308 | DO NOT use this for the contents of a Lisp string! | 309 | DO NOT use this for the contents of a Lisp string or a Lisp buffer! |
| 309 | prepare_to_modify_buffer could relocate the string. */ | 310 | prepare_to_modify_buffer could relocate the text. */ |
| 310 | 311 | ||
| 311 | insert (string, length) | 312 | insert (string, length) |
| 312 | register unsigned char *string; | 313 | register unsigned char *string; |
| @@ -438,6 +439,77 @@ insert_from_string_1 (string, pos, length, inherit) | |||
| 438 | adjust_point (length); | 439 | adjust_point (length); |
| 439 | } | 440 | } |
| 440 | 441 | ||
| 442 | /* Insert text from BUF, starting at POS and having length LENGTH, into the | ||
| 443 | current buffer. If the text in BUF has properties, they are absorbed | ||
| 444 | into the current buffer. | ||
| 445 | |||
| 446 | It does not work to use `insert' for this, because a malloc could happen | ||
| 447 | and relocate BUF's text before the bcopy happens. */ | ||
| 448 | |||
| 449 | void | ||
| 450 | insert_from_buffer (buf, pos, length, inherit) | ||
| 451 | struct buffer *buf; | ||
| 452 | int pos, length; | ||
| 453 | int inherit; | ||
| 454 | { | ||
| 455 | if (length > 0) | ||
| 456 | { | ||
| 457 | insert_from_buffer_1 (buf, pos, length, inherit); | ||
| 458 | signal_after_change (PT-length, 0, length); | ||
| 459 | } | ||
| 460 | } | ||
| 461 | |||
| 462 | static void | ||
| 463 | insert_from_buffer_1 (buf, pos, length, inherit) | ||
| 464 | struct buffer *buf; | ||
| 465 | int pos, length; | ||
| 466 | int inherit; | ||
| 467 | { | ||
| 468 | register Lisp_Object temp; | ||
| 469 | int chunk; | ||
| 470 | |||
| 471 | /* Make sure point-max won't overflow after this insertion. */ | ||
| 472 | XSETINT (temp, length + Z); | ||
| 473 | if (length + Z != XINT (temp)) | ||
| 474 | error ("maximum buffer size exceeded"); | ||
| 475 | |||
| 476 | prepare_to_modify_buffer (PT, PT); | ||
| 477 | |||
| 478 | if (PT != GPT) | ||
| 479 | move_gap (PT); | ||
| 480 | if (GAP_SIZE < length) | ||
| 481 | make_gap (length - GAP_SIZE); | ||
| 482 | |||
| 483 | record_insert (PT, length); | ||
| 484 | MODIFF++; | ||
| 485 | |||
| 486 | if (pos < BUF_GPT (buf)) | ||
| 487 | { | ||
| 488 | chunk = min (length, BUF_GPT (buf) - pos); | ||
| 489 | bcopy (BUF_CHAR_ADDRESS (buf, pos), GPT_ADDR, chunk); | ||
| 490 | } | ||
| 491 | else | ||
| 492 | chunk = 0; | ||
| 493 | if (chunk < length) | ||
| 494 | bcopy (BUF_CHAR_ADDRESS (buf, pos + chunk), | ||
| 495 | GPT_ADDR + chunk, length - chunk); | ||
| 496 | |||
| 497 | #ifdef USE_TEXT_PROPERTIES | ||
| 498 | if (current_buffer->intervals != 0) | ||
| 499 | offset_intervals (current_buffer, PT, length); | ||
| 500 | #endif | ||
| 501 | |||
| 502 | GAP_SIZE -= length; | ||
| 503 | GPT += length; | ||
| 504 | ZV += length; | ||
| 505 | Z += length; | ||
| 506 | adjust_point (length); | ||
| 507 | |||
| 508 | /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */ | ||
| 509 | graft_intervals_into_buffer (copy_intervals (buf->intervals, pos, length), | ||
| 510 | PT - length, length, current_buffer, inherit); | ||
| 511 | } | ||
| 512 | |||
| 441 | /* Insert the character C before point */ | 513 | /* Insert the character C before point */ |
| 442 | 514 | ||
| 443 | void | 515 | void |