changeset 57270:bb98cba59362

Simplify last change. (lookup_fringe_bitmap): New function. (valid_fringe_bitmap_p, resolve_fringe_bitmap): Remove. (Fdestroy_fringe_bitmap): Use lookup_fringe_bitmap. Keep standard bitmaps in Vfringe_bitmaps. (Fdefine_fringe_bitmap): Use lookup_fringe_bitmap. (Fset_fringe_bitmap_face): Likewise.
author Kim F. Storm <storm@cua.dk>
date Wed, 29 Sep 2004 11:57:48 +0000
parents 3ff2bf32d84d
children 4d3c89d6b88d
files src/fringe.c
diffstat 1 files changed, 33 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/src/fringe.c	Wed Sep 29 11:57:34 2004 +0000
+++ b/src/fringe.c	Wed Sep 29 11:57:48 2004 +0000
@@ -450,22 +450,28 @@
 
 static int max_used_fringe_bitmap = MAX_STANDARD_FRINGE_BITMAPS;
 
-/* Return 1 if FRINGE_ID is a valid fringe bitmap id.  */
+
+/* Lookup bitmap number for symbol BITMAP.
+   Return 0 if not a bitmap.  */
 
 int
-valid_fringe_bitmap_p (bitmap)
+lookup_fringe_bitmap (bitmap)
      Lisp_Object bitmap;
 {
   int bn;
 
+  bitmap = Fget (bitmap, Qfringe);
   if (!INTEGERP (bitmap))
     return 0;
 
   bn = XINT (bitmap);
-  return (bn >= NO_FRINGE_BITMAP
-	  && bn < max_used_fringe_bitmap
-	  && (bn < MAX_STANDARD_FRINGE_BITMAPS
-	      || fringe_bitmaps[bn] != NULL));
+  if (bn > NO_FRINGE_BITMAP
+      && bn < max_used_fringe_bitmap
+      && (bn < MAX_STANDARD_FRINGE_BITMAPS
+	  || fringe_bitmaps[bn] != NULL))
+    return bn;
+
+  return 0;
 }
 
 /* Get fringe bitmap name for bitmap number BN.
@@ -501,42 +507,6 @@
 }
 
 
-/* Resolve a BITMAP parameter.
-
-   An INTEGER, corresponding to a bitmap number.
-   A STRING which is interned to a symbol.
-   A SYMBOL which has a fringe property which is a bitmap number.
-*/
-
-static int
-resolve_fringe_bitmap (bitmap, namep)
-     Lisp_Object bitmap;
-     Lisp_Object *namep;
-{
-  if (namep)
-    *namep = Qnil;
-
-  if (STRINGP (bitmap))
-    bitmap = intern (SDATA (bitmap));
-
-  if (SYMBOLP (bitmap))
-    {
-      if (namep)
-	*namep = bitmap;
-      bitmap = Fget (bitmap, Qfringe);
-    }
-
-  if (valid_fringe_bitmap_p (bitmap))
-    {
-      if (namep && NILP (*namep))
-	*namep = get_fringe_bitmap_name (XINT (bitmap));
-      return XINT (bitmap);
-    }
-
-  return -1;
-}
-
-
 /* Draw the bitmap WHICH in one of the left or right fringes of
    window W.  ROW is the glyph row for which to display the bitmap; it
    determines the vertical position at which the bitmap has to be
@@ -1068,7 +1038,9 @@
 }
 
 
-void
+/* Free resources used by a user-defined bitmap.  */
+
+int
 destroy_fringe_bitmap (n)
      int n;
 {
@@ -1099,20 +1071,21 @@
      Lisp_Object bitmap;
 {
   int n;
-  Lisp_Object sym;
 
-  n = resolve_fringe_bitmap (bitmap, &sym);
-  if (n < 0)
+  CHECK_SYMBOL (bitmap);
+  n = lookup_fringe_bitmap (bitmap);
+  if (!n)
     return Qnil;
 
   destroy_fringe_bitmap (n);
 
-  if (SYMBOLP (sym))
+  if (n >= MAX_STANDARD_FRINGE_BITMAPS)
     {
-      Vfringe_bitmaps = Fdelq (sym, Vfringe_bitmaps);
+      Vfringe_bitmaps = Fdelq (bitmap, Vfringe_bitmaps);
       /* It would be better to remove the fringe property.  */
-      Fput (sym, Qfringe, Qnil);
+      Fput (bitmap, Qfringe, Qnil);
     }
+
   return Qnil;
 }
 
@@ -1216,12 +1189,10 @@
   unsigned short *b;
   struct fringe_bitmap fb, *xfb;
   int fill1 = 0, fill2 = 0;
-  Lisp_Object sym;
 
-  n = resolve_fringe_bitmap (bitmap, &sym);
+  CHECK_SYMBOL (bitmap);
 
-  if (NILP (sym) || INTEGERP (sym))
-    sym = wrong_type_argument (Qsymbolp, bitmap);
+  n = lookup_fringe_bitmap (bitmap);
 
   if (!STRINGP (bits) && !VECTORP (bits))
     bits = wrong_type_argument (Qstringp, bits);
@@ -1274,7 +1245,7 @@
   else if (!NILP (align) && !EQ (align, Qcenter))
     error ("Bad align argument");
 
-  if (n < 0)
+  if (!n)
     {
       if (max_used_fringe_bitmap < MAX_FRINGE_BITMAPS)
 	n = max_used_fringe_bitmap++;
@@ -1289,8 +1260,8 @@
 	    error ("Cannot define more fringe bitmaps");
 	}
 
-      Vfringe_bitmaps = Fcons (sym, Vfringe_bitmaps);
-      Fput (sym, Qfringe, make_number (n));
+      Vfringe_bitmaps = Fcons (bitmap, Vfringe_bitmaps);
+      Fput (bitmap, Qfringe, make_number (n));
     }
 
   fb.dynamic = 1;
@@ -1318,7 +1289,7 @@
 
   init_fringe_bitmap (n, xfb, 0);
 
-  return sym;
+  return bitmap;
 }
 
 DEFUN ("set-fringe-bitmap-face", Fset_fringe_bitmap_face, Sset_fringe_bitmap_face,
@@ -1328,11 +1299,12 @@
   (bitmap, face)
      Lisp_Object bitmap, face;
 {
-  int bn;
+  int n;
   int face_id;
 
-  bn = resolve_fringe_bitmap (bitmap, 0);
-  if (bn < 0)
+  CHECK_SYMBOL (bitmap);
+  n = lookup_fringe_bitmap (bitmap);
+  if (!n)
     error ("Undefined fringe bitmap");
 
   if (!NILP (face))
@@ -1344,7 +1316,7 @@
   else
     face_id = FRINGE_FACE_ID;
 
-  fringe_faces [bn] = face_id;
+  fringe_faces[n] = face_id;
 
   return Qnil;
 }