]> code.delx.au - gnu-emacs/blobdiff - src/frame.c
(verify_interval_modification): Don't run
[gnu-emacs] / src / frame.c
index d356e6fcba019cdad5649f8c823d9c23687ee94c..4b5cb8ff0bdb0656cf0bf22a846abf7bd29b25e9 100644 (file)
@@ -1,5 +1,6 @@
 /* Generic frame functions.
-   Copyright (C) 1993, 1994, 1995, 1997, 1999 Free Software Foundation.
+   Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000, 2001
+   Free Software Foundation.
 
 This file is part of GNU Emacs.
 
@@ -29,6 +30,13 @@ Boston, MA 02111-1307, USA.  */
 #ifdef WINDOWSNT
 #include "w32term.h"
 #endif
+#ifdef macintosh
+#include "macterm.h"
+#endif
+#include "buffer.h"
+/* These help us bind and responding to switch-frame events.  */
+#include "commands.h"
+#include "keyboard.h"
 #include "frame.h"
 #ifdef HAVE_WINDOW_SYSTEM
 #include "fontset.h"
@@ -41,45 +49,6 @@ Boston, MA 02111-1307, USA.  */
 #include "dosfns.h"
 #endif
 
-#ifdef macintosh
-extern struct mac_output *NewMacWindow ();
-extern void DisposeMacWindow (struct mac_output *);
-#endif
-
-/* Evaluate this expression to rebuild the section of syms_of_frame
-   that initializes and staticpros the symbols declared below.  Note
-   that Emacs 18 has a bug that keeps C-x C-e from being able to
-   evaluate this expression.
-
-(progn
-  ;; Accumulate a list of the symbols we want to initialize from the
-  ;; declarations at the top of the file.
-  (goto-char (point-min))
-  (search-forward "/\*&&& symbols declared here &&&*\/\n")
-  (let (symbol-list)
-    (while (looking-at "Lisp_Object \\(Q[a-z_]+\\)")
-      (setq symbol-list
-           (cons (buffer-substring (match-beginning 1) (match-end 1))
-                 symbol-list))
-      (forward-line 1))
-    (setq symbol-list (nreverse symbol-list))
-    ;; Delete the section of syms_of_... where we initialize the symbols.
-    (search-forward "\n  /\*&&& init symbols here &&&*\/\n")
-    (let ((start (point)))
-      (while (looking-at "^  Q")
-       (forward-line 2))
-      (kill-region start (point)))
-    ;; Write a new symbol initialization section.
-    (while symbol-list
-      (insert (format "  %s = intern (\"" (car symbol-list)))
-      (let ((start (point)))
-       (insert (substring (car symbol-list) 1))
-       (subst-char-in-region start (point) ?_ ?-))
-      (insert (format "\");\n  staticpro (&%s);\n" (car symbol-list)))
-      (setq symbol-list (cdr symbol-list)))))
-  */        
-
-/*&&& symbols declared here &&&*/
 Lisp_Object Qframep;
 Lisp_Object Qframe_live_p;
 Lisp_Object Qheight;
@@ -100,68 +69,13 @@ Lisp_Object Qvisible;
 Lisp_Object Qbuffer_predicate;
 Lisp_Object Qbuffer_list;
 Lisp_Object Qtitle;
+Lisp_Object Qdisplay_type;
+Lisp_Object Qbackground_mode;
+Lisp_Object Qinhibit_default_face_x_resources;
 
 Lisp_Object Vterminal_frame;
 Lisp_Object Vdefault_frame_alist;
