]> code.delx.au - gnu-emacs/blobdiff - src/editfns.c
[!SYSTEM_MALLOC] (MEMMOVE_MISSING): Defined.
[gnu-emacs] / src / editfns.c
index 0a868abe76111b10a3b0ce1612182cbd5a1560f2..de8d167191b51a632402931dca0959545576a110 100644 (file)
@@ -360,7 +360,7 @@ DEFUN ("buffer-size", Fbufsize, Sbufsize, 0, 0, 0,
 
 DEFUN ("point-min", Fpoint_min, Spoint_min, 0, 0, 0,
   "Return the minimum permissible value of point in the current buffer.\n\
-This is 1, unless a clipping restriction is in effect.")
+This is 1, unless narrowing (a buffer restriction) is in effect.")
   ()
 {
   Lisp_Object temp;
@@ -370,7 +370,7 @@ This is 1, unless a clipping restriction is in effect.")
 
 DEFUN ("point-min-marker", Fpoint_min_marker, Spoint_min_marker, 0, 0, 0,
   "Return a marker to the minimum permissible value of point in this buffer.\n\
-This is the beginning, unless a clipping restriction is in effect.")
+This is the beginning, unless narrowing (a buffer restriction) is in effect.")
   ()
 {
   return buildmark (BEGV);
@@ -378,8 +378,8 @@ This is the beginning, unless a clipping restriction is in effect.")
 
 DEFUN ("point-max", Fpoint_max, Spoint_max, 0, 0, 0,
   "Return the maximum permissible value of point in the current buffer.\n\
-This is (1+ (buffer-size)), unless a clipping restriction is in effect,\n\
-in which case it is less.")
+This is (1+ (buffer-size)), unless narrowing (a buffer restriction)\n\
+is in effect, in which case it is less.")
   ()
 {
   Lisp_Object temp;
@@ -389,8 +389,8 @@ in which case it is less.")
 
 DEFUN ("point-max-marker", Fpoint_max_marker, Spoint_max_marker, 0, 0, 0,
   "Return a marker to the maximum permissible value of point in this buffer.\n\
-This is (1+ (buffer-size)), unless a clipping restriction is in effect,\n\
-in which case it is less.")
+This is (1+ (buffer-size)), unless narrowing (a buffer restriction)\n\
+is in effect, in which case it is less.")
   ()
 {
   return buildmark (ZV);
@@ -719,7 +719,43 @@ Any other markers at the point of insertion remain before the text.")
        }
       else if (XTYPE (tem) == Lisp_String)
        {
-         insert_from_string (tem, 0, XSTRING (tem)->size);
+         insert_from_string (tem, 0, XSTRING (tem)->size, 0);
+       }
+      else
+       {
+         tem = wrong_type_argument (Qchar_or_string_p, tem);
+         goto retry;
+       }
+    }
+
+  return Qnil;
+}
+
+DEFUN ("insert-and-inherit", Finsert_and_inherit, Sinsert_and_inherit,
+   0, MANY, 0,
+  "Insert the arguments at point, inheriting properties from adjoining text.\n\
+Point moves forward so that it ends up after the inserted text.\n\
+Any other markers at the point of insertion remain before the text.")
+  (nargs, args)
+     int nargs;
+     register Lisp_Object *args;
+{
+  register int argnum;
+  register Lisp_Object tem;
+  char str[1];
+
+  for (argnum = 0; argnum < nargs; argnum++)
+    {
+      tem = args[argnum];
+    retry:
+      if (XTYPE (tem) == Lisp_Int)
+       {
+         str[0] = XINT (tem);
+         insert (str, 1);
+       }
+      else if (XTYPE (tem) == Lisp_String)
+       {
+         insert_from_string (tem, 0, XSTRING (tem)->size, 1);
        }
       else
        {
@@ -754,7 +790,44 @@ Any other markers at the point of insertion also end up after the text.")
        }
       else if (XTYPE (tem) == Lisp_String)
        {
-         insert_from_string_before_markers (tem, 0, XSTRING (tem)->size);
+         insert_from_string_before_markers (tem, 0, XSTRING (tem)->size, 0);
+       }
+      else
+       {
+         tem = wrong_type_argument (Qchar_or_string_p, tem);
+         goto retry;
+       }
+    }
+
+  return Qnil;
+}
+
+DEFUN ("insert-before-markers-and-inherit",
+  Finsert_and_inherit_before_markers, Sinsert_and_inherit_before_markers,
+  0, MANY, 0,
+  "Insert text at point, relocating markers and inheriting properties.\n\
+Point moves forward so that it ends up after the inserted text.\n\
+Any other markers at the point of insertion also end up after the text.")
+  (nargs, args)
+     int nargs;
+     register Lisp_Object *args;
+{
+  register int argnum;
+  register Lisp_Object tem;
+  char str[1];
+
+  for (argnum = 0; argnum < nargs; argnum++)
+    {
+      tem = args[argnum];
+    retry:
+      if (XTYPE (tem) == Lisp_Int)
+       {
+         str[0] = XINT (tem);
+         insert_before_markers (str, 1);
+       }
+      else if (XTYPE (tem) == Lisp_String)
+       {
+         insert_from_string_before_markers (tem, 0, XSTRING (tem)->size, 1);
        }
       else
        {
@@ -817,7 +890,7 @@ Lisp_Object
 make_buffer_string (start, end)
      int start, end;
 {
-  Lisp_Object result;
+  Lisp_Object result, tem;
 
   if (start < GPT && GPT < end)
     move_gap (start);
@@ -825,8 +898,12 @@ make_buffer_string (start, end)
   result = make_uninit_string (end - start);
   bcopy (&FETCH_CHAR (start), XSTRING (result)->data, end - start);
 
-  /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
-  copy_intervals_to_string (result, current_buffer, start, end - start);
+  tem = Fnext_property_change (make_number (start), Qnil, make_number (end));
+
+#ifdef USE_TEXT_PROPERTIES
+  if (XINT (tem) != end)
+    copy_intervals_to_string (result, current_buffer, start, end - start);
+#endif
 
   return result;
 }
@@ -918,7 +995,7 @@ They default to the beginning and the end of BUFFER.")
 
   /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
   graft_intervals_into_buffer (copy_intervals (bp->intervals, start, len),
-                              opoint, bp);
+                              opoint, len, current_buffer, 0);
 
   return Qnil;
 }
@@ -1054,6 +1131,7 @@ and don't mark the buffer as really changed.")
      Lisp_Object start, end, fromchar, tochar, noundo;
 {
   register int pos, stop, look;
+  int changed = 0;
 
   validate_region (&start, &end);
   CHECK_NUMBER (fromchar, 2);
@@ -1063,7 +1141,6 @@ and don't mark the buffer as really changed.")
   stop = XINT (end);
   look = XINT (fromchar);
 
-  modify_region (current_buffer, pos, stop);
   if (! NILP (noundo))
     {
       if (MODIFF - 1 == current_buffer->save_modified)
@@ -1076,15 +1153,23 @@ and don't mark the buffer as really changed.")
     {
       if (FETCH_CHAR (pos) == look)
        {
+         if (! changed)
+           {
+             modify_region (current_buffer, XINT (start), stop);
+             changed = 1;
+           }
+
          if (NILP (noundo))
            record_change (pos, 1);
          FETCH_CHAR (pos) = XINT (tochar);
-         if (NILP (noundo))
-           signal_after_change (pos, 1, 1);
        }
       pos++;
     }
 
+  if (changed)
+    signal_after_change (XINT (start),
+                        stop - XINT (start), stop - XINT (start));
+
   return Qnil;
 }
 
@@ -1533,6 +1618,8 @@ syms_of_editfns ()
   defsubr (&Schar_after);
   defsubr (&Sinsert);
   defsubr (&Sinsert_before_markers);
+  defsubr (&Sinsert_and_inherit);
+  defsubr (&Sinsert_and_inherit_before_markers);
   defsubr (&Sinsert_char);
 
   defsubr (&Suser_login_name);