{
register struct Lisp_Marker *m = XMARKER (marker);
- if (m->bytepos >= prev_to_byte)
+ if (m->bytepos >= prev_to_byte
+ && (old_bytes != 0
+ /* If this is an insertion (replacing 0 chars),
+ reject the case of a marker that is at the
+ insertion point and should stay before the insertion. */
+ || m->bytepos > from_byte || m->insertion_type))
{
if (m->bytepos < prev_to_byte + combined_after_bytes)
{
unsigned char workbuf[4], *str;
int len;
- if ((c >= 0240 || !NILP (Vnonascii_translation_table)) && c < 0400)
+ if (c < 0400
+ && (c >= 0240
+ || (c >= 0200 && !NILP (Vnonascii_translation_table))))
{
c = unibyte_char_to_multibyte (c);
len = CHAR_STRING (c, workbuf, str);
{
unsigned int c = *ptr++;
- if (c < 0240 && NILP (Vnonascii_translation_table))
+ if (c < 0200 || (c < 0240 && NILP (Vnonascii_translation_table)))
outgoing_nbytes++;
else
{
void
byte_combining_error ()
{
- error ("Byte combining across region boundary inhibitted");
+ error ("Byte combining across boundary of accessible buffer text inhibitted");
}
/* If we are going to combine bytes at POS which is at a narrowed
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;
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))
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));
to_byte = CHAR_TO_BYTE (to);
del_range_2 (from, from_byte, to, to_byte);
+ signal_after_change (from, to - from, 0);
}
/* Like del_range_1 but args are byte positions, not char positions. */
}
del_range_2 (from, from_byte, to, to_byte);
+ signal_after_change (from, to - from, 0);
}
/* Like del_range_1, but positions are specified both as charpos
}
del_range_2 (from, from_byte, to, to_byte);
+ signal_after_change (from, to - from, 0);
}
/* Delete a range of text, specified both as character positions
CHECK_MARKERS ();
evaporate_overlays (from);
- signal_after_change (from, nchars_del, 0);
}
\f
/* Call this if you're about to change the region of BUFFER from
"This function is for use internally in `combine-after-change-calls'.")
()
{
- register Lisp_Object val;
int count = specpdl_ptr - specpdl;
int beg, end, change;
int begpos, endpos;
Lisp_Object tail;
+ if (NILP (combine_after_change_list))
+ return Qnil;
+
record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
Fset_buffer (combine_after_change_buffer);
Vcombine_after_change_calls);
signal_after_change (begpos, endpos - begpos - change, endpos - begpos);
- return unbind_to (count, val);
+ return unbind_to (count, Qnil);
}
\f
void
{
staticpro (&combine_after_change_list);
combine_after_change_list = Qnil;
+ combine_after_change_buffer = Qnil;
DEFVAR_BOOL ("check-markers-debug-flag", &check_markers_debug_flag,
"Non-nil means enable debugging checks for invalid marker positions.");