changeset 12214:c6ee462394fe

(Fprevious_overlay_change): Check for overlays that end at POS.
author Richard M. Stallman <rms@gnu.org>
date Wed, 14 Jun 1995 14:09:53 +0000
parents 59bfaac6cee2
children 2f1f03964f08
files src/buffer.c
diffstat 1 files changed, 24 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/buffer.c	Wed Jun 14 12:05:55 1995 +0000
+++ b/src/buffer.c	Wed Jun 14 14:09:53 1995 +0000
@@ -2663,7 +2663,7 @@
 DEFUN ("previous-overlay-change", Fprevious_overlay_change,
        Sprevious_overlay_change, 1, 1, 0,
   "Return the previous position before POS where an overlay starts or ends.\n\
-If there are no more overlay boundaries after POS, return (point-min).")
+If there are no more overlay boundaries before POS, return (point-min).")
   (pos)
      Lisp_Object pos;
 {
@@ -2672,19 +2672,25 @@
   Lisp_Object *overlay_vec;
   int len;
   int i;
+  Lisp_Object tail;
 
   CHECK_NUMBER_COERCE_MARKER (pos, 0);
 
   len = 10;
   overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object));
 
+  /* At beginning of buffer, we know the answer;
+     avoid bug subtracting 1 below.  */
+  if (XINT (pos) == BEGV)
+    return pos;
+
   /* Put all the overlays we want in a vector in overlay_vec.
      Store the length in len.
      prevpos gets the position of an overlay end.  */
   noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len,
 			   (int *) 0, &prevpos);
 
-  /* If any of these overlays starts before endpos,
+  /* If any of these overlays starts after prevpos,
      maybe use its starting point instead.  */
   for (i = 0; i < noverlays; i++)
     {
@@ -2697,6 +2703,22 @@
 	prevpos = ostartpos;
     }
 
+  /* If any overlay ends at pos, consider its starting point too.  */
+  for (tail = current_buffer->overlays_before;
+       GC_CONSP (tail);
+       tail = XCONS (tail)->cdr)
+    {
+      Lisp_Object overlay, ostart;
+      int ostartpos;
+
+      overlay = XCONS (tail)->car;
+
+      ostart = OVERLAY_START (overlay);
+      ostartpos = OVERLAY_POSITION (ostart);
+      if (ostartpos > prevpos && ostartpos < XINT (pos))
+	prevpos = ostartpos;
+    }
+
   xfree (overlay_vec);
   return make_number (prevpos);
 }