]> code.delx.au - gnu-emacs/blobdiff - src/insdel.c
(PENDING_OUTPUT_COUNT) [__GNU_LIBRARY__]: Alternate definition for the GNU
[gnu-emacs] / src / insdel.c
index 1deda9d7ac82aed7c183256ecf318bc923162f5d..711e272da597174f5a71673bc022e6843b334805 100644 (file)
@@ -1,5 +1,5 @@
 /* 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.
 
@@ -18,14 +18,12 @@ along with GNU Emacs; see the file COPYING.  If not, write to
 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!  */
@@ -248,7 +246,10 @@ make_gap (increment)
   /* 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;
@@ -305,6 +306,9 @@ insert (string, length)
 
   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;
@@ -314,14 +318,19 @@ insert (string, 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;
@@ -348,10 +357,18 @@ insert_from_string (string, pos, length)
 
   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);
@@ -391,12 +408,13 @@ insert_before_markers (string, 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
@@ -425,6 +443,9 @@ del_range (from, to)
 
   prepare_to_modify_buffer (from, to);
 
+  record_delete (from, numdel);
+  MODIFF++;
+
   /* Relocate point as if it were a marker.  */
   if (from < point)
     {
@@ -434,8 +455,8 @@ del_range (from, to)
        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.  */
@@ -454,9 +475,19 @@ del_range (from, to)
   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)
@@ -465,10 +496,15 @@ modify_region (start, end)
       || 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;
@@ -476,8 +512,10 @@ prepare_to_modify_buffer (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)
@@ -494,6 +532,8 @@ prepare_to_modify_buffer (start, end)
 #endif /* not CLASH_DETECTION */
 
   signal_before_change (start, end);
+
+  Vdeactivate_mark = Qt;
 }
 \f
 static Lisp_Object
@@ -510,7 +550,7 @@ after_change_function_restore (value)
   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.  */
 
@@ -519,10 +559,10 @@ signal_before_change (start, end)
 {
   /* 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))
     {
@@ -542,7 +582,7 @@ signal_before_change (start, end)
     }
 }
 
-/* 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.)