aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKarl Heuer1998-12-10 03:19:37 +0000
committerKarl Heuer1998-12-10 03:19:37 +0000
commit4468c4f1cf677d3d68d7af111923e025f16bb948 (patch)
tree2cc71180adc975fbfedaac932fbfa7b34ec6fcba /src
parentf5cdb8516aad771196a6dda456aac9b70d568634 (diff)
downloademacs-4468c4f1cf677d3d68d7af111923e025f16bb948.tar.gz
emacs-4468c4f1cf677d3d68d7af111923e025f16bb948.zip
(insert_from_buffer_1): Properly count the size
of output from conversion to multibyte even when input is split across the gap.
Diffstat (limited to 'src')
-rw-r--r--src/insdel.c45
1 files changed, 35 insertions, 10 deletions
diff --git a/src/insdel.c b/src/insdel.c
index ab7927964de..31fbae441df 100644
--- a/src/insdel.c
+++ b/src/insdel.c
@@ -1388,7 +1388,7 @@ insert_from_buffer_1 (buf, from, nchars, inherit)
1388 int inherit; 1388 int inherit;
1389{ 1389{
1390 register Lisp_Object temp; 1390 register Lisp_Object temp;
1391 int chunk; 1391 int chunk, chunk_expanded;
1392 int from_byte = buf_charpos_to_bytepos (buf, from); 1392 int from_byte = buf_charpos_to_bytepos (buf, from);
1393 int to_byte = buf_charpos_to_bytepos (buf, from + nchars); 1393 int to_byte = buf_charpos_to_bytepos (buf, from + nchars);
1394 int incoming_nbytes = to_byte - from_byte; 1394 int incoming_nbytes = to_byte - from_byte;
@@ -1403,10 +1403,31 @@ insert_from_buffer_1 (buf, from, nchars, inherit)
1403 if (NILP (current_buffer->enable_multibyte_characters)) 1403 if (NILP (current_buffer->enable_multibyte_characters))
1404 outgoing_nbytes = nchars; 1404 outgoing_nbytes = nchars;
1405 else if (NILP (buf->enable_multibyte_characters)) 1405 else if (NILP (buf->enable_multibyte_characters))
1406 outgoing_nbytes 1406 {
1407 = count_size_as_multibyte (BUF_BYTE_ADDRESS (buf, from_byte), 1407 int outgoing_before_gap = 0;
1408 incoming_nbytes); 1408 int outgoing_after_gap = 0;
1409
1410 if (from < BUF_GPT (buf))
1411 {
1412 chunk = BUF_GPT_BYTE (buf) - from_byte;
1413 if (chunk > incoming_nbytes)
1414 chunk = incoming_nbytes;
1415 outgoing_before_gap
1416 = count_size_as_multibyte (BUF_BYTE_ADDRESS (buf, from_byte),
1417 chunk);
1418 }
1419 else
1420 chunk = 0;
1421
1422 if (chunk < incoming_nbytes)
1423 outgoing_after_gap
1424 = count_size_as_multibyte (BUF_BYTE_ADDRESS (buf,
1425 from_byte + chunk),
1426 incoming_nbytes - chunk);
1409 1427
1428 outgoing_nbytes = outgoing_before_gap + outgoing_after_gap;
1429 }
1430
1410 /* Make sure point-max won't overflow after this insertion. */ 1431 /* Make sure point-max won't overflow after this insertion. */
1411 XSETINT (temp, outgoing_nbytes + Z); 1432 XSETINT (temp, outgoing_nbytes + Z);
1412 if (outgoing_nbytes + Z != XINT (temp)) 1433 if (outgoing_nbytes + Z != XINT (temp))
@@ -1427,16 +1448,20 @@ insert_from_buffer_1 (buf, from, nchars, inherit)
1427 chunk = BUF_GPT_BYTE (buf) - from_byte; 1448 chunk = BUF_GPT_BYTE (buf) - from_byte;
1428 if (chunk > incoming_nbytes) 1449 if (chunk > incoming_nbytes)
1429 chunk = incoming_nbytes; 1450 chunk = incoming_nbytes;
1430 copy_text (BUF_BYTE_ADDRESS (buf, from_byte), 1451 /* Record number of output bytes, so we know where
1431 GPT_ADDR, chunk, 1452 to put the output from the second copy_text. */
1432 ! NILP (buf->enable_multibyte_characters), 1453 chunk_expanded
1433 ! NILP (current_buffer->enable_multibyte_characters)); 1454 = copy_text (BUF_BYTE_ADDRESS (buf, from_byte),
1455 GPT_ADDR, chunk,
1456 ! NILP (buf->enable_multibyte_characters),
1457 ! NILP (current_buffer->enable_multibyte_characters));
1434 } 1458 }
1435 else 1459 else
1436 chunk = 0; 1460 chunk_expanded = chunk = 0;
1461
1437 if (chunk < incoming_nbytes) 1462 if (chunk < incoming_nbytes)
1438 copy_text (BUF_BYTE_ADDRESS (buf, from_byte + chunk), 1463 copy_text (BUF_BYTE_ADDRESS (buf, from_byte + chunk),
1439 GPT_ADDR + chunk, incoming_nbytes - chunk, 1464 GPT_ADDR + chunk_expanded, incoming_nbytes - chunk,
1440 ! NILP (buf->enable_multibyte_characters), 1465 ! NILP (buf->enable_multibyte_characters),
1441 ! NILP (current_buffer->enable_multibyte_characters)); 1466 ! NILP (current_buffer->enable_multibyte_characters));
1442 1467