]> code.delx.au - gnu-emacs/blobdiff - src/insdel.c
Remove #definition of HAVE_CLOSEDIR; autoconf figures this out.
[gnu-emacs] / src / insdel.c
index 80f1d67369bcedbdba4773e8fcef3a25294d9d8f..f53d6a76c6a1f925aba931b1ae92133fe618b7e7 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.
 
@@ -20,12 +20,10 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #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!  */
@@ -214,7 +212,7 @@ adjust_markers (from, to, amount)
 
   marker = current_buffer->markers;
 
-  while (!NULL (marker))
+  while (!NILP (marker))
     {
       m = XMARKER (marker);
       mpos = m->bufpos;
@@ -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,11 +318,15 @@ 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)
      Lisp_Object string;
      register int pos, length;
@@ -348,11 +356,19 @@ 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;
-  point += length;
+
+  /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
+  graft_intervals_into_buffer (XSTRING (string)->intervals, point,
+                              current_buffer);
+
+  SET_PT (point + length);
 
   signal_after_change (point-length, 0, length);
 }
@@ -425,6 +441,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 +453,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 +473,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,35 +494,42 @@ 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;
 {
-  if (!NULL (current_buffer->read_only))
+  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);
 
 #ifdef CLASH_DETECTION
-  if (!NULL (current_buffer->filename)
+  if (!NILP (current_buffer->filename)
       && current_buffer->save_modified >= MODIFF)
     lock_file (current_buffer->filename);
 #else
   /* At least warn if this file has changed on disk since it was visited.  */
-  if (!NULL (current_buffer->filename)
+  if (!NILP (current_buffer->filename)
       && current_buffer->save_modified >= MODIFF
-      && NULL (Fverify_visited_file_modtime (Fcurrent_buffer ()))
-      && !NULL (Ffile_exists_p (current_buffer->filename)))
+      && NILP (Fverify_visited_file_modtime (Fcurrent_buffer ()))
+      && !NILP (Ffile_exists_p (current_buffer->filename)))
     call1 (intern ("ask-user-about-supersession-threat"),
           current_buffer->filename);
 #endif /* not CLASH_DETECTION */
 
   signal_before_change (start, end);
+
+  Vdeactivate_mark = Qt;
 }
 \f
 static Lisp_Object
@@ -510,7 +546,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,12 +555,12 @@ signal_before_change (start, end)
 {
   /* If buffer is unmodified, run a special hook for that case.  */
   if (current_buffer->save_modified >= MODIFF
-      && !NULL (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 (!NULL (Vbefore_change_function))
+  if (!NILP (Vbefore_change_function))
     {
       int count = specpdl_ptr - specpdl;
       Lisp_Object function;
@@ -542,7 +578,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.)
@@ -551,7 +587,7 @@ signal_before_change (start, end)
 signal_after_change (pos, lendel, lenins)
      int pos, lendel, lenins;
 {
-  if (!NULL (Vafter_change_function))
+  if (!NILP (Vafter_change_function))
     {
       int count = specpdl_ptr - specpdl;
       Lisp_Object function;