-
-static void
-syms_of_frame_1 ()
-{
-  /*&&& init symbols here &&&*/
-  Qframep = intern ("framep");
-  staticpro (&Qframep);
-  Qframe_live_p = intern ("frame-live-p");
-  staticpro (&Qframe_live_p);
-  Qheight = intern ("height");
-  staticpro (&Qheight);
-  Qicon = intern ("icon");
-  staticpro (&Qicon);
-  Qminibuffer = intern ("minibuffer");
-  staticpro (&Qminibuffer);
-  Qmodeline = intern ("modeline");
-  staticpro (&Qmodeline);
-  Qname = intern ("name");
-  staticpro (&Qname);
-  Qonly = intern ("only");
-  staticpro (&Qonly);
-  Qunsplittable = intern ("unsplittable");
-  staticpro (&Qunsplittable);
-  Qmenu_bar_lines = intern ("menu-bar-lines");
-  staticpro (&Qmenu_bar_lines);
-  Qtool_bar_lines = intern ("tool-bar-lines");
-  staticpro (&Qtool_bar_lines);
-  Qwidth = intern ("width");
-  staticpro (&Qwidth);
-  Qx = intern ("x");
-  staticpro (&Qx);
-  Qw32 = intern ("w32");
-  staticpro (&Qw32);
-  Qpc = intern ("pc");
-  staticpro (&Qpc);
-  Qmac = intern ("mac");
-  staticpro (&Qmac);
-  Qvisible = intern ("visible");
-  staticpro (&Qvisible);
-  Qbuffer_predicate = intern ("buffer-predicate");
-  staticpro (&Qbuffer_predicate);
-  Qbuffer_list = intern ("buffer-list");
-  staticpro (&Qbuffer_list);
-  Qtitle = intern ("title");
-  staticpro (&Qtitle);
-
-  DEFVAR_LISP ("default-frame-alist", &Vdefault_frame_alist,
-    "Alist of default values for frame creation.\n\
-These may be set in your init file, like this:\n\
-  (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1))\n\
-These override values given in window system configuration data,\n\
- including X Windows' defaults database.\n\
-For values specific to the first Emacs frame, see `initial-frame-alist'.\n\
-For values specific to the separate minibuffer frame, see\n\
- `minibuffer-frame-alist'.\n\
-The `menu-bar-lines' element of the list controls whether new frames\n\
- have menu bars; `menu-bar-mode' works by altering this element.");
-  Vdefault_frame_alist = Qnil;
-}
+Lisp_Object Vmouse_position_function;
 \f
 static void
 set_menu_bar_lines_1 (window, n)
@@ -173,6 +87,11 @@ set_menu_bar_lines_1 (window, n)
   XSETFASTINT (w->last_modified, 0);
   XSETFASTINT (w->top, XFASTINT (w->top) + n);
   XSETFASTINT (w->height, XFASTINT (w->height) - n);
+  
+  if (INTEGERP (w->orig_top))
+    XSETFASTINT (w->orig_top, XFASTINT (w->orig_top) + n);
+  if (INTEGERP (w->orig_height))
+    XSETFASTINT (w->orig_height, XFASTINT (w->orig_height) - n);
 
   /* Handle just the top child in a vertical split.  */
   if (!NILP (w->vchild))
@@ -216,12 +135,6 @@ set_menu_bar_lines (f, value, oldval)
     }
 }
 \f
-#include "buffer.h"
-
-/* These help us bind and responding to switch-frame events.  */
-#include "commands.h"
-#include "keyboard.h"
-
 Lisp_Object Vemacs_iconified;
 Lisp_Object Vframe_list;
 
@@ -286,14 +199,8 @@ make_frame (mini_p)
   register struct frame *f;
   register Lisp_Object root_window;
   register Lisp_Object mini_window;
-  register struct Lisp_Vector *vec;
-  int i;
-
-  vec = allocate_vectorlike ((EMACS_INT) VECSIZE (struct frame));
-  for (i = 0; i < VECSIZE (struct frame); i++)
-    XSETFASTINT (vec->contents[i], 0);
-  vec->size = VECSIZE (struct frame);
-  f = (struct frame *)vec;
+
+  f = allocate_frame ();
   XSETFRAME (frame, f);
 
   f->desired_matrix = 0;
@@ -334,9 +241,9 @@ make_frame (mini_p)
   f->title = Qnil;
   f->menu_bar_window = Qnil;
   f->tool_bar_window = Qnil;
-  f->desired_tool_bar_items = f->current_tool_bar_items = Qnil;
+  f->tool_bar_items = Qnil;
   f->desired_tool_bar_string = f->current_tool_bar_string = Qnil;
-  f->n_desired_tool_bar_items = f->n_current_tool_bar_items = 0;
+  f->n_tool_bar_items = 0;
 
   root_window = make_window ();
   if (mini_p)
@@ -411,10 +318,6 @@ make_frame (mini_p)
      a newly-created, never-selected window.  */
   XSETFASTINT (XWINDOW (f->selected_window)->use_time, ++window_select_count);
 
-#ifdef HAVE_WINDOW_SYSTEM
-  f->fontset_data = alloc_fontset_data ();
-#endif
-
   return f;
 }
 \f
