]> code.delx.au - gnu-emacs/blobdiff - src/insdel.c
Delete the code that was trying to define BSD "right"
[gnu-emacs] / src / insdel.c
index b3bc81467fdbb33c156e35ae83cf643bf1804c03..12b7eedb58b5f28dbd891a5c4122540275f97237 100644 (file)
@@ -23,6 +23,7 @@ Boston, MA 02111-1307, USA.  */
 #include "lisp.h"
 #include "intervals.h"
 #include "buffer.h"
+#include "charset.h"
 #include "window.h"
 #include "blockinput.h"
 
@@ -153,6 +154,7 @@ gap_left (pos, newgap)
      or may be where a quit was detected.  */
   adjust_markers (pos + 1, GPT, GAP_SIZE);
   GPT = pos + 1;
+  if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor.  */
   QUIT;
 }
 
@@ -231,6 +233,7 @@ gap_right (pos)
 
   adjust_markers (GPT + GAP_SIZE, pos + 1 + GAP_SIZE, - GAP_SIZE);
   GPT = pos + 1;
+  if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor.  */
   QUIT;
 }
 
@@ -271,8 +274,24 @@ adjust_markers (from, to, amount)
             but then this range contains no markers.  */
          if (mpos > from + amount && mpos <= from)
            {
-             record_marker_adjustment (marker, from + amount - mpos);
-             mpos = from + amount;
+             int before = mpos;
+             int after = from + amount;
+
+             mpos = after;
+
+             /* Compute the before and after positions
+                as buffer positions.  */
+             if (before > GPT + GAP_SIZE)
+               before -= GAP_SIZE;
+             else if (before > GPT)
+               before = GPT;
+
+             if (after > GPT + GAP_SIZE)
+               after -= GAP_SIZE;
+             else if (after > GPT)
+               after = GPT;
+
+             record_marker_adjustment (marker, after - before);
            }
        }
       if (mpos > from && mpos <= to)
@@ -290,6 +309,7 @@ adjust_markers_for_insert (pos, amount)
      register int pos, amount;
 {
   Lisp_Object marker;
+  int adjusted = 0;
 
   marker = BUF_MARKERS (current_buffer);
 
@@ -297,9 +317,16 @@ adjust_markers_for_insert (pos, amount)
     {
       register struct Lisp_Marker *m = XMARKER (marker);
       if (m->insertion_type && m->bufpos == pos)
-       m->bufpos += amount;
+       {
+         m->bufpos += amount;
+         adjusted = 1;
+       }
       marker = m->chain;
     }
+  if (adjusted)
+    /* Adjusting only markers whose insertion-type is t may result in
+       disordered overlays in the slot `overlays_before'.  */
+    fix_overlays_before (current_buffer, pos, pos + amount);
 }
 
 /* Add the specified amount to point.  This is used only when the value
@@ -339,7 +366,8 @@ make_gap (increment)
     error ("Buffer exceeds maximum size");
 
   BLOCK_INPUT;
-  result = BUFFER_REALLOC (BEG_ADDR, (Z - BEG + GAP_SIZE + increment));
+  /* We allocate extra 1-byte `\0' at the tail for anchoring a search.  */
+  result = BUFFER_REALLOC (BEG_ADDR, (Z - BEG + GAP_SIZE + increment + 1));
 
   if (result == 0)
     {
@@ -370,6 +398,9 @@ make_gap (increment)
   GAP_SIZE += old_gap_size;
   GPT = real_gap_loc;
 
+  /* Put an anchor.  */
+  *(Z_ADDR) = 0;
+
   Vinhibit_quit = tem;
 }
 \f
@@ -432,6 +463,7 @@ insert_1 (string, length, inherit, prepare)
   GPT += length;
   ZV += length;
   Z += length;
+  if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor.  */
   adjust_overlays_for_insert (PT, length);
   adjust_markers_for_insert (PT, length);
   adjust_point (length);
@@ -500,6 +532,7 @@ insert_from_string_1 (string, pos, length, inherit)
   GPT += length;
   ZV += length;
   Z += length;
+  if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor.  */
   adjust_overlays_for_insert (PT, length);
   adjust_markers_for_insert (PT, length);
 
@@ -576,6 +609,7 @@ insert_from_buffer_1 (buf, pos, length, inherit)
   GPT += length;
   ZV += length;
   Z += length;
+  if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor.  */
   adjust_overlays_for_insert (PT, length);
   adjust_markers_for_insert (PT, length);
   adjust_point (length);
@@ -590,9 +624,12 @@ insert_from_buffer_1 (buf, pos, length, inherit)
 
 void
 insert_char (c)
-     unsigned char c;
+     int c;
 {
-  insert (&c, 1);
+  unsigned char workbuf[4], *str;
+  int len = CHAR_STRING (c, workbuf, str);
+
+  insert (str, len);
 }
 
 /* Insert the null-terminated string S before point */
@@ -714,6 +751,7 @@ del_range_1 (from, to, prepare)
   ZV -= numdel;
   Z -= numdel;
   GPT = from;
+  *(GPT_ADDR) = 0;             /* Put an anchor.  */
 
   if (GPT - BEG < beg_unchanged)
     beg_unchanged = GPT - BEG;
@@ -988,7 +1026,8 @@ DEFUN ("combine-after-change-execute", Fcombine_after_change_execute,
   for (tail = combine_after_change_list; CONSP (tail);
        tail = XCONS (tail)->cdr)
     {
-      Lisp_Object elt, thisbeg, thisend, thischange;
+      Lisp_Object elt;
+      int thisbeg, thisend, thischange;
 
       /* Extract the info from the next element.  */
       elt = XCONS (tail)->car;