the equivalent length in characters. */
Charcount
-bytecount_to_charcount (CONST Bufbyte *ptr, Bytecount len)
+bytecount_to_charcount (const Bufbyte *ptr, Bytecount len)
{
Charcount count = 0;
- CONST Bufbyte *end = ptr + len;
+ const Bufbyte *end = ptr + len;
#if (LONGBITS == 32 || LONGBITS == 64)
/* Determine the section in the middle of the string that's
amenable to this treatment. Everything has to be aligned
on CPU word boundaries. */
- CONST Bufbyte *aligned_ptr =
- (CONST Bufbyte *) (((unsigned long) (ptr + LONG_BYTES - 1)) &
+ const Bufbyte *aligned_ptr =
+ (const Bufbyte *) (((unsigned long) (ptr + LONG_BYTES - 1)) &
ALIGN_MASK);
- CONST Bufbyte *aligned_end =
- (CONST Bufbyte *) (((unsigned long) end) & ALIGN_MASK);
+ const Bufbyte *aligned_end =
+ (const Bufbyte *) (((unsigned long) end) & ALIGN_MASK);
/* Handle unaligned stuff at the beginning. */
while (ptr < aligned_ptr)
the equivalent length in bytes. */
Bytecount
-charcount_to_bytecount (CONST Bufbyte *ptr, Charcount len)
+charcount_to_bytecount (const Bufbyte *ptr, Charcount len)
{
- CONST Bufbyte *newptr = ptr;
+ const Bufbyte *newptr = ptr;
while (len > 0)
{
adjust_markers (struct buffer *buf, Memind from, Memind to,
Bytecount amount)
{
- struct Lisp_Marker *m;
+ Lisp_Marker *m;
for (m = BUF_MARKERS (buf); m; m = marker_next (m))
m->memind = do_marker_adjustment (m->memind, from, to, amount);
static void
adjust_markers_for_insert (struct buffer *buf, Memind ind, Bytecount amount)
{
- struct Lisp_Marker *m;
+ Lisp_Marker *m;
for (m = BUF_MARKERS (buf); m; m = marker_next (m))
{
/* Routines for dealing with the gap */
/************************************************************************/
-/* XEmacs requires an ANSI C compiler, and it damn well better have a
- working memmove() */
-#define GAP_USE_BCOPY
-#ifdef BCOPY_UPWARD_SAFE
-# undef BCOPY_UPWARD_SAFE
-#endif
-#ifdef BCOPY_DOWNWARD_SAFE
-# undef BCOPY_DOWNWARD_SAFE
-#endif
-#define BCOPY_UPWARD_SAFE 1
-#define BCOPY_DOWNWARD_SAFE 1
-
/* maximum amount of memory moved in a single chunk. Increasing this
value improves gap-motion efficiency but decreases QUIT responsiveness
time. Was 32000 but today's processors are faster and files are
/* Move at most GAP_MOVE_CHUNK chars before checking again for a quit. */
if (i > GAP_MOVE_CHUNK)
i = GAP_MOVE_CHUNK;
-#ifdef GAP_USE_BCOPY
- if (i >= 128
- /* bcopy is safe if the two areas of memory do not overlap
- or on systems where bcopy is always safe for moving upward. */
- && (BCOPY_UPWARD_SAFE
- || to - from >= 128))
+
+ if (i >= 128)
{
- /* If overlap is not safe, avoid it by not moving too many
- characters at once. */
- if (!BCOPY_UPWARD_SAFE && i > to - from)
- i = to - from;
new_s1 -= i;
- from -= i, to -= i;
+ from -= i;
+ to -= i;
memmove (to, from, i);
}
else
-#endif
{
new_s1 -= i;
while (--i >= 0)
/* Move at most GAP_MOVE_CHUNK chars before checking again for a quit. */
if (i > GAP_MOVE_CHUNK)
i = GAP_MOVE_CHUNK;
-#ifdef GAP_USE_BCOPY
- if (i >= 128
- /* bcopy is safe if the two areas of memory do not overlap
- or on systems where bcopy is always safe for moving downward. */
- && (BCOPY_DOWNWARD_SAFE
- || from - to >= 128))
+
+ if (i >= 128)
{
- /* If overlap is not safe, avoid it by not moving too many
- characters at once. */
- if (!BCOPY_DOWNWARD_SAFE && i > from - to)
- i = from - to;
new_s1 += i;
memmove (to, from, i);
- from += i, to += i;
+ from += i;
+ to += i;
}
else
-#endif
{
new_s1 += i;
while (--i >= 0)
Bytecount old_gap_size;
/* If we have to get more space, get enough to last a while. We use
- a geometric progession that saves on realloc space. */
+ a geometric progression that saves on realloc space. */
increment += 2000 + ((BI_BUF_Z (buf) - BI_BUF_BEG (buf)) / 8);
if (increment > BUF_END_GAP_SIZE (buf))
of the specified region, that will also be handled correctly.
begin_multiple_change() returns a number (actually a specpdl depth)
- that you must pass to end_multiple_change() when you are done. */
+ that you must pass to end_multiple_change() when you are done.
+
+ FSF Emacs 20 implements a similar feature, accessible from Lisp
+ through a `combine-after-change-calls' special form, which is
+ essentially equivalent to this function. We should consider
+ whether we want to introduce a similar Lisp form. */
int
begin_multiple_change (struct buffer *buf, Bufpos start, Bufpos end)
/* We should first reset the variable and then change the buffer,
because Fset_buffer() can throw. */
inside_change_hook = 0;
- Fset_buffer (buffer);
+ if (XBUFFER (buffer) != current_buffer)
+ Fset_buffer (buffer);
return Qnil;
}
if (!inside_change_hook)
{
Lisp_Object buffer;
+ int speccount;
/* Are we in a multiple-change session? */
if (buf->text->changes->in_multiple_change &&
}
/* Now in any case run the before-change-functions if any. */
+ speccount = specpdl_depth ();
+ record_unwind_protect (change_function_restore, Fcurrent_buffer ());
+ inside_change_hook = 1;
MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
{
/* Obsolete, for compatibility */
|| !NILP (symbol_value_in_buffer (Qbefore_change_function, buffer)))
{
- int speccount = specpdl_depth ();
- record_unwind_protect (change_function_restore, Fcurrent_buffer ());
set_buffer_internal (buf);
- inside_change_hook = 1;
va_run_hook_with_args (Qbefore_change_functions, 2,
make_int (start), make_int (end));
/* Obsolete, for compatibility */
va_run_hook_with_args (Qbefore_change_function, 2,
make_int (start), make_int (end));
- unbind_to (speccount, Qnil);
}
}
+ /* Make sure endpoints remain valid. before-change-functions
+ might have modified the buffer. */
+ if (start < BUF_BEGV (buf)) start = BUF_BEGV (buf);
+ if (start > BUF_ZV (buf)) start = BUF_ZV (buf);
+ if (end < BUF_BEGV (buf)) end = BUF_BEGV (buf);
+ if (end > BUF_ZV (buf)) end = BUF_ZV (buf);
+
MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
{
XSETBUFFER (buffer, mbuf);
- report_extent_modification (buffer, start, end,
- &inside_change_hook, 0);
+ report_extent_modification (buffer, start, end, 0);
}
+ unbind_to (speccount, Qnil);
/* Only now do we indicate that the before-change-functions have
been called, in case some function throws out. */
if (!inside_change_hook)
{
Lisp_Object buffer;
+ int speccount;
if (buf->text->changes->in_multiple_change &&
buf->text->changes->mc_begin != 0)
return; /* after-change-functions signalled when all changes done */
}
+ speccount = specpdl_depth ();
+ record_unwind_protect (change_function_restore, Fcurrent_buffer ());
+ inside_change_hook = 1;
MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
{
XSETBUFFER (buffer, mbuf);
/* Obsolete, for compatibility */
|| !NILP (symbol_value_in_buffer (Qafter_change_function, buffer)))
{
- int speccount = specpdl_depth ();
- record_unwind_protect (change_function_restore, Fcurrent_buffer ());
set_buffer_internal (buf);
- inside_change_hook = 1;
/* The actual after-change functions take slightly
different arguments than what we were passed. */
va_run_hook_with_args (Qafter_change_functions, 3,
va_run_hook_with_args (Qafter_change_function, 3,
make_int (start), make_int (new_end),
make_int (orig_end - start));
- unbind_to (speccount, Qnil);
}
}
+ /* Make sure endpoints remain valid. after-change-functions
+ might have modified the buffer. */
+ if (start < BUF_BEGV (buf)) start = BUF_BEGV (buf);
+ if (start > BUF_ZV (buf)) start = BUF_ZV (buf);
+ if (new_end < BUF_BEGV (buf)) new_end = BUF_BEGV (buf);
+ if (new_end > BUF_ZV (buf)) new_end = BUF_ZV (buf);
+ if (orig_end < BUF_BEGV (buf)) orig_end = BUF_BEGV (buf);
+ if (orig_end > BUF_ZV (buf)) orig_end = BUF_ZV (buf);
+
MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
{
XSETBUFFER (buffer, mbuf);
- report_extent_modification (buffer, start, new_end,
- &inside_change_hook, 1);
+ report_extent_modification (buffer, start, new_end, 1);
}
+ unbind_to (speccount, Qnil); /* sets inside_change_hook back to 0 */
}
}
/************************************************************************/
void
-fixup_internal_substring (CONST Bufbyte *nonreloc, Lisp_Object reloc,
+fixup_internal_substring (const Bufbyte *nonreloc, Lisp_Object reloc,
Bytecount offset, Bytecount *len)
{
assert ((nonreloc && NILP (reloc)) || (!nonreloc && STRINGP (reloc)));
if (*len < 0)
{
if (nonreloc)
- *len = strlen ((CONST char *) nonreloc) - offset;
+ *len = strlen ((const char *) nonreloc) - offset;
else
*len = XSTRING_LENGTH (reloc) - offset;
}
Charcount
buffer_insert_string_1 (struct buffer *buf, Bufpos pos,
- CONST Bufbyte *nonreloc, Lisp_Object reloc,
+ const Bufbyte *nonreloc, Lisp_Object reloc,
Bytecount offset, Bytecount length,
int flags)
{
Charcount
buffer_insert_raw_string_1 (struct buffer *buf, Bufpos pos,
- CONST Bufbyte *nonreloc, Bytecount length,
+ const Bufbyte *nonreloc, Bytecount length,
int flags)
{
/* This function can GC */
/* Insert the null-terminated string S (in external format). */
Charcount
-buffer_insert_c_string_1 (struct buffer *buf, Bufpos pos, CONST char *s,
+buffer_insert_c_string_1 (struct buffer *buf, Bufpos pos, const char *s,
int flags)
{
/* This function can GC */
- CONST char *translated = GETTEXT (s);
- return buffer_insert_string_1 (buf, pos, (CONST Bufbyte *) translated, Qnil,
+ const char *translated = GETTEXT (s);
+ return buffer_insert_string_1 (buf, pos, (const Bufbyte *) translated, Qnil,
0, strlen (translated), flags);
}
/* Make a string from a buffer. This needs to take into account the gap,
and add any necessary extents from the buffer. */
-Lisp_Object
-make_string_from_buffer (struct buffer *buf, Bufpos pos, Charcount length)
+static Lisp_Object
+make_string_from_buffer_1 (struct buffer *buf, Bufpos pos, Charcount length,
+ int no_extents)
{
/* This function can GC */
- Lisp_Object val;
- struct gcpro gcpro1;
- Bytind bi_ind;
- Bytecount bi_len;
+ Bytind bi_ind = bufpos_to_bytind (buf, pos);
+ Bytecount bi_len = bufpos_to_bytind (buf, pos + length) - bi_ind;
+ Lisp_Object val = make_uninit_string (bi_len);
- bi_ind = bufpos_to_bytind (buf, pos);
- bi_len = bufpos_to_bytind (buf, pos + length) - bi_ind;
-
- val = make_uninit_string (bi_len);
+ struct gcpro gcpro1;
GCPRO1 (val);
- add_string_extents (val, buf, bi_ind, bi_len);
+ if (!no_extents)
+ add_string_extents (val, buf, bi_ind, bi_len);
{
Bytecount len1 = BI_BUF_GPT (buf) - bi_ind;
return val;
}
+Lisp_Object
+make_string_from_buffer (struct buffer *buf, Bufpos pos, Charcount length)
+{
+ return make_string_from_buffer_1 (buf, pos, length, 0);
+}
+
+Lisp_Object
+make_string_from_buffer_no_extents (struct buffer *buf, Bufpos pos,
+ Charcount length)
+{
+ return make_string_from_buffer_1 (buf, pos, length, 1);
+}
+
void
barf_if_buffer_read_only (struct buffer *buf, Bufpos from, Bufpos to)
{
}
void
-find_charsets_in_bufbyte_string (unsigned char *charsets, CONST Bufbyte *str,
+find_charsets_in_bufbyte_string (unsigned char *charsets, const Bufbyte *str,
Bytecount len)
{
#ifndef MULE
/* Telescope this. */
charsets[0] = 1;
#else
- CONST Bufbyte *strend = str + len;
+ const Bufbyte *strend = str + len;
memset (charsets, 0, NUM_LEADING_BYTES);
while (str < strend)
}
void
-find_charsets_in_emchar_string (unsigned char *charsets, CONST Emchar *str,
+find_charsets_in_emchar_string (unsigned char *charsets, const Emchar *str,
Charcount len)
{
#ifndef MULE
}
int
-bufbyte_string_displayed_columns (CONST Bufbyte *str, Bytecount len)
+bufbyte_string_displayed_columns (const Bufbyte *str, Bytecount len)
{
int cols = 0;
- CONST Bufbyte *end = str + len;
+ const Bufbyte *end = str + len;
while (str < end)
{
}
int
-emchar_string_displayed_columns (CONST Emchar *str, Charcount len)
+emchar_string_displayed_columns (const Emchar *str, Charcount len)
{
#ifdef MULE
int cols = 0;
/* NOTE: Does not reset the Dynarr. */
void
-convert_bufbyte_string_into_emchar_dynarr (CONST Bufbyte *str, Bytecount len,
+convert_bufbyte_string_into_emchar_dynarr (const Bufbyte *str, Bytecount len,
Emchar_dynarr *dyn)
{
- CONST Bufbyte *strend = str + len;
+ const Bufbyte *strend = str + len;
while (str < strend)
{
}
}
-int
-convert_bufbyte_string_into_emchar_string (CONST Bufbyte *str, Bytecount len,
+Charcount
+convert_bufbyte_string_into_emchar_string (const Bufbyte *str, Bytecount len,
Emchar *arr)
{
- CONST Bufbyte *strend = str + len;
+ const Bufbyte *strend = str + len;
Charcount newlen = 0;
while (str < strend)
{
/************************************************************************/
void
-vars_of_insdel (void)
+reinit_vars_of_insdel (void)
{
int i;
}
void
+vars_of_insdel (void)
+{
+ reinit_vars_of_insdel ();
+}
+
+void
init_buffer_text (struct buffer *b)
{
if (!b->base_buffer)