changeset 12699:d0f4113de2ea

(record_overlay_string, overlay_strings): Handle zero-sized overlays better.
author Karl Heuer <kwzh@gnu.org>
date Thu, 27 Jul 1995 22:44:41 +0000
parents e04324240c6b
children b3a8ee2da96a
files src/buffer.c
diffstat 1 files changed, 37 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/buffer.c	Thu Jul 27 22:04:24 1995 +0000
+++ b/src/buffer.c	Thu Jul 27 22:44:41 1995 +0000
@@ -1949,7 +1949,7 @@
 
 struct sortstr
 {
-  Lisp_Object string;
+  Lisp_Object string, string2;
   int size;
   int priority;
 };
@@ -1987,10 +1987,9 @@
 }
 
 static void
-record_overlay_string (ssl, str, pri, size)
+record_overlay_string (ssl, str, str2, pri, size)
      struct sortstrlist *ssl;
-     Lisp_Object str;
-     Lisp_Object pri;
+     Lisp_Object str, str2, pri;
      int size;
 {
   if (ssl->used == ssl->size)
@@ -2003,19 +2002,26 @@
 		  xrealloc (ssl->buf, ssl->size * sizeof (struct sortstr)));
     }
   ssl->buf[ssl->used].string = str;
+  ssl->buf[ssl->used].string2 = str2;
   ssl->buf[ssl->used].size = size;
   ssl->buf[ssl->used].priority = (INTEGERP (pri) ? XINT (pri) : 0);
   ssl->used++;
   ssl->bytes += XSTRING (str)->size;
+  if (STRINGP (str2))
+    ssl->bytes += XSTRING (str2)->size;
 }
 
 /* Return the concatenation of the strings associated with overlays that
    begin or end at POS, ignoring overlays that are specific to a window
    other than W.  The strings are concatenated in the appropriate order:
    shorter overlays nest inside longer ones, and higher priority inside
-   lower.  Returns the string length, and stores the contents indirectly
-   through PSTR, if that variable is non-null.  The string may be
-   overwritten by subsequent calls.  */
+   lower.  Normally all of the after-strings come first, but zero-sized
+   overlays have their after-strings ride along with the before-strings
+   because it would look strange to print them inside-out.
+
+   Returns the string length, and stores the contents indirectly through
+   PSTR, if that variable is non-null.  The string may be overwritten by
+   subsequent calls.  */
 int
 overlay_strings (pos, w, pstr)
      int pos;
@@ -2042,14 +2048,17 @@
       window = Foverlay_get (overlay, Qwindow);
       if (WINDOWP (window) && XWINDOW (window) != w)
 	continue;
-      if (endpos == pos
-	  && (str = Foverlay_get (overlay, Qafter_string), STRINGP (str)))
-	record_overlay_string (&overlay_tails, str,
-			       Foverlay_get (overlay, Qpriority),
-			       endpos - startpos);
       if (startpos == pos
 	  && (str = Foverlay_get (overlay, Qbefore_string), STRINGP (str)))
 	record_overlay_string (&overlay_heads, str,
+			       (startpos == endpos
+				? Foverlay_get (overlay, Qafter_string)
+				: Qnil),
+			       Foverlay_get (overlay, Qpriority),
+			       endpos - startpos);
+      else if (endpos == pos
+	  && (str = Foverlay_get (overlay, Qafter_string), STRINGP (str)))
+	record_overlay_string (&overlay_tails, str, Qnil,
 			       Foverlay_get (overlay, Qpriority),
 			       endpos - startpos);
     }
@@ -2068,14 +2077,17 @@
       window = Foverlay_get (overlay, Qwindow);
       if (WINDOWP (window) && XWINDOW (window) != w)
 	continue;
-      if (endpos == pos
-	  && (str = Foverlay_get (overlay, Qafter_string), STRINGP (str)))
-	record_overlay_string (&overlay_tails, str,
-			       Foverlay_get (overlay, Qpriority),
-			       endpos - startpos);
       if (startpos == pos
 	  && (str = Foverlay_get (overlay, Qbefore_string), STRINGP (str)))
 	record_overlay_string (&overlay_heads, str,
+			       (startpos == endpos
+				? Foverlay_get (overlay, Qafter_string)
+				: Qnil),
+			       Foverlay_get (overlay, Qpriority),
+			       endpos - startpos);
+      else if (endpos == pos
+	       && (str = Foverlay_get (overlay, Qafter_string), STRINGP (str)))
+	record_overlay_string (&overlay_tails, str, Qnil,
 			       Foverlay_get (overlay, Qpriority),
 			       endpos - startpos);
     }
@@ -2107,7 +2119,15 @@
 	  tem = overlay_heads.buf[i].string;
 	  bcopy (XSTRING (tem)->data, p, XSTRING (tem)->size);
 	  p += XSTRING (tem)->size;
+	  tem = overlay_heads.buf[i].string2;
+	  if (STRINGP (tem))
+	    {
+	      bcopy (XSTRING (tem)->data, p, XSTRING (tem)->size);
+	      p += XSTRING (tem)->size;
+	    }
 	}
+      if (p != overlay_str_buf + total)
+	abort ();
       if (pstr)
 	*pstr = overlay_str_buf;
       return total;