(Freplace_match): New arg SUBEXP.
[bpt/emacs.git] / src / xfaces.c
index 36c3c1a..b2c410d 100644 (file)
@@ -87,13 +87,13 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
    (assq FACE-NAME global-face-data) returns a vector describing the
    global parameters for that face.
 
-   Let PARAM-FACE be FRAME->display.x->param_faces[Faref (FACE-VECTOR, 2)].
+   Let PARAM-FACE be FRAME->output_data.x->param_faces[Faref (FACE-VECTOR, 2)].
    PARAM_FACE is a struct face whose members are the Xlib analogues of
    the parameters in FACE-VECTOR.  If an element of FACE-VECTOR is
    nil, then the corresponding member of PARAM_FACE is FACE_DEFAULT.
    These faces are called "parameter faces", because they're the ones
    lisp manipulates to control what gets displayed.  Elements 0 and 1
-   of FRAME->display.x->param_faces are special - they describe the
+   of FRAME->output_data.x->param_faces are special - they describe the
    default and mode line faces.  None of the faces in param_faces have
    GC's.  (See src/dispextern.h for the definiton of struct face.
    lisp/faces.el maintains the isomorphism between face_alist and
@@ -104,9 +104,9 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
    properties.  The resulting faces are called "computed faces"; none
    of their members are FACE_DEFAULT; they are completely specified.
    They then call intern_compute_face to search
-   FRAME->display.x->computed_faces for a matching face, add one if
+   FRAME->output_data.x->computed_faces for a matching face, add one if
    none is found, and return the index into
-   FRAME->display.x->computed_faces.  FRAME's glyph matrices use these
+   FRAME->output_data.x->computed_faces.  FRAME's glyph matrices use these
    indices to record the faces of the matrix characters, and the X
    display hooks consult compute_faces to decide how to display these
    characters.  Elements 0 and 1 of computed_faces always describe the
@@ -145,10 +145,10 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 /* Definitions and declarations.  */
 
 /* The number of face-id's in use (same for all frames).  */
-int next_face_id;
+static int next_face_id;
 
 /* The number of the face to use to indicate the region.  */
-int region_face;
+static int region_face;
 
 /* This is what appears in a slot in a face to signify that the face
    does not specify that display aspect.  */
@@ -231,17 +231,17 @@ intern_face (f, face)
   if (face->foreground != FACE_DEFAULT)
     xgcv.foreground = face->foreground;
   else
-    xgcv.foreground = f->display.x->foreground_pixel;
+    xgcv.foreground = f->output_data.x->foreground_pixel;
 
   if (face->background != FACE_DEFAULT)
     xgcv.background = face->background;
   else
-    xgcv.background = f->display.x->background_pixel;
+    xgcv.background = f->output_data.x->background_pixel;
 
-  if (face->font && (int) face->font != FACE_DEFAULT)
+  if (face->font && face->font != (XFontStruct *) FACE_DEFAULT)
     xgcv.font = face->font->fid;
   else
-    xgcv.font = f->display.x->font->fid;
+    xgcv.font = f->output_data.x->font->fid;
 
   xgcv.graphics_exposures = 0;
 
@@ -340,29 +340,19 @@ load_color (f, name)
      struct frame *f;
      Lisp_Object name;
 {
-  Display *dpy = FRAME_X_DISPLAY (f);
-  Colormap cmap;
   XColor color;
   int result;
 
   if (NILP (name))
     return FACE_DEFAULT;
 
-  cmap = DefaultColormapOfScreen (DefaultScreenOfDisplay (dpy));
-
   CHECK_STRING (name, 0);
-  BLOCK_INPUT;
-  result = XParseColor (dpy, cmap, (char *) XSTRING (name)->data, &color);
-  UNBLOCK_INPUT;
+  /* if the colormap is full, defined_color will return a best match
+     to the values in an an existing cell. */
+  result = defined_color(f, (char *) XSTRING (name)->data, &color, 1);
   if (! result)
     Fsignal (Qerror, Fcons (build_string ("undefined color"),
                            Fcons (name, Qnil)));
-  BLOCK_INPUT;
-  result = XAllocColor (dpy, cmap, &color);
-  UNBLOCK_INPUT;
-  if (! result)
-    Fsignal (Qerror, Fcons (build_string ("X server cannot allocate color"),
-                           Fcons (name, Qnil)));
   return (unsigned long) color.pixel;
 }
 
