changeset 41830:71cbc17f7f8b

(make_gap_larger): New function. (make_gap_smaller): New function. (make_gap) [USE_MMAP_FOR_BUFFERS || REL_ALLOC]: Call make_gap_smaller if arg is negative.
author Andrew Innes <andrewi@gnu.org>
date Wed, 05 Dec 2001 21:37:11 +0000
parents b4833df45a4c
children fa7af2e13043
files src/insdel.c
diffstat 1 files changed, 70 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/insdel.c	Wed Dec 05 19:27:45 2001 +0000
+++ b/src/insdel.c	Wed Dec 05 21:37:11 2001 +0000
@@ -520,7 +520,7 @@
 /* Make the gap NBYTES_ADDED bytes longer.  */
 
 void
-make_gap (nbytes_added)
+make_gap_larger (nbytes_added)
      int nbytes_added;
 {
   Lisp_Object tem;
@@ -568,6 +568,75 @@
 
   Vinhibit_quit = tem;
 }
+
+
+/* Make the gap NBYTES_REMOVED bytes shorted.  */
+
+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 old_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;
+  old_gap_size = GAP_SIZE;
+  real_Z = Z;
+  real_Z_byte = Z_BYTE;
+
+  /* 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, GAP_SIZE - nbytes_removed);
+  GPT += GAP_SIZE - nbytes_removed;
+  GPT_BYTE += GAP_SIZE - nbytes_removed;
+  Z += GAP_SIZE - nbytes_removed;
+  Z_BYTE += GAP_SIZE - nbytes_removed;
+  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 = old_gap_size - nbytes_removed;
+  GPT = real_gap_loc;
+  GPT_BYTE = real_gap_loc_byte;
+  Z = real_Z;
+  Z_BYTE = real_Z_byte;
+
+  /* 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)
+  else
+    make_gap_smaller (-nbytes_added);
+#endif
+}
 
 /* Copy NBYTES bytes of text from FROM_ADDR to TO_ADDR.
    FROM_MULTIBYTE says whether the incoming text is multibyte.