]> code.delx.au - gnu-emacs/blobdiff - src/marker.c
(byte-compile-no-warnings): New function.
[gnu-emacs] / src / marker.c
index b634d644790c621b3c8d10030f59abe4f8aa0c06..b91609ca084fbede024222b1ed333a99139a89e6 100644 (file)
@@ -49,7 +49,7 @@ clear_charpos_cache (b)
 /* Converting between character positions and byte positions.  */
 
 /* There are several places in the buffer where we know
-   the corrspondence: BEG, BEGV, PT, GPT, ZV and Z,
+   the correspondence: BEG, BEGV, PT, GPT, ZV and Z,
    and everywhere there is a marker.  So we find the one of these places
    that is closest to the specified position, and scan from there.  */
 
@@ -149,8 +149,8 @@ buf_charpos_to_bytepos (b, charpos)
   if (best_above == best_above_byte)
     return charpos;
 
-  best_below = 1;
-  best_below_byte = 1;
+  best_below = BEG;
+  best_below_byte = BEG_BYTE;
 
   /* We find in best_above and best_above_byte
      the closest known point above CHARPOS,
@@ -252,6 +252,24 @@ buf_charpos_to_bytepos (b, charpos)
 }
 
 #undef CONSIDER
+
+/* Used for debugging: recompute the bytepos corresponding to CHARPOS
+   in the simplest, most reliable way.  */
+
+int
+verify_bytepos (charpos)
+{
+  int below = 1;
+  int below_byte = 1;
+
+  while (below != charpos)
+    {
+      below++;
+      BUF_INC_POS (current_buffer, below_byte);
+    }
+
+  return below_byte;
+}
 \f
 /* bytepos_to_charpos returns the char position corresponding to BYTEPOS.  */
 
@@ -326,8 +344,8 @@ buf_bytepos_to_charpos (b, bytepos)
   if (best_above == best_above_byte)
     return bytepos;
 
-  best_below = 1;
-  best_below_byte = 1;
+  best_below = BEG;
+  best_below_byte = BEG_BYTE;
 
   CONSIDER (BUF_PT_BYTE (b), BUF_PT (b));
   CONSIDER (BUF_GPT_BYTE (b), BUF_GPT (b));
@@ -531,14 +549,14 @@ Returns MARKER.  */)
       m->chain = BUF_MARKERS (b);
       BUF_MARKERS (b) = marker;
     }
-  
+
   return marker;
 }
 
 /* This version of Fset_marker won't let the position
    be outside the visible part.  */
 
-Lisp_Object 
+Lisp_Object
 set_marker_restricted (marker, pos, buffer)
      Lisp_Object marker, pos, buffer;
 {
@@ -607,14 +625,14 @@ set_marker_restricted (marker, pos, buffer)
       m->chain = BUF_MARKERS (b);
       BUF_MARKERS (b) = marker;
     }
-  
+
   return marker;
 }
 \f
 /* Set the position of MARKER, specifying both the
    character position and the corresponding byte position.  */
 
-Lisp_Object 
+Lisp_Object
 set_marker_both (marker, buffer, charpos, bytepos)
      Lisp_Object marker, buffer;
      int charpos, bytepos;
@@ -658,14 +676,14 @@ set_marker_both (marker, buffer, charpos, bytepos)
       m->chain = BUF_MARKERS (b);
       BUF_MARKERS (b) = marker;
     }
-  
+
   return marker;
 }
 
 /* This version of set_marker_both won't let the position
    be outside the visible part.  */
 
-Lisp_Object 
+Lisp_Object
 set_marker_restricted_both (marker, buffer, charpos, bytepos)
      Lisp_Object marker, buffer;
      int charpos, bytepos;
@@ -718,11 +736,14 @@ set_marker_restricted_both (marker, buffer, charpos, bytepos)
       m->chain = BUF_MARKERS (b);
       BUF_MARKERS (b) = marker;
     }
-  
+
   return marker;
 }
 \f
-/* This is called during garbage collection,
+/* Remove MARKER from the chain of whatever buffer it is in.
+   Leave it "in no buffer".
+
+   This is called during garbage collection,
    so we must be careful to ignore and preserve mark bits,
    including those in chain fields of markers.  */
 
@@ -885,6 +906,23 @@ DEFUN ("buffer-has-markers-at", Fbuffer_has_markers_at, Sbuffer_has_markers_at,
 
   return Qnil;
 }
+
+/* For debugging -- count the markers in buffer BUF.  */
+
+int
+count_markers (buf)
+     struct buffer *buf;
+{
+  int total = 0;
+  Lisp_Object tail;
+
+  for (tail = BUF_MARKERS (buf);
+       !NILP (tail);
+       tail = XMARKER (tail)->chain)
+    total++;
+
+  return total;
+}
 \f
 void
 syms_of_marker ()