summaryrefslogtreecommitdiff
path: root/src/insdel.c
diff options
context:
space:
mode:
authorAndrew Innes <andrewi@gnu.org>2001-12-05 21:37:11 +0000
committerAndrew Innes <andrewi@gnu.org>2001-12-05 21:37:11 +0000
commit0d7a6743ff51818f6caccab970cfeed60b528f48 (patch)
tree1935591d66c4005cce943f20d2d10d55c34df67c /src/insdel.c
parent60dbbe5d94901631bebee73b21a459573238f4c7 (diff)
downloademacs-0d7a6743ff51818f6caccab970cfeed60b528f48.tar.gz
(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.
Diffstat (limited to 'src/insdel.c')
-rw-r--r--src/insdel.c71
1 files changed, 70 insertions, 1 deletions
diff --git a/src/insdel.c b/src/insdel.c
index a6953ad9bfc..db5cd98a487 100644
--- a/src/insdel.c
+++ b/src/insdel.c
@@ -520,7 +520,7 @@ adjust_markers_for_replace (from, from_byte, old_chars, old_bytes,
/* 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 @@ make_gap (nbytes_added)
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.