@@ -555,30 +458,41 @@ make_terminal_frame ()
   if (!inhibit_window_system
       && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
          || XFRAME (selected_frame)->output_method == output_msdos_raw))
-    f->output_method = output_msdos_raw;
+    {
+      f->output_method = output_msdos_raw;
+      /* This initialization of foreground and background pixels is
+        only important for the initial frame created in temacs.  If
+        we don't do that, we get black background and foreground in
+        the dumped Emacs because the_only_x_display is a static
+        variable, hence it is born all-zeroes, and zero is the code
+        for the black color.  Other frames all inherit their pixels
+        from what's already in the_only_x_display.  */
+      if ((!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
+         && f->output_data.x->background_pixel == 0
+         && f->output_data.x->foreground_pixel == 0)
+       {
+         f->output_data.x->background_pixel = FACE_TTY_DEFAULT_BG_COLOR;
+         f->output_data.x->foreground_pixel = FACE_TTY_DEFAULT_FG_COLOR;
+       }
+    }
   else
     f->output_method = output_termcap;
 #else
+#ifdef WINDOWSNT
+  f->output_method = output_termcap;
+  f->output_data.x = &tty_display;
+#else
 #ifdef macintosh
-  f->output_data.mac = NewMacWindow(f);
-  f->output_data.mac->background_pixel = 0xffffff;
-  f->output_data.mac->foreground_pixel = 0;
-  f->output_data.mac->n_param_faces = 0;
-  f->output_data.mac->n_computed_faces = 0;
-  f->output_data.mac->size_computed_faces = 0;  
-  f->output_method = output_mac;
-  f->auto_raise = 1;
-  f->auto_lower = 1;
-  init_frame_faces (f);
-#else  /* !macintosh */
+  make_mac_terminal_frame (f);
+#else
   f->output_data.x = &tty_display;
-#endif /* !macintosh */
+#endif /* macintosh */
+#endif /* WINDOWSNT */
 #endif /* MSDOS */
 
-#ifndef macintosh
   if (!noninteractive)
     init_frame_faces (f);
-#endif
+
   return f;
 }
 
@@ -631,11 +545,25 @@ Note that changing the size of one terminal frame automatically affects all.")
     XCDR (XCAR (tem)) = Fcopy_sequence (XCDR (XCAR (tem)));
   return frame;
 }
+
 \f
+/* Perform the switch to frame FRAME.
+
+   If FRAME is a switch-frame event `(switch-frame FRAME1)', use
+   FRAME1 as frame.
+
+   If TRACK is non-zero and the frame that currently has the focus
+   redirects its focus to the selected frame, redirect that focused
+   frame's focus to FRAME instead.
+
+   FOR_DELETION non-zero means that the selected frame is being
+   deleted, which includes the possibility that the frame's display
+   is dead.  */
+
 Lisp_Object
-do_switch_frame (frame, no_enter, track)
-     Lisp_Object frame, no_enter;
-     int track;
+do_switch_frame (frame, track, for_deletion)
+     Lisp_Object frame;
+     int track, for_deletion;
 {
   struct frame *sf = SELECTED_FRAME ();
   
@@ -686,7 +614,7 @@ do_switch_frame (frame, no_enter, track)
 #else /* ! 0 */
   /* Instead, apply it only to the frame we're pointing to.  */
 #ifdef HAVE_WINDOW_SYSTEM
-  if (track && (FRAME_WINDOW_P (XFRAME (frame))))
+  if (track && FRAME_WINDOW_P (XFRAME (frame)))
     {
       Lisp_Object focus, xfocus;
 
@@ -701,6 +629,9 @@ do_switch_frame (frame, no_enter, track)
 #endif /* HAVE_X_WINDOWS */
 #endif /* ! 0 */
 
+  if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
+    resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
+
   selected_frame = frame;
   if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
     last_nonminibuf_frame = XFRAME (selected_frame);
@@ -727,7 +658,7 @@ function is called.")
   (frame, no_enter)
     Lisp_Object frame, no_enter;
 {
-  return do_switch_frame (frame, no_enter, 1);
+  return do_switch_frame (frame, 1, 0);
 }
 
 
@@ -746,7 +677,7 @@ to that frame.")
   /* Preserve prefix arg that the command loop just cleared.  */
   current_kboard->Vprefix_arg = Vcurrent_prefix_arg;
   call1 (Vrun_hooks, Qmouse_leave_buffer_hook);
-  return do_switch_frame (event, no_enter, 0);
+  return do_switch_frame (event, 0, 0);
 }
 
 DEFUN ("ignore-event", Fignore_event, Signore_event, 0, 0, "",
@@ -876,7 +807,13 @@ DEFUN ("frame-list", Fframe_list, Sframe_list,
        "Return a list of all frames.")
   ()
 {
-  return Fcopy_sequence (Vframe_list);
+  Lisp_Object frames;
+  frames = Fcopy_sequence (Vframe_list);
+#ifdef HAVE_WINDOW_SYSTEM
+  if (FRAMEP (tip_frame))
+    frames = Fdelq (tip_frame, frames);
+#endif
+  return frames;
 }
 
 /* Return the next frame in the frame list after FRAME.
@@ -932,7 +869,7 @@ next_frame (frame, minibuf)
                if (FRAME_VISIBLE_P (XFRAME (f)))
                  return f;
              }
-           else if (XFASTINT (minibuf) == 0)
+           else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
              {
                FRAME_SAMPLE_VISIBILITY (XFRAME (f));
                if (FRAME_VISIBLE_P (XFRAME (f))
@@ -942,11 +879,9 @@ next_frame (frame, minibuf)
            else if (WINDOWP (minibuf))
              {
                if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
-                   /* Check that F either is, or has forwarded its focus to,
-                      MINIBUF's frame.  */
-                   && (EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
-                       || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
-                              FRAME_FOCUS_FRAME (XFRAME (f)))))
+                   || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
+                   || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
+                          FRAME_FOCUS_FRAME (XFRAME (f))))
                  return f;
              }
            else
