changeset 9656:e6cb99e4370c

(insert_from_buffer, insert_from_buffer_1): New functions.
author Karl Heuer <kwzh@gnu.org>
date Sat, 22 Oct 1994 04:45:57 +0000
parents 93ccc7bbae8a
children 0fc126c193e7
files src/insdel.c
diffstat 1 files changed, 74 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/insdel.c	Sat Oct 22 04:39:30 1994 +0000
+++ b/src/insdel.c	Sat Oct 22 04:45:57 1994 +0000
@@ -27,6 +27,7 @@
 
 static void insert_1 ();
 static void insert_from_string_1 ();
+static void insert_from_buffer_1 ();
 static void gap_left ();
 static void gap_right ();
 static void adjust_markers ();
@@ -305,8 +306,8 @@
 }
 
 /* Insert a string of specified length before point.
-   DO NOT use this for the contents of a Lisp string!
-   prepare_to_modify_buffer could relocate the string.  */
+   DO NOT use this for the contents of a Lisp string or a Lisp buffer!
+   prepare_to_modify_buffer could relocate the text.  */
 
 insert (string, length)
      register unsigned char *string;
@@ -438,6 +439,77 @@
   adjust_point (length);
 }
 
+/* Insert text from BUF, starting at POS and having length LENGTH, into the
+   current buffer.  If the text in BUF has properties, they are absorbed
+   into the current buffer.
+
+   It does not work to use `insert' for this, because a malloc could happen
+   and relocate BUF's text before the bcopy happens.  */
+
+void
+insert_from_buffer (buf, pos, length, inherit)
+     struct buffer *buf;
+     int pos, length;
+     int inherit;
+{
+  if (length > 0)
+    {
+      insert_from_buffer_1 (buf, pos, length, inherit);
+      signal_after_change (PT-length, 0, length);
+    }
+}
+
+static void
+insert_from_buffer_1 (buf, pos, length, inherit)
+     struct buffer *buf;
+     int pos, length;
+     int inherit;
+{
+  register Lisp_Object temp;
+  int chunk;
+
+  /* Make sure point-max won't overflow after this insertion.  */
+  XSETINT (temp, length + Z);
+  if (length + Z != XINT (temp))
+    error ("maximum buffer size exceeded");
+
+  prepare_to_modify_buffer (PT, PT);
+
+  if (PT != GPT)
+    move_gap (PT);
+  if (GAP_SIZE < length)
+    make_gap (length - GAP_SIZE);
+
+  record_insert (PT, length);
+  MODIFF++;
+
+  if (pos < BUF_GPT (buf))
+    {
+      chunk = min (length, BUF_GPT (buf) - pos);
+      bcopy (BUF_CHAR_ADDRESS (buf, pos), GPT_ADDR, chunk);
+    }
+  else
+    chunk = 0;
+  if (chunk < length)
+    bcopy (BUF_CHAR_ADDRESS (buf, pos + chunk),
+	   GPT_ADDR + chunk, length - chunk);
+
+#ifdef USE_TEXT_PROPERTIES
+  if (current_buffer->intervals != 0)
+    offset_intervals (current_buffer, PT, length);
+#endif
+
+  GAP_SIZE -= length;
+  GPT += length;
+  ZV += length;
+  Z += length;
+  adjust_point (length);
+
+  /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
+  graft_intervals_into_buffer (copy_intervals (buf->intervals, pos, length),
+			       PT - length, length, current_buffer, inherit);
+}
+
 /* Insert the character C before point */
 
 void