combined_after_bytes = count_combining_after (string, nbytes, PT, PT_BYTE);
/* This is the net amount that Z will increase from this insertion. */
- adjusted_nchars = nchars - !!combined_before_bytes - !!combined_after_bytes;
+ /* The combined bytes before all count as one character, because
+ they start with a leading code, but the combined bytes after
+ count as separate characters, because they are all trailing codes. */
+
+ adjusted_nchars = nchars - !!combined_before_bytes - combined_after_bytes;
if (prepare)
prepare_to_modify_buffer (PT - !!combined_before_bytes,
- PT + !!combined_after_bytes,
+ PT + combined_after_bytes,
NULL);
/* Record deletion of the surrounding text that combines with
from the buffer and reinsert them. */
if (combined_after_bytes)
- record_delete (PT, 1);
+ record_delete (PT, combined_after_bytes);
if (combined_before_bytes)
record_delete (PT - 1, 1);
#endif
GAP_SIZE -= nbytes;
- GPT += adjusted_nchars;
+ GPT += nchars - !! combined_before_bytes - !!combined_after_bytes;
ZV += adjusted_nchars;
Z += adjusted_nchars;
GPT_BYTE += nbytes;
PT + adjusted_nchars, PT_BYTE + nbytes,
combined_before_bytes, combined_after_bytes,
before_markers);
- adjust_point (adjusted_nchars + !!combined_after_bytes,
+ adjust_point (adjusted_nchars + combined_after_bytes,
nbytes + combined_after_bytes);
if (combined_after_bytes)
PT, PT_BYTE);
/* This is the net amount that Z will increase from this insertion. */
- adjusted_nchars = nchars - !!combined_before_bytes - !!combined_after_bytes;
+ adjusted_nchars = nchars - !!combined_before_bytes - combined_after_bytes;
/* Record deletion of the surrounding text that combines with
the insertion. This, together with recording the insertion,
from the buffer and reinsert them. */
if (combined_after_bytes)
- record_delete (PT, 1);
+ record_delete (PT, combined_after_bytes);
if (combined_before_bytes)
record_delete (PT - 1, 1);
offset_intervals (current_buffer, PT, adjusted_nchars);
GAP_SIZE -= outgoing_nbytes;
- GPT += adjusted_nchars;
+ GPT += nchars - !!combined_before_bytes - !!combined_after_bytes;
ZV += adjusted_nchars;
Z += adjusted_nchars;
GPT_BYTE += outgoing_nbytes;
graft_intervals_into_buffer (XSTRING (string)->intervals, PT, nchars,
current_buffer, inherit);
- adjust_point (adjusted_nchars + !!combined_after_bytes,
+ adjust_point (adjusted_nchars + combined_after_bytes,
outgoing_nbytes + combined_after_bytes);
}
\f
PT, PT_BYTE);
/* This is the net amount that Z will increase from this insertion. */
- adjusted_nchars = nchars - !!combined_before_bytes - !!combined_after_bytes;
+ adjusted_nchars = nchars - !!combined_before_bytes - combined_after_bytes;
/* Record deletion of the surrounding text that combines with
the insertion. This, together with recording the insertion,
from the buffer and reinsert them. */
if (combined_after_bytes)
- record_delete (PT, 1);
+ record_delete (PT, combined_after_bytes);
if (combined_before_bytes)
record_delete (PT - 1, 1);
#endif
GAP_SIZE -= outgoing_nbytes;
- GPT += adjusted_nchars;
+ GPT += nchars - !!combined_before_bytes - !!combined_after_bytes;
ZV += adjusted_nchars;
Z += adjusted_nchars;
GPT_BYTE += outgoing_nbytes;
adjust_markers_for_insert (PT, PT_BYTE, PT + adjusted_nchars,
PT_BYTE + outgoing_nbytes,
combined_before_bytes, combined_after_bytes, 0);
- adjust_point (adjusted_nchars + !!combined_after_bytes,
+ adjust_point (adjusted_nchars + combined_after_bytes,
outgoing_nbytes + combined_after_bytes);
if (combined_after_bytes)
int from, from_byte, to, to_byte, len, len_byte;
int combined_before_bytes, combined_after_bytes;
{
- int adjusted_nchars = len - !!combined_before_bytes - !!combined_after_bytes;
+ int adjusted_nchars = len - !!combined_before_bytes - combined_after_bytes;
record_insert (from - !!combined_before_bytes, len);
if (from < PT)
- adjust_point (len - (to - from) + !!combined_after_bytes,
+ adjust_point (len - (to - from) + combined_after_bytes,
len_byte - (to_byte - from_byte) + combined_after_bytes);
#ifdef USE_TEXT_PROPERTIES
offset_intervals (current_buffer, PT, adjusted_nchars - (to - from));
/* This is the net amount that Z will increase from this insertion. */
adjusted_inschars
- = inschars - !!combined_before_bytes - !!combined_after_bytes;
+ = inschars - !!combined_before_bytes - combined_after_bytes;
/* Record deletion of the surrounding text that combines with
the insertion. This, together with recording the insertion,
from the buffer and reinsert them. */
if (combined_after_bytes)
- record_delete (PT, 1);
+ record_delete (PT, combined_after_bytes);
if (combined_before_bytes)
record_delete (PT - 1, 1);
/* Relocate point as if it were a marker. */
if (from < PT)
adjust_point ((from + adjusted_inschars - (PT < to ? PT : to)
- + !!combined_after_bytes),
+ + combined_after_bytes),
(from_byte + insbytes
- (PT_BYTE < to_byte ? PT_BYTE : to_byte)
+ combined_after_bytes));
#endif
GAP_SIZE -= insbytes;
- GPT += adjusted_inschars;
+ GPT += inschars - !!combined_before_bytes - !!combined_after_bytes;
ZV += adjusted_inschars;
Z += adjusted_inschars;
GPT_BYTE += insbytes;
if (insbytes == 0)
evaporate_overlays (from);
+ if (combined_after_bytes)
+ move_gap_both (GPT + 1, GPT_BYTE + combined_after_bytes);
+
MODIFF++;
UNGCPRO;