if (! m->insertion_type)
/* Normal markers will end up at the beginning of the
re-inserted text after undoing a deletion, and must be
- adjusted to move them to the correct place. */
+ adjusted to move them to the correct place. */
record_marker_adjustment (marker, from - charpos);
else if (charpos < to)
/* Before-insertion markers will automatically move forward
/* Make the gap NBYTES_ADDED bytes longer. */
void
-make_gap (nbytes_added)
+make_gap_larger (nbytes_added)
int nbytes_added;
{
Lisp_Object tem;
/* Don't allow a buffer size that won't fit in an int
even if it will fit in a Lisp integer.
- That won't work because so many places use `int'. */
-
- if (Z_BYTE - BEG_BYTE + GAP_SIZE + nbytes_added
- >= MOST_POSITIVE_FIXNUM)
+ That won't work because so many places use `int'.
+
+ Make sure we don't introduce overflows in the calculation. */
+
+ if (Z_BYTE - BEG_BYTE + GAP_SIZE
+ >= (((EMACS_INT) 1 << (min (VALBITS, BITS_PER_INT) - 1)) - 1
+ - nbytes_added))
error ("Buffer exceeds maximum size");
enlarge_buffer_text (current_buffer, nbytes_added);
Vinhibit_quit = tem;
}
+
+
+/* Make the gap NBYTES_REMOVED bytes shorter. */
+
+void
+make_gap_smaller (nbytes_removed)
+ int nbytes_removed;
+{
+ Lisp_Object tem;
+ int real_gap_loc;
+ int real_gap_loc_byte;
+ int real_Z;
+ int real_Z_byte;
+ int real_beg_unchanged;
+ int new_gap_size;
+
+ /* Make sure the gap is at least 20 bytes. */
+ if (GAP_SIZE - nbytes_removed < 20)
+ nbytes_removed = GAP_SIZE - 20;
+
+ /* Prevent quitting in move_gap. */
+ tem = Vinhibit_quit;
+ Vinhibit_quit = Qt;
+
+ real_gap_loc = GPT;
+ real_gap_loc_byte = GPT_BYTE;
+ new_gap_size = GAP_SIZE - nbytes_removed;
+ real_Z = Z;
+ real_Z_byte = Z_BYTE;
+ real_beg_unchanged = BEG_UNCHANGED;
+
+ /* Pretend that the last unwanted part of the gap is the entire gap,
+ and that the first desired part of the gap is part of the buffer
+ text. */
+ bzero (GPT_ADDR, new_gap_size);
+ GPT += new_gap_size;
+ GPT_BYTE += new_gap_size;
+ Z += new_gap_size;
+ Z_BYTE += new_gap_size;
+ GAP_SIZE = nbytes_removed;
+
+ /* Move the unwanted pretend gap to the end of the buffer. This
+ adjusts the markers properly too. */
+ gap_right (Z, Z_BYTE);
+
+ enlarge_buffer_text (current_buffer, -nbytes_removed);
+
+ /* Now restore the desired gap. */
+ GAP_SIZE = new_gap_size;
+ GPT = real_gap_loc;
+ GPT_BYTE = real_gap_loc_byte;
+ Z = real_Z;
+ Z_BYTE = real_Z_byte;
+ BEG_UNCHANGED = real_beg_unchanged;
+
+ /* Put an anchor. */
+ *(Z_ADDR) = 0;
+
+ Vinhibit_quit = tem;
+}
+
+void
+make_gap (nbytes_added)
+ int nbytes_added;
+{
+ if (nbytes_added >= 0)
+ make_gap_larger (nbytes_added);
+#if defined USE_MMAP_FOR_BUFFERS || defined REL_ALLOC || defined DOUG_LEA_MALLOC
+ else
+ make_gap_smaller (-nbytes_added);
+#endif
+}
\f
/* Copy NBYTES bytes of text from FROM_ADDR to TO_ADDR.
FROM_MULTIBYTE says whether the incoming text is multibyte.
int
copy_text (from_addr, to_addr, nbytes,
from_multibyte, to_multibyte)
- unsigned char *from_addr;
+ const unsigned char *from_addr;
unsigned char *to_addr;
int nbytes;
int from_multibyte, to_multibyte;
int
count_size_as_multibyte (ptr, nbytes)
- unsigned char *ptr;
+ const unsigned char *ptr;
int nbytes;
{
int i;
void
insert (string, nbytes)
- register unsigned char *string;
+ register const unsigned char *string;
register int nbytes;
{
if (nbytes > 0)
void
insert_and_inherit (string, nbytes)
- register unsigned char *string;
+ register const unsigned char *string;
register int nbytes;
{
if (nbytes > 0)
void
insert_string (s)
- char *s;
+ const char *s;
{
insert (s, strlen (s));
}
void
insert_before_markers (string, nbytes)
- unsigned char *string;
+ const unsigned char *string;
register int nbytes;
{
if (nbytes > 0)
void
insert_before_markers_and_inherit (string, nbytes)
- unsigned char *string;
+ const unsigned char *string;
register int nbytes;
{
if (nbytes > 0)
void
insert_1 (string, nbytes, inherit, prepare, before_markers)
- register unsigned char *string;
+ register const unsigned char *string;
register int nbytes;
int inherit, prepare, before_markers;
{
int
count_combining_before (string, length, pos, pos_byte)
- unsigned char *string;
+ const unsigned char *string;
int length;
int pos, pos_byte;
{
int len, combining_bytes;
- unsigned char *p;
+ const unsigned char *p;
if (NILP (current_buffer->enable_multibyte_characters))
return 0;
int
count_combining_after (string, length, pos, pos_byte)
- unsigned char *string;
+ const unsigned char *string;
int length;
int pos, pos_byte;
{
void
insert_1_both (string, nchars, nbytes, inherit, prepare, before_markers)
- register unsigned char *string;
+ register const unsigned char *string;
register int nchars, nbytes;
int inherit, prepare, before_markers;
{
if (nchars == 0)
return;
-
+
if (NILP (current_buffer->enable_multibyte_characters))
nchars = nbytes;
if (GPT_BYTE < GPT)
abort ();
+ /* The insert may have been in the unchanged region, so check again. */
+ if (Z - GPT < END_UNCHANGED)
+ END_UNCHANGED = Z - GPT;
+
adjust_overlays_for_insert (PT, nchars);
adjust_markers_for_insert (PT, PT_BYTE,
PT + nchars, PT_BYTE + nbytes,
outgoing_nbytes = nchars;
else if (! STRING_MULTIBYTE (string))
outgoing_nbytes
- = count_size_as_multibyte (&XSTRING (string)->data[pos_byte],
+ = count_size_as_multibyte (SDATA (string) + pos_byte,
nbytes);
GCPRO1 (string);
/* Copy the string text into the buffer, perhaps converting
between single-byte and multibyte. */
- copy_text (XSTRING (string)->data + pos_byte, GPT_ADDR, nbytes,
+ copy_text (SDATA (string) + pos_byte, GPT_ADDR, nbytes,
STRING_MULTIBYTE (string),
! NILP (current_buffer->enable_multibyte_characters));
if (GPT_BYTE < GPT)
abort ();
+ /* The insert may have been in the unchanged region, so check again. */
+ if (Z - GPT < END_UNCHANGED)
+ END_UNCHANGED = Z - GPT;
+
adjust_overlays_for_insert (PT, nchars);
adjust_markers_for_insert (PT, PT_BYTE, PT + nchars,
PT_BYTE + outgoing_nbytes,
offset_intervals (current_buffer, PT, nchars);
- intervals = XSTRING (string)->intervals;
+ intervals = STRING_INTERVALS (string);
/* Get the intervals for the part of the string we are inserting. */
- if (nbytes < STRING_BYTES (XSTRING (string)))
+ if (nbytes < SBYTES (string))
intervals = copy_intervals (intervals, pos, nchars);
-
+
/* Insert those intervals. */
graft_intervals_into_buffer (intervals, PT, nchars,
current_buffer, inherit);
if (chunk < incoming_nbytes)
outgoing_after_gap
- = count_size_as_multibyte (BUF_BYTE_ADDRESS (buf,
+ = 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))
if (GPT_BYTE < GPT)
abort ();
+ /* The insert may have been in the unchanged region, so check again. */
+ if (Z - GPT < END_UNCHANGED)
+ END_UNCHANGED = Z - GPT;
+
adjust_overlays_for_insert (PT, nchars);
adjust_markers_for_insert (PT, PT_BYTE, PT + nchars,
PT_BYTE + outgoing_nbytes,
from += nchars;
intervals = copy_intervals (intervals, from, nchars);
}
-
+
/* Insert those intervals. */
graft_intervals_into_buffer (intervals, PT, nchars, current_buffer, inherit);
if (STRINGP (prev_text))
{
- nchars_del = XSTRING (prev_text)->size;
- nbytes_del = STRING_BYTES (XSTRING (prev_text));
+ nchars_del = SCHARS (prev_text);
+ nbytes_del = SBYTES (prev_text);
}
/* Update various buffer positions for the new text. */
MODIFF++;
}
+/* Like adjust_after_replace, but doesn't require PREV_TEXT.
+ This is for use when undo is not enabled in the current buffer. */
+
+void
+adjust_after_replace_noundo (from, from_byte, nchars_del, nbytes_del, len, len_byte)
+ int from, from_byte, nchars_del, nbytes_del, len, len_byte;
+{
+#ifdef BYTE_COMBINING_DEBUG
+ if (count_combining_before (GPT_ADDR, len_byte, from, from_byte)
+ || count_combining_after (GPT_ADDR, len_byte, from, from_byte))
+ abort ();
+#endif
+
+ /* Update various buffer positions for the new text. */
+ GAP_SIZE -= len_byte;
+ ZV += len; Z+= len;
+ ZV_BYTE += len_byte; Z_BYTE += len_byte;
+ GPT += len; GPT_BYTE += len_byte;
+ if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */
+
+ if (nchars_del > 0)
+ adjust_markers_for_replace (from, from_byte, nchars_del, nbytes_del,
+ len, len_byte);
+ else
+ adjust_markers_for_insert (from, from_byte,
+ from + len, from_byte + len_byte, 0);
+
+ if (len > nchars_del)
+ adjust_overlays_for_insert (from, len - nchars_del);
+ else if (len < nchars_del)
+ adjust_overlays_for_delete (from, nchars_del - len);
+ if (BUF_INTERVALS (current_buffer) != 0)
+ {
+ offset_intervals (current_buffer, from, len - nchars_del);
+ }
+
+ if (from < PT)
+ adjust_point (len - nchars_del, len_byte - nbytes_del);
+
+ /* As byte combining will decrease Z, we must check this again. */
+ if (Z - GPT < END_UNCHANGED)
+ END_UNCHANGED = Z - GPT;
+
+ CHECK_MARKERS ();
+
+ if (len == 0)
+ evaporate_overlays (from);
+ MODIFF++;
+}
+
/* Record undo information, adjust markers and position keepers for an
insertion of a text from FROM (FROM_BYTE) to TO (TO_BYTE). The
text already exists in the current buffer but character length (TO
Lisp_Object new;
int from, to, prepare, inherit, markers;
{
- int inschars = XSTRING (new)->size;
- int insbytes = STRING_BYTES (XSTRING (new));
+ int inschars = SCHARS (new);
+ int insbytes = SBYTES (new);
int from_byte, to_byte;
int nbytes_del, nchars_del;
register Lisp_Object temp;
outgoing_insbytes = inschars;
else if (! STRING_MULTIBYTE (new))
outgoing_insbytes
- = count_size_as_multibyte (XSTRING (new)->data, insbytes);
+ = count_size_as_multibyte (SDATA (new), insbytes);
/* Make sure point-max won't overflow after this insertion. */
XSETINT (temp, Z_BYTE - nbytes_del + insbytes);
/* Copy the string text into the buffer, perhaps converting
between single-byte and multibyte. */
- copy_text (XSTRING (new)->data, GPT_ADDR, insbytes,
+ copy_text (SDATA (new), GPT_ADDR, insbytes,
STRING_MULTIBYTE (new),
! NILP (current_buffer->enable_multibyte_characters));
/* Get the intervals for the part of the string we are inserting--
not including the combined-before bytes. */
- intervals = XSTRING (new)->intervals;
+ intervals = STRING_INTERVALS (new);
/* Insert those intervals. */
graft_intervals_into_buffer (intervals, from, inschars,
current_buffer, inherit);
return;
}
- if (!NILP (combine_after_change_list))
+ if (!NILP (combine_after_change_list))
Fcombine_after_change_execute ();
if (!NILP (Vafter_change_functions))
doc: /* This function is for use internally in `combine-after-change-calls'. */)
()
{
- int count = specpdl_ptr - specpdl;
+ int count = SPECPDL_INDEX ();
int beg, end, change;
int begpos, endpos;
Lisp_Object tail;
that was changed. */
begpos = BEG + beg;
endpos = Z - end;
-
+
/* We are about to handle these, so discard them. */
combine_after_change_list = Qnil;