@@ -1002,11 +937,9 @@ prev_frame (frame, minibuf)
          else if (WINDOWP (minibuf))
            {
              if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
-                 /* Check that F either is, or has forwarded its focus to,
-                    MINIBUF's frame.  */
-                 && (EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
-                     || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
-                            FRAME_FOCUS_FRAME (XFRAME (f)))))
+                 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
+                 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
+                        FRAME_FOCUS_FRAME (XFRAME (f))))
                prev = f;
            }
          else if (EQ (minibuf, Qvisible))
@@ -1131,7 +1064,10 @@ DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
 If omitted, FRAME defaults to the selected frame.\n\
 A frame may not be deleted if its minibuffer is used by other frames.\n\
 Normally, you may not delete a frame if all other frames are invisible,\n\
-but if the second optional argument FORCE is non-nil, you may do so.")
+but if the second optional argument FORCE is non-nil, you may do so.\n\
+\n\
+This function runs `delete-frame-hook' before actually deleting the\n\
+frame.  The hook is called with one argument FRAME.")
   (frame, force)
      Lisp_Object frame, force;
 {
@@ -1153,7 +1089,13 @@ but if the second optional argument FORCE is non-nil, you may do so.")
   if (! FRAME_LIVE_P (f))
     return Qnil;
 
-  if (NILP (force) && !other_visible_frames (f))
+  if (NILP (force) && !other_visible_frames (f)
+#ifdef macintosh
+      /* Terminal frame deleted before any other visible frames are
+        created.  */
+      && strcmp (XSTRING (f->name)->data, "F1") != 0
+#endif
+     )
     error ("Attempt to delete the sole visible or iconified frame");
 
 #if 0
@@ -1184,6 +1126,15 @@ but if the second optional argument FORCE is non-nil, you may do so.")
        }
     }
 
+  /* Run `delete-frame-hook'.  */
+  if (!NILP (Vrun_hooks))
+    {
+      Lisp_Object args[2];
+      args[0] = intern ("delete-frame-hook");
+      args[1] = frame;
+      Frun_hook_with_args (2, args);
+    }
+
   minibuffer_selected = EQ (minibuf_window, selected_window);
 
   /* Don't let the frame remain selected.  */
@@ -1204,7 +1155,7 @@ but if the second optional argument FORCE is non-nil, you may do so.")
            }
        }
 
-      do_switch_frame (frame1, Qnil, 0);
+      do_switch_frame (frame1, 0, 1);
       sf = SELECTED_FRAME ();
     }
 
@@ -1221,6 +1172,10 @@ but if the second optional argument FORCE is non-nil, you may do so.")
        Fselect_window (minibuf_window);
     }
 