@@ -373,14 +363,22 @@ unload_color (f, pixel)
 {
   Colormap cmap;
   Display *dpy = FRAME_X_DISPLAY (f);
+  int class = FRAME_X_DISPLAY_INFO (f)->visual->class;
+
   if (pixel == FACE_DEFAULT
       || pixel == BLACK_PIX_DEFAULT (f)
       || pixel == WHITE_PIX_DEFAULT (f))
     return;
   cmap = DefaultColormapOfScreen (DefaultScreenOfDisplay (dpy));
-  BLOCK_INPUT;
-  XFreeColors (dpy, cmap, &pixel, 1, 0);
-  UNBLOCK_INPUT;
+  
+  /* If display has an immutable color map, freeing colors is not
+     necessary and some servers don't allow it.  So don't do it.  */
+  if (! (class == StaticColor || class == StaticGray || class == TrueColor))
+    {
+      BLOCK_INPUT;
+      XFreeColors (dpy, cmap, &pixel, 1, (unsigned long)0);
+      UNBLOCK_INPUT;
+    }
 }
 
 DEFUN ("pixmap-spec-p", Fpixmap_spec_p, Spixmap_spec_p, 1, 1, 0,
@@ -480,14 +478,6 @@ clear_face_cache ()
   /* No action.  */
 }
 
-static void
-build_face (f, face)
-     struct frame *f;
-     struct face *face;
-{
-  face->gc = 1;
-}
-
 #ifdef MSDOS
 unsigned long
 load_color (f, name)
@@ -709,21 +699,21 @@ frame_update_line_height (f)
      FRAME_PTR f;
 {
   int i;
-  int biggest = FONT_HEIGHT (f->display.x->font);
+  int biggest = FONT_HEIGHT (f->output_data.x->font);
 
-  for (i = 0; i < f->display.x->n_param_faces; i++)
-    if (f->display.x->param_faces[i] != 0
-       && f->display.x->param_faces[i]->font != (XFontStruct *) FACE_DEFAULT)
+  for (i = 0; i < f->output_data.x->n_param_faces; i++)
+    if (f->output_data.x->param_faces[i] != 0
+       && f->output_data.x->param_faces[i]->font != (XFontStruct *) FACE_DEFAULT)
       {
-       int height = FONT_HEIGHT (f->display.x->param_faces[i]->font);
+       int height = FONT_HEIGHT (f->output_data.x->param_faces[i]->font);
        if (height > biggest)
          biggest = height;
       }
 
-  if (biggest == f->display.x->line_height)
+  if (biggest == f->output_data.x->line_height)
     return 0;
 
-  f->display.x->line_height = biggest;
+  f->output_data.x->line_height = biggest;
   return 1;
 }
 #endif /* not HAVE_X_WINDOWS */
@@ -884,7 +874,8 @@ compute_char_face (f, w, pos, region_beg, region_end, endptr, limit, mouse)
     len = 40;
     overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object));
     
-    noverlays = overlays_at (pos, 0, &overlay_vec, &len, &next_overlay, NULL);
+    noverlays = overlays_at (pos, 0, &overlay_vec, &len,
+                            &next_overlay, (int *) 0);
 
     /* If there are more than 40,
        make enough space for all, and try again.  */
@@ -893,7 +884,7 @@ compute_char_face (f, w, pos, region_beg, region_end, endptr, limit, mouse)
        len = noverlays;
        overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object));
        noverlays = overlays_at (pos, 0, &overlay_vec, &len,
-                                &next_overlay, NULL);
+                                &next_overlay, (int *) 0);
       }
 
     if (next_overlay < endpos)
@@ -912,10 +903,13 @@ compute_char_face (f, w, pos, region_beg, region_end, endptr, limit, mouse)
   if (CONSP (prop))
     {
       /* We have a list of faces, merge them in reverse order */
-      Lisp_Object length = Flength (prop);
-      int len = XINT (length);
+      Lisp_Object length;
+      int len;
       Lisp_Object *faces;
 
+      length = Fsafe_length (prop);
+      len = XFASTINT (length);
+
       /* Put them into an array */
       faces = (Lisp_Object *) alloca (len * sizeof (Lisp_Object));
       for (j = 0; j < len; j++)
@@ -949,10 +943,12 @@ compute_char_face (f, w, pos, region_beg, region_end, endptr, limit, mouse)
       if (CONSP (prop))
        {
          /* We have a list of faces, merge them in reverse order */
-         Lisp_Object length = Flength (prop);
-         int len = XINT (length);
+         Lisp_Object length;
+         int len;
          Lisp_Object *faces;
-         int i;
+
+         length = Fsafe_length (prop);
+         len = XFASTINT (length);
 
          /* Put them into an array */
          faces = (Lisp_Object *) alloca (len * sizeof (Lisp_Object));
@@ -1109,7 +1105,7 @@ DEFUN ("set-face-attribute-internal", Fset_face_attribute_internal,
       face->font = 0; /* The one and only font.  */
 #else
       XFontStruct *font = load_font (f, attr_value);
-      if (face->font != f->display.x->font)
+      if (face->font != f->output_data.x->font)
        unload_font (f, face->font);
       face->font = font;
       if (frame_update_line_height (f))