/* Buffer insertion/deletion and gap motion for GNU Emacs.
- Copyright (C) 1985, 1986 Free Software Foundation, Inc.
+ Copyright (C) 1985, 1986, 1993 Free Software Foundation, Inc.
This file is part of GNU Emacs.
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
-#include "config.h"
+#include <config.h>
#include "lisp.h"
+#include "intervals.h"
#include "buffer.h"
#include "window.h"
-
-/* Nonzero means don't allow protected fields to be modified. */
-
-extern int check_protected_fields;
+#include "blockinput.h"
/* Move gap to position `pos'.
Note that this can quit! */
/* If we have to get more space, get enough to last a while. */
increment += 2000;
+ BLOCK_INPUT;
result = BUFFER_REALLOC (BEG_ADDR, (Z - BEG + GAP_SIZE + increment));
+ UNBLOCK_INPUT;
+
if (result == 0)
memory_full ();
BEG_ADDR = result;
bcopy (string, GPT_ADDR, length);
+ /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
+ offset_intervals (current_buffer, point, length);
+
GAP_SIZE -= length;
GPT += length;
ZV += length;
signal_after_change (point-length, 0, length);
}
-/* Function to insert part of the text of a string (STRING) consisting
- of LENGTH characters at position POS.
- It does not work to use `insert' for this, becase a GC could happen
+/* Insert the part of the text of STRING, a Lisp object assumed to be
+ of type string, consisting of the LENGTH characters starting at
+ position POS. If the text of STRING has properties, they are absorbed
+ into the buffer.
+
+ It does not work to use `insert' for this, because a GC could happen
before we bcopy the stuff into the buffer, and relocate the string
without insert noticing. */
-insert_from_string (string, pos, length)
+
+insert_from_string (string, pos, length, inherit)
Lisp_Object string;
register int pos, length;
+ int inherit;
{
register Lisp_Object temp;
struct gcpro gcpro1;
bcopy (XSTRING (string)->data, GPT_ADDR, length);
+ /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
+ offset_intervals (current_buffer, point, length);
+
GAP_SIZE -= length;
GPT += length;
ZV += length;
Z += length;
+
+ /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
+ graft_intervals_into_buffer (XSTRING (string)->intervals, point, length,
+ current_buffer, inherit);
+
SET_PT (point + length);
signal_after_change (point-length, 0, length);
/* Insert part of a Lisp string, relocating markers after. */
-insert_from_string_before_markers (string, pos, length)
+insert_from_string_before_markers (string, pos, length, inherit)
Lisp_Object string;
register int pos, length;
+ int inherit;
{
register int opoint = point;
- insert_from_string (string, pos, length);
+ insert_from_string (string, pos, length, inherit);
adjust_markers (opoint - 1, opoint, length);
}
\f
prepare_to_modify_buffer (from, to);
+ record_delete (from, numdel);
+ MODIFF++;
+
/* Relocate point as if it were a marker. */
if (from < point)
{
SET_PT (point - numdel);
}
- record_delete (from, numdel);
- MODIFF++;
+ /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
+ offset_intervals (current_buffer, point, - numdel);
/* Relocate all markers pointing into the new, larger gap
to point at the end of the text before the gap. */
signal_after_change (from, numdel, 0);
}
\f
-modify_region (start, end)
+/* Call this if you're about to change the region of BUFFER from START
+ to END. This checks the read-only properties of the region, calls
+ the necessary modification hooks, and warns the next redisplay that
+ it should pay attention to that area. */
+modify_region (buffer, start, end)
+ struct buffer *buffer;
int start, end;
{
+ struct buffer *old_buffer = current_buffer;
+
+ if (buffer != old_buffer)
+ set_buffer_internal (buffer);
+
prepare_to_modify_buffer (start, end);
if (start - 1 < beg_unchanged || unchanged_modified == MODIFF)
|| unchanged_modified == MODIFF)
end_unchanged = Z - end;
MODIFF++;
+
+ if (buffer != old_buffer)
+ set_buffer_internal (old_buffer);
}
/* Check that it is okay to modify the buffer between START and END.
- Run the before-change-function, if any. */
+ Run the before-change-function, if any. If intervals are in use,
+ verify that the text to be modified is not read-only, and call
+ any modification properties the text may have. */
prepare_to_modify_buffer (start, end)
Lisp_Object start, end;
if (!NILP (current_buffer->read_only))
Fbarf_if_buffer_read_only ();
- if (check_protected_fields)
- Fregion_fields (start, end, Qnil, Qt);
+ /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
+ verify_interval_modification (current_buffer, start, end);
+
+ verify_overlay_modification (start, end);
#ifdef CLASH_DETECTION
if (!NILP (current_buffer->filename)
#endif /* not CLASH_DETECTION */
signal_before_change (start, end);
+
+ Vdeactivate_mark = Qt;
}
\f
static Lisp_Object
Vafter_change_function = value;
}
-/* Signal a change to the buffer immediatly before it happens.
+/* Signal a change to the buffer immediately before it happens.
START and END are the bounds of the text to be changed,
as Lisp objects. */
{
/* If buffer is unmodified, run a special hook for that case. */
if (current_buffer->save_modified >= MODIFF
- && !NILP (Vfirst_change_function))
- {
- call0 (Vfirst_change_function);
- }
+ && !NILP (Vfirst_change_hook)
+ && !NILP (Vrun_hooks))
+ call1 (Vrun_hooks, Qfirst_change_hook);
+
/* Now in any case run the before-change-function if any. */
if (!NILP (Vbefore_change_function))
{
}
}
-/* Signal a change immediatly after it happens.
+/* Signal a change immediately after it happens.
POS is the address of the start of the changed text.
LENDEL is the number of characters of the text before the change.
(Not the whole buffer; just the part that was changed.)