+  /* Don't let echo_area_window to remain on a deleted frame.  */
+  if (EQ (f->minibuffer_window, echo_area_window))
+    echo_area_window = sf->minibuffer_window;
+
   /* Clear any X selections for this frame.  */
 #ifdef HAVE_X_WINDOWS
   if (FRAME_X_P (f))
@@ -1254,11 +1209,6 @@ but if the second optional argument FORCE is non-nil, you may do so.")
   if (FRAME_MESSAGE_BUF (f))
     xfree (FRAME_MESSAGE_BUF (f));
 
-#ifdef HAVE_WINDOW_SYSTEM
-  /* Free all fontset data.  */
-  free_fontset_data (FRAME_FONTSET_DATA (f));
-#endif
-
   /* Since some events are handled at the interrupt level, we may get
      an event for f at any time; if we zero out the frame's display
      now, then we may trip up the event-handling code.  Instead, we'll
@@ -1271,14 +1221,6 @@ but if the second optional argument FORCE is non-nil, you may do so.")
     x_destroy_window (f);
 #endif
 
-/* Done by x_destroy_window above already */
-#if 0
-#ifdef macintosh
-  if (FRAME_MAC_P (f))
-    DisposeMacWindow (f->output_data.mac);
-#endif
-#endif
-
   f->output_data.nothing = 0;
 
   /* If we've deleted the last_nonminibuf_frame, then try to find
@@ -1375,15 +1317,19 @@ The position is given in character cells, where (0, 0) is the\n\
 upper-left corner.\n\
 If Emacs is running on a mouseless terminal or hasn't been programmed\n\
 to read the mouse position, it returns the selected frame for FRAME\n\
-and nil for X and Y.")
+and nil for X and Y.\n\
+If `mouse-position-function' is non-nil, `mouse-position' calls it,\n\
+passing the normal return value to that function as an argument,\n\
+and returns whatever that function returns.")
   ()
 {
   FRAME_PTR f;
   Lisp_Object lispy_dummy;
   enum scroll_bar_part party_dummy;
-  Lisp_Object x, y;
+  Lisp_Object x, y, retval;
   int col, row;
   unsigned long long_dummy;
+  struct gcpro gcpro1;
 
   f = SELECTED_FRAME ();
   x = y = Qnil;
@@ -1405,7 +1351,11 @@ and nil for X and Y.")
     }
 #endif
   XSETFRAME (lispy_dummy, f);
-  return Fcons (lispy_dummy, Fcons (x, y));
+  retval = Fcons (lispy_dummy, Fcons (x, y));
+  GCPRO1 (retval);
+  if (!NILP (Vmouse_position_function))
+    retval = call1 (Vmouse_position_function, retval);
+  RETURN_UNGCPRO (retval);
 }
 
 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
@@ -1580,7 +1530,7 @@ but if the second optional argument FORCE is non-nil, you may do so.")
 #if 0 /* This isn't logically necessary, and it can do GC.  */
   /* Don't let the frame remain selected.  */
   if (EQ (frame, selected_frame))
-    do_switch_frame (next_frame (frame, Qt), Qnil, 0)
+    do_switch_frame (next_frame (frame, Qt), 0, 0)
 #endif
 
   /* Don't allow minibuf_window to remain on a deleted frame.  */
@@ -1856,9 +1806,13 @@ frames_bury_buffer (buffer)
 
   FOR_EACH_FRAME (tail, frame)
     {
-      XFRAME (frame)->buffer_list
-       = nconc2 (Fdelq (buffer, XFRAME (frame)->buffer_list),
-                 Fcons (buffer, Qnil));
+      struct frame *f = XFRAME (frame);
+      Lisp_Object found;
+      
+      found = Fmemq (buffer, f->buffer_list);
+      if (!NILP (found))
+       f->buffer_list = nconc2 (Fdelq (buffer, f->buffer_list),
+                                Fcons (buffer, Qnil));
     }
 }
 
@@ -1944,20 +1898,41 @@ store_frame_param (f, prop, val)
      struct frame *f;
      Lisp_Object prop, val;
 {
-  register Lisp_Object tem;
+  register Lisp_Object old_alist_elt;
 
+  /* The buffer-alist parameter is stored in a special place and is
+     not in the alist.  */
   if (EQ (prop, Qbuffer_list))
     {
       f->buffer_list = val;
       return;
     }
 
-  tem = Fassq (prop, f->param_alist);
-  if (EQ (tem, Qnil))
+  /* If PROP is a symbol which is supposed to have frame-local values,
+     and it is set up based on this frame, switch to the global
+     binding.  That way, we can create or alter the frame-local binding
+     without messing up the symbol's status.  */
+  if (SYMBOLP (prop))
+    {
+      Lisp_Object valcontents;
+      valcontents = XSYMBOL (prop)->value;
+      if ((BUFFER_LOCAL_VALUEP (valcontents)
+          || SOME_BUFFER_LOCAL_VALUEP (valcontents))
+         && XBUFFER_LOCAL_VALUE (valcontents)->check_frame
+         && XFRAME (XBUFFER_LOCAL_VALUE (valcontents)->frame) == f)
+       swap_in_global_binding (prop);
+    }
+
+  /* Update the frame parameter alist.  */
+  old_alist_elt = Fassq (prop, f->param_alist);
+  if (EQ (old_alist_elt, Qnil))
     f->param_alist = Fcons (Fcons (prop, val), f->param_alist);
   else
-    Fsetcdr (tem, val);
+    Fsetcdr (old_alist_elt, val);
 
+  /* Update some other special parameters in their special places
+     in addition to the alist.  */
+  
   if (EQ (prop, Qbuffer_predicate))
     f->buffer_predicate = val;
 
@@ -1996,7 +1971,7 @@ If FRAME is omitted, return information on the currently selected frame.")
   int height, width;
   struct gcpro gcpro1;
 
-  if (EQ (frame, Qnil))
+  if (NILP (frame))
     frame = selected_frame;
 
   CHECK_FRAME (frame, 0);
@@ -2012,15 +1987,44 @@ If FRAME is omitted, return information on the currently selected frame.")
     {
       int fg = FRAME_FOREGROUND_PIXEL (f);
       int bg = FRAME_BACKGROUND_PIXEL (f);
+      Lisp_Object elt;
 
-      store_in_alist (&alist, intern ("foreground-color"),
-                     tty_color_name (f, fg));
-      store_in_alist (&alist, intern ("background-color"),
-                     tty_color_name (f, bg));
+      /* If the frame's parameter alist says the colors are
+        unspecified and reversed, take the frame's background pixel
+        for foreground and vice versa.  */
+      elt = Fassq (Qforeground_color, alist);
+      if (!NILP (elt) && CONSP (elt) && STRINGP (XCDR (elt)))
+       {
+         if (strncmp (XSTRING (XCDR (elt))->data,
+                      unspecified_bg,
+                      XSTRING (XCDR (elt))->size) == 0)
+           store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
+         else if (strncmp (XSTRING (XCDR (elt))->data,
+                           unspecified_fg,
+                           XSTRING (XCDR (elt))->size) == 0)
+           store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
+       }
+      else
+       store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
+      elt = Fassq (Qbackground_color, alist);
+      if (!NILP (elt) && CONSP (elt) && STRINGP (XCDR (elt)))
+       {
+         if (strncmp (XSTRING (XCDR (elt))->data,
+                      unspecified_fg,
+                      XSTRING (XCDR (elt))->size) == 0)
+           store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
+         else if (strncmp (XSTRING (XCDR (elt))->data,
+                           unspecified_bg,
+                           XSTRING (XCDR (elt))->size) == 0)
+           store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
+       }
+      else
+       store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
       store_in_alist (&alist, intern ("font"),
                      build_string (FRAME_MSDOS_P (f)
                                    ? "ms-dos"
-                                   : FRAME_W32_P (f) ? "w32term" : "tty"));
+                                   : FRAME_W32_P (f) ? "w32term"
+                                   :"tty"));
     }
   store_in_alist (&alist, Qname, f->name);
   height = (FRAME_NEW_HEIGHT (f) ? FRAME_NEW_HEIGHT (f) : FRAME_HEIGHT (f));
@@ -2033,8 +2037,7 @@ If FRAME is omitted, return information on the currently selected frame.")
                   : FRAME_MINIBUF_ONLY_P (f) ? Qonly
                   : FRAME_MINIBUF_WINDOW (f)));
   store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
-  store_in_alist (&alist, Qbuffer_list,
-                 frame_buffer_list (selected_frame));
+  store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame));
 
   /* I think this should be done with a hook.  */
 #ifdef HAVE_WINDOW_SYSTEM
@@ -2053,19 +2056,108 @@ If FRAME is omitted, return information on the currently selected frame.")
   return alist;
 }
 
+
+DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
+   "Return FRAME's value for parameter PARAMETER.\n\
+If FRAME is nil, describe the currently selected frame.")
+  (frame, parameter)
+       Lisp_Object frame, parameter;
+{
+  struct frame *f;
+  Lisp_Object value;
+
+  if (NILP (frame))
+    frame = selected_frame;
+  else
+    CHECK_FRAME (frame, 0);
+  CHECK_SYMBOL (parameter, 1);
+  
+  f = XFRAME (frame);
+  value = Qnil;
+  
+  if (FRAME_LIVE_P (f))
+    {
+      if (EQ (parameter, Qname))
+       value = f->name;
+#ifdef HAVE_X_WINDOWS
+      else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
+       value = XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element);
+#endif /* HAVE_X_WINDOWS */
+      else
+       {
+         value = Fassq (parameter, f->param_alist);
+         if (CONSP (value))
+           {
+             value = XCDR (value);
+             /* Fframe_parameters puts the actual fg/bg color names,
+                even if f->param_alist says otherwise.  This is
+                important when param_alist's notion of colors is
+                "unspecified".  We need to do the same here.  */
+             if (STRINGP (value) && !FRAME_WINDOW_P (f))
+               {
+                 char *color_name;
+                 EMACS_INT csz;
+
+                 if (EQ (parameter, Qbackground_color))
+                   {
+                     color_name = XSTRING (value)->data;
+                     csz = XSTRING (value)->size;
+                     if (strncmp (color_name, unspecified_bg, csz) == 0)
+                       value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
+                     else if (strncmp (color_name, unspecified_fg, csz) == 0)
+                       value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
+                   }
+                 else if (EQ (parameter, Qforeground_color))
+                   {
+                     color_name = XSTRING (value)->data;
+                     csz = XSTRING (value)->size;
+                     if (strncmp (color_name, unspecified_fg, csz) == 0)
+                       value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
+                     else if (strncmp (color_name, unspecified_bg, csz) == 0)
+                       value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
+                   }
+               }
+           }
+         else if (EQ (parameter, Qdisplay_type)
+                  || EQ (parameter, Qbackground_mode))
+           /* Avoid consing in frequent cases.  */
+           value = Qnil;
+         else
+           value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
+       }
+    }
+  
+  return value;
+}
+
+
 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters, 
        Smodify_frame_parameters, 2, 2, 0,
   "Modify the parameters of frame FRAME according to ALIST.\n\
+If FRAME is nil, it defaults to the selected frame.\n\
 ALIST is an alist of parameters to change and their new values.\n\
 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.\n\
 The meaningful PARMs depend on the kind of frame.\n\
 Undefined PARMs are ignored, but stored in the frame's parameter list\n\
-so that `frame-parameters' will return them.")
+so that `frame-parameters' will return them.\n\
+\n\
+The value of frame parameter FOO can also be accessed\n\
+as a frame-local binding for the variable FOO, if you have\n\
+enabled such bindings for that variable with `make-variable-frame-local'.")
   (frame, alist)
      Lisp_Object frame, alist;
 {
   FRAME_PTR f;
   register Lisp_Object tail, prop, val;
+  int count = BINDING_STACK_SIZE ();
+
+  /* Bind this to t to inhibit initialization of the default face from
+     X resources in face-set-after-frame-default.  If we don't inhibit
+     this, modifying the `font' frame parameter, for example, while
+     there is a `default.attributeFont' X resource, won't work,
+     because `default's font is reset to the value of the X resource
+     and that resets the `font' frame parameter.  */
+  specbind (Qinhibit_default_face_x_resources, Qt);
 
   if (EQ (frame, Qnil))
     frame = selected_frame;
@@ -2083,11 +2175,6 @@ so that `frame-parameters' will return them.")
     IT_set_frame_parameters (f, alist);
   else
 #endif
-#ifdef macintosh
-  if (FRAME_MAC_P (f))
-    mac_set_frame_parameters (f, alist);
-  else
-#endif
 
     {
       int length = XINT (Flength (alist));
@@ -2119,7 +2206,7 @@ so that `frame-parameters' will return them.")
        }
     }
 
-  return Qnil;
+  return unbind_to (count, Qnil);
 }
 \f
 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
@@ -2333,9 +2420,67 @@ the rightmost or bottommost possible position (that stays within the screen).")
 void
 syms_of_frame ()
 {
-  syms_of_frame_1 ();
+  Qframep = intern ("framep");
+  staticpro (&Qframep);
+  Qframe_live_p = intern ("frame-live-p");
+  staticpro (&Qframe_live_p);
+  Qheight = intern ("height");
+  staticpro (&Qheight);
+  Qicon = intern ("icon");
+  staticpro (&Qicon);
+  Qminibuffer = intern ("minibuffer");
+  staticpro (&Qminibuffer);
+  Qmodeline = intern ("modeline");
+  staticpro (&Qmodeline);
+  Qname = intern ("name");
+  staticpro (&Qname);
+  Qonly = intern ("only");
+  staticpro (&Qonly);
+  Qunsplittable = intern ("unsplittable");
+  staticpro (&Qunsplittable);
+  Qmenu_bar_lines = intern ("menu-bar-lines");
+  staticpro (&Qmenu_bar_lines);
+  Qtool_bar_lines = intern ("tool-bar-lines");
+  staticpro (&Qtool_bar_lines);
+  Qwidth = intern ("width");
+  staticpro (&Qwidth);
+  Qx = intern ("x");
+  staticpro (&Qx);
+  Qw32 = intern ("w32");
+  staticpro (&Qw32);
+  Qpc = intern ("pc");
+  staticpro (&Qpc);
+  Qmac = intern ("mac");
+  staticpro (&Qmac);
+  Qvisible = intern ("visible");
+  staticpro (&Qvisible);
+  Qbuffer_predicate = intern ("buffer-predicate");
+  staticpro (&Qbuffer_predicate);
+  Qbuffer_list = intern ("buffer-list");
+  staticpro (&Qbuffer_list);
+  Qtitle = intern ("title");
+  staticpro (&Qtitle);
+  Qdisplay_type = intern ("display-type");
+  staticpro (&Qdisplay_type);
+  Qbackground_mode = intern ("background-mode");
+  staticpro (&Qbackground_mode);
 
-  staticpro (&Vframe_list);
+  DEFVAR_LISP ("default-frame-alist", &Vdefault_frame_alist,
+    "Alist of default values for frame creation.\n\
+These may be set in your init file, like this:\n\
+  (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1))\n\
+These override values given in window system configuration data,\n\
+ including X Windows' defaults database.\n\
+For values specific to the first Emacs frame, see `initial-frame-alist'.\n\
+For values specific to the separate minibuffer frame, see\n\
+ `minibuffer-frame-alist'.\n\
+The `menu-bar-lines' element of the list controls whether new frames\n\
+ have menu bars; `menu-bar-mode' works by altering this element.");
+  Vdefault_frame_alist = Qnil;
+
+  Qinhibit_default_face_x_resources
+    = intern ("inhibit-default-face-x-resources");
+  staticpro (&Qinhibit_default_face_x_resources);
 
   DEFVAR_LISP ("terminal-frame", &Vterminal_frame,
     "The initial frame-object, which represents Emacs's stdout.");
@@ -2344,6 +2489,14 @@ syms_of_frame ()
     "Non-nil if all of emacs is iconified and frame updates are not needed.");
   Vemacs_iconified = Qnil;
 
+  DEFVAR_LISP ("mouse-position-function", &Vmouse_position_function,
+    "If non-nil, function to transform normal value of `mouse-position'.\n\
+`mouse-position' calls this function, passing its usual return value as\n\
+argument, and returns whatever this function returns.\n\
+This abnormal hook exists for the benefit of packages like `xt-mouse.el'\n\
+which need to do mouse handling at the Lisp level.");
+  Vmouse_position_function = Qnil;
+
   DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
     "Minibufferless frames use this frame's minibuffer.\n\
 \n\
@@ -2357,6 +2510,8 @@ this variable doesn't necessarily say anything meaningful about the\n\
 current set of frames, or where the minibuffer is currently being\n\
 displayed.");
 
+  staticpro (&Vframe_list);
+
   defsubr (&Sactive_minibuffer_window);
   defsubr (&Sframep);
   defsubr (&Sframe_live_p);
@@ -2392,6 +2547,7 @@ displayed.");
   defsubr (&Sredirect_frame_focus);
   defsubr (&Sframe_focus);
   defsubr (&Sframe_parameters);
+  defsubr (&Sframe_parameter);
   defsubr (&Smodify_frame_parameters);
   defsubr (&Sframe_char_height);
   defsubr (&Sframe_char_width);