]> code.delx.au - gnu-emacs/blobdiff - src/xfaces.c
Merge from emacs-24
[gnu-emacs] / src / xfaces.c
index 9579bcce5727ad6f82e49f409a860300716c639a..6afa0a2953d9bc39790c922965b700fe2f71c59b 100644 (file)
@@ -273,10 +273,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #define IGNORE_DEFFACE_P(ATTR) EQ ((ATTR), QCignore_defface)
 
-/* Value is the number of elements of VECTOR.  */
-
-#define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
-
 /* Size of hash table of realized faces in face caches (should be a
    prime number).  */
 
@@ -515,7 +511,7 @@ DEFUN ("dump-colors", Fdump_colors, Sdump_colors, 0, 0, 0,
 
   fputc ('\n', stderr);
 
-  for (i = n = 0; i < sizeof color_count / sizeof color_count[0]; ++i)
+  for (i = n = 0; i < ARRAYELTS (color_count); ++i)
     if (color_count[i])
       {
        fprintf (stderr, "%3d: %5d", i, color_count[i]);
@@ -1072,7 +1068,7 @@ tty_color_name (struct frame *f, int idx)
        return XCAR (coldesc);
     }
 #ifdef MSDOS
-  /* We can have an MSDOG frame under -nw for a short window of
+  /* We can have an MS-DOS frame under -nw for a short window of
      opportunity before internal_terminal_init is called.  DTRT.  */
   if (FRAME_MSDOS_P (f) && !inhibit_window_system)
     return msdos_stdcolor_name (idx);
@@ -1242,9 +1238,6 @@ load_color2 (struct frame *f, struct face *face, Lisp_Object name,
    record that fact in flags of the face so that we don't try to free
    these colors.  */
 
-#ifndef MSDOS
-static
-#endif
 unsigned long
 load_color (struct frame *f, struct face *face, Lisp_Object name,
            enum lface_attribute_index target_index)
@@ -3122,10 +3115,9 @@ FRAME 0 means change the face on all frames, and change the default
 
               /* FIXME:
                  If frame is t, and selected frame is a tty frame, the font
-                 can't be realized.  An improvement wuld be to loop over frames
+                 can't be realized.  An improvement would be to loop over frames
                  for a non-tty frame and use that.  See discussion in
-                 bug#18573.
-              */
+                 bug#18573.  */
               if (f->terminal->type != output_termcap)
                 {
                   if (! FONT_OBJECT_P (value))
@@ -3415,7 +3407,8 @@ set_font_frame_param (Lisp_Object frame, Lisp_Object lface)
          ASET (lface, LFACE_FONT_INDEX, font);
        }
       f->default_face_done_p = 0;
-      Fmodify_frame_parameters (frame, list1 (Fcons (Qfont, font)));
+      AUTO_FRAME_ARG (arg, Qfont, font);
+      Fmodify_frame_parameters (frame, arg);
     }
 }
 
@@ -3804,18 +3797,23 @@ Default face attributes override any local face attributes.  */)
              && newface->font)
            {
              Lisp_Object name = newface->font->props[FONT_NAME_INDEX];
-             Fmodify_frame_parameters (frame, list1 (Fcons (Qfont, name)));
+             AUTO_FRAME_ARG (arg, Qfont, name);
+             Fmodify_frame_parameters (frame, arg);
            }
 
          if (STRINGP (gvec[LFACE_FOREGROUND_INDEX]))
-           Fmodify_frame_parameters (frame,
-                                     list1 (Fcons (Qforeground_color,
-                                                   gvec[LFACE_FOREGROUND_INDEX])));
+           {
+             AUTO_FRAME_ARG (arg, Qforeground_color,
+                             gvec[LFACE_FOREGROUND_INDEX]);
+             Fmodify_frame_parameters (frame, arg);
+           }
 
          if (STRINGP (gvec[LFACE_BACKGROUND_INDEX]))
-           Fmodify_frame_parameters (frame,
-                                     list1 (Fcons (Qbackground_color,
-                                                   gvec[LFACE_BACKGROUND_INDEX])));
+           {
+             AUTO_FRAME_ARG (arg, Qbackground_color,
+                             gvec[LFACE_BACKGROUND_INDEX]);
+             Fmodify_frame_parameters (frame, arg);
+           }
        }
     }
 
@@ -4105,15 +4103,15 @@ free_realized_face (struct frame *f, struct face *face)
     }
 }
 
+#ifdef HAVE_WINDOW_SYSTEM
 
-/* Prepare face FACE for subsequent display on frame F.  This
-   allocated GCs if they haven't been allocated yet or have been freed
-   by clearing the face cache.  */
+/* Prepare face FACE for subsequent display on frame F.  This must be called
+   before using X resources of FACE to allocate GCs if they haven't been
+   allocated yet or have been freed by clearing the face cache.  */
 
 void
 prepare_face_for_display (struct frame *f, struct face *face)
 {
-#ifdef HAVE_WINDOW_SYSTEM
   eassert (FRAME_WINDOW_P (f));
 
   if (face->gc == 0)
@@ -4141,10 +4139,10 @@ prepare_face_for_display (struct frame *f, struct face *face)
        font_prepare_for_face (f, face);
       unblock_input ();
     }
-#endif /* HAVE_WINDOW_SYSTEM */
 }
 
-\f
+#endif /* HAVE_WINDOW_SYSTEM */
+
 /* Returns the `distance' between the colors X and Y.  */
 
 static int
@@ -5093,14 +5091,14 @@ Value is ORDER.  */)
 {
   Lisp_Object list;
   int i;
-  int indices[DIM (font_sort_order)];
+  int indices[ARRAYELTS (font_sort_order)];
 
   CHECK_LIST (order);
   memset (indices, 0, sizeof indices);
   i = 0;
 
   for (list = order;
-       CONSP (list) && i < DIM (indices);
+       CONSP (list) && i < ARRAYELTS (indices);
        list = XCDR (list), ++i)
     {
       Lisp_Object attr = XCAR (list);
@@ -5122,9 +5120,9 @@ Value is ORDER.  */)
       indices[i] = xlfd;
     }
 
-  if (!NILP (list) || i != DIM (indices))
+  if (!NILP (list) || i != ARRAYELTS (indices))
     signal_error ("Invalid font sort order", order);
-  for (i = 0; i < DIM (font_sort_order); ++i)
+  for (i = 0; i < ARRAYELTS (font_sort_order); ++i)
     if (indices[i] == 0)
       signal_error ("Invalid font sort order", order);
 
@@ -5490,7 +5488,6 @@ realize_non_ascii_face (struct frame *f, Lisp_Object font_object,
   face = xmalloc (sizeof *face);
   *face = *base_face;
   face->gc = 0;
-  face->extra = NULL;
   face->overstrike
     = (! NILP (font_object)
        && FONT_WEIGHT_NAME_NUMERIC (face->lface[LFACE_WEIGHT_INDEX]) > 100
@@ -5565,7 +5562,7 @@ realize_x_face (struct face_cache *cache, Lisp_Object attrs[LFACE_VECTOR_SIZE])
        }
       if (! FONT_OBJECT_P (attrs[LFACE_FONT_INDEX]))
        attrs[LFACE_FONT_INDEX]
-         = font_load_for_lface (f, attrs, attrs[LFACE_FONT_INDEX]);
+         = font_load_for_lface (f, attrs, Ffont_spec (0, NULL));
       if (FONT_OBJECT_P (attrs[LFACE_FONT_INDEX]))
        {
          face->font = XFONT_OBJECT (attrs[LFACE_FONT_INDEX]);
@@ -5998,6 +5995,7 @@ face_at_buffer_position (struct window *w, ptrdiff_t pos,
     endpos = XINT (end);
 
   /* Look at properties from overlays.  */
+  USE_SAFE_ALLOCA;
   {
     ptrdiff_t next_overlay;
 
@@ -6024,7 +6022,10 @@ face_at_buffer_position (struct window *w, ptrdiff_t pos,
   /* Optimize common cases where we can use the default face.  */
   if (noverlays == 0
       && NILP (prop))
-    return default_face->id;
+    {
+      SAFE_FREE ();
+      return default_face->id;
+    }
 
   /* Begin with attributes from the default face.  */
   memcpy (attrs, default_face->lface, sizeof attrs);
@@ -6052,6 +6053,8 @@ face_at_buffer_position (struct window *w, ptrdiff_t pos,
 
   *endptr = endpos;
 
+  SAFE_FREE ();
+
   /* Look up a realized face with the given face attributes,
      or realize a new one for ASCII characters.  */
   return lookup_face (f, attrs);
@@ -6317,7 +6320,7 @@ dump_realized_face (struct face *face)
 {
   fprintf (stderr, "ID: %d\n", face->id);
 #ifdef HAVE_X_WINDOWS
-  fprintf (stderr, "gc: %ld\n", (long) face->gc);
+  fprintf (stderr, "gc: %p\n", face->gc);
 #endif
   fprintf (stderr, "foreground: 0x%lx (%s)\n",
           face->foreground,
@@ -6348,7 +6351,7 @@ DEFUN ("dump-face", Fdump_face, Sdump_face, 0, 1, 0, doc: /* */)
       int i;
 
       fprintf (stderr, "font selection order: ");
-      for (i = 0; i < DIM (font_sort_order); ++i)
+      for (i = 0; i < ARRAYELTS (font_sort_order); ++i)
        fprintf (stderr, "%d ", font_sort_order[i]);
       fprintf (stderr, "\n");