Mercurial > emacs
changeset 23850:1a0fa0377fb3
(insert_from_buffer_1): Properly count the size
of output from conversion to multibyte even when input
is split across the gap.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Thu, 10 Dec 1998 03:19:37 +0000 |
parents | 1f014e9d0768 |
children | 6c6028a96f5a |
files | src/insdel.c |
diffstat | 1 files changed, 36 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/src/insdel.c Thu Dec 10 03:17:51 1998 +0000 +++ b/src/insdel.c Thu Dec 10 03:19:37 1998 +0000 @@ -1388,7 +1388,7 @@ int inherit; { register Lisp_Object temp; - int chunk; + int chunk, chunk_expanded; int from_byte = buf_charpos_to_bytepos (buf, from); int to_byte = buf_charpos_to_bytepos (buf, from + nchars); int incoming_nbytes = to_byte - from_byte; @@ -1403,10 +1403,31 @@ if (NILP (current_buffer->enable_multibyte_characters)) outgoing_nbytes = nchars; else if (NILP (buf->enable_multibyte_characters)) - outgoing_nbytes - = count_size_as_multibyte (BUF_BYTE_ADDRESS (buf, from_byte), - incoming_nbytes); - + { + int outgoing_before_gap = 0; + int outgoing_after_gap = 0; + + if (from < BUF_GPT (buf)) + { + chunk = BUF_GPT_BYTE (buf) - from_byte; + if (chunk > incoming_nbytes) + chunk = incoming_nbytes; + outgoing_before_gap + = count_size_as_multibyte (BUF_BYTE_ADDRESS (buf, from_byte), + chunk); + } + else + chunk = 0; + + if (chunk < incoming_nbytes) + outgoing_after_gap + = count_size_as_multibyte (BUF_BYTE_ADDRESS (buf, + from_byte + chunk), + incoming_nbytes - chunk); + + outgoing_nbytes = outgoing_before_gap + outgoing_after_gap; + } + /* Make sure point-max won't overflow after this insertion. */ XSETINT (temp, outgoing_nbytes + Z); if (outgoing_nbytes + Z != XINT (temp)) @@ -1427,16 +1448,20 @@ chunk = BUF_GPT_BYTE (buf) - from_byte; if (chunk > incoming_nbytes) chunk = incoming_nbytes; - copy_text (BUF_BYTE_ADDRESS (buf, from_byte), - GPT_ADDR, chunk, - ! NILP (buf->enable_multibyte_characters), - ! NILP (current_buffer->enable_multibyte_characters)); + /* Record number of output bytes, so we know where + to put the output from the second copy_text. */ + chunk_expanded + = copy_text (BUF_BYTE_ADDRESS (buf, from_byte), + GPT_ADDR, chunk, + ! NILP (buf->enable_multibyte_characters), + ! NILP (current_buffer->enable_multibyte_characters)); } else - chunk = 0; + chunk_expanded = chunk = 0; + if (chunk < incoming_nbytes) copy_text (BUF_BYTE_ADDRESS (buf, from_byte + chunk), - GPT_ADDR + chunk, incoming_nbytes - chunk, + GPT_ADDR + chunk_expanded, incoming_nbytes - chunk, ! NILP (buf->enable_multibyte_characters), ! NILP (current_buffer->enable_multibyte_characters));