]> code.delx.au - gnu-emacs/blobdiff - src/marker.c
* xfns.c (xpm_load) [!ALLOC_XPM_COLORS]: Declare local variable I in inner block.
[gnu-emacs] / src / marker.c
index 0cb6d3979a1294ec16b893dbd2ef20783bdbd86d..7ef5b2a2bbd84662d7a451971346dce825949a55 100644 (file)
@@ -32,6 +32,8 @@ static int cached_bytepos;
 static struct buffer *cached_buffer;
 static int cached_modiff;
 
+static void byte_char_debug_check P_ ((struct buffer *, int, int));
+
 /* Nonzero means enable debugging checks on byte/char correspondences.  */
 
 static int byte_debug_flag;
@@ -97,7 +99,7 @@ clear_charpos_cache (b)
     }                                                                  \
 }
 
-int
+static void
 byte_char_debug_check (b, charpos, bytepos)
      struct buffer *b;
      int charpos, bytepos;
@@ -168,7 +170,7 @@ buf_charpos_to_bytepos (b, charpos)
     CONSIDER (cached_charpos, cached_bytepos);
 
   tail = BUF_MARKERS (b);
-  while (XSYMBOL (tail) != XSYMBOL (Qnil))
+  while (! NILP (tail))
     {
       CONSIDER (XMARKER (tail)->charpos, XMARKER (tail)->bytepos);
 
@@ -336,7 +338,7 @@ buf_bytepos_to_charpos (b, bytepos)
     CONSIDER (cached_bytepos, cached_charpos);
 
   tail = BUF_MARKERS (b);
-  while (XSYMBOL (tail) != XSYMBOL (Qnil))
+  while (! NILP (tail))
     {
       CONSIDER (XMARKER (tail)->bytepos, XMARKER (tail)->charpos);
 
@@ -355,7 +357,7 @@ buf_bytepos_to_charpos (b, bytepos)
 
   if (bytepos - best_below_byte < best_above_byte - bytepos)
     {
-      int record = best_above_byte - bytepos > 5000;
+      int record = bytepos - best_below_byte > 5000;
 
       while (best_below_byte < bytepos)
        {
@@ -365,8 +367,10 @@ buf_bytepos_to_charpos (b, bytepos)
 
       /* If this position is quite far from the nearest known position,
         cache the correspondence by creating a marker here.
-        It will last until the next GC.  */
-      if (record)
+        It will last until the next GC.
+        But don't do it if BUF_MARKERS is nil;
+        that is a signal from Fset_buffer_multibyte.  */
+      if (record && ! NILP (BUF_MARKERS (b)))
        {
          Lisp_Object marker, buffer;
          marker = Fmake_marker ();
@@ -396,8 +400,10 @@ buf_bytepos_to_charpos (b, bytepos)
 
       /* If this position is quite far from the nearest known position,
         cache the correspondence by creating a marker here.
-        It will last until the next GC.  */
-      if (record)
+        It will last until the next GC.
+        But don't do it if BUF_MARKERS is nil;
+        that is a signal from Fset_buffer_multibyte.  */
+      if (record && ! NILP (BUF_MARKERS (b)))
        {
          Lisp_Object marker, buffer;
          marker = Fmake_marker ();
@@ -444,10 +450,6 @@ DEFUN ("marker-position", Fmarker_position, Smarker_position, 1, 1, 0,
   (marker)
      Lisp_Object marker;
 {
-  register Lisp_Object pos;
-  register int i;
-  register struct buffer *buf;
-
   CHECK_MARKER (marker, 0);
   if (XMARKER (marker)->buffer)
     return make_number (XMARKER (marker)->charpos);
@@ -739,9 +741,11 @@ unchain_marker (marker)
   if (EQ (b->name, Qnil))
     abort ();
 
+  XMARKER (marker)->buffer = 0;
+
   tail = BUF_MARKERS (b);
   prev = Qnil;
-  while (XSYMBOL (tail) != XSYMBOL (Qnil))
+  while (! GC_NILP (tail))
     {
       next = XMARKER (tail)->chain;
       XUNMARK (next);
@@ -764,13 +768,17 @@ unchain_marker (marker)
              XMARKER (prev)->chain = next;
              XSETMARKBIT (XMARKER (prev)->chain, omark);
            }
-         break;
+         /* We have removed the marker from the chain;
+            no need to scan the rest of the chain.  */
+         return;
        }
       else
        prev = tail;
       tail = next;
     }
-  XMARKER (marker)->buffer = 0;
+
+  /* Marker was not in its chain.  */
+  abort ();
 }
 
 /* Return the char position of marker MARKER, as a C integer.  */
@@ -818,16 +826,14 @@ see `marker-insertion-type'.")
 {
   register Lisp_Object new;
 
-  if (INTEGERP (marker) || MARKERP (marker))
-    {
-      new = Fmake_marker ();
-      Fset_marker (new, marker,
-                  (MARKERP (marker) ? Fmarker_buffer (marker) : Qnil));
-      XMARKER (new)->insertion_type = !NILP (type);
-      return new;
-    }
-  else
+  if (! (INTEGERP (marker) || MARKERP (marker)))
     marker = wrong_type_argument (Qinteger_or_marker_p, marker);
+
+  new = Fmake_marker ();
+  Fset_marker (new, marker,
+              (MARKERP (marker) ? Fmarker_buffer (marker) : Qnil));
+  XMARKER (new)->insertion_type = !NILP (type);
+  return new;
 }
 
 DEFUN ("marker-insertion-type", Fmarker_insertion_type,
@@ -837,7 +843,6 @@ nil means the marker stays before text inserted there.")
   (marker)
      register Lisp_Object marker;
 {
-  register Lisp_Object buf;
   CHECK_MARKER (marker, 0);
   return XMARKER (marker)->insertion_type ? Qt : Qnil;
 }