Reimplement terminal parameters in C; clean up term.c, create terminal.c.
[bpt/emacs.git] / src / frame.c
index 8d45ddc..c314062 100644 (file)
@@ -107,7 +107,7 @@ Lisp_Object Qtitle, Qname;
 Lisp_Object Qunsplittable;
 Lisp_Object Qmenu_bar_lines, Qtool_bar_lines;
 Lisp_Object Qleft_fringe, Qright_fringe;
-Lisp_Object Qbuffer_predicate, Qbuffer_list;
+Lisp_Object Qbuffer_predicate, Qbuffer_list, Qburied_buffer_list;
 Lisp_Object Qtty_color_mode;
 Lisp_Object Qtty, Qtty_type;
 Lisp_Object Qwindow_system;
@@ -303,6 +303,7 @@ make_frame (mini_p)
   f->menu_bar_items_used = 0;
   f->buffer_predicate = Qnil;
   f->buffer_list = Qnil;
+  f->buried_buffer_list = Qnil;
   f->namebuf = 0;
   f->title = Qnil;
   f->menu_bar_window = Qnil;
@@ -637,6 +638,33 @@ make_terminal_frame (struct device *device)
   return f;
 }
 
+/* Get a suitable value for frame parameter PARAMETER for a newly
+   created frame, based on (1) the user-supplied frame parameter
+   alist SUPPLIED_PARMS, (2) CURRENT_VALUE, and finally, if all else
+   fails, (3) Vdefault_frame_alist.  */
+
+static Lisp_Object
+get_future_frame_param (Lisp_Object parameter,
+                        Lisp_Object supplied_parms,
+                        char *current_value)
+{
+  Lisp_Object result;
+
+  result = Fassq (parameter, supplied_parms);
+  if (NILP (result))
+    result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
+  if (NILP (result) && current_value != NULL)
+    result = build_string (current_value);
+  if (NILP (result))
+    result = Fassq (parameter, Vdefault_frame_alist);
+  if (!NILP (result) && !STRINGP (result))
+    result = XCDR (result);
+  if (NILP (result) || !STRINGP (result))
+    result = Qnil;
+
+  return result;
+}
+
 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
        1, 1, 0,
        doc: /* Create an additional terminal frame, possibly on another terminal.
@@ -661,8 +689,6 @@ affects all frames on the same terminal device.  */)
   struct device *d = NULL;
   Lisp_Object frame, tem;
   struct frame *sf = SELECTED_FRAME ();
-  Lisp_Object tty, tty_type;
-  struct gcpro gcpro1, gcpro2;
 
 #ifdef MSDOS
   if (sf->output_method != output_msdos_raw
@@ -696,41 +722,24 @@ affects all frames on the same terminal device.  */)
   if (!d)
     { 
       char *name = 0, *type = 0;
+      Lisp_Object tty, tty_type;
 
-      tty = Fassq (Qtty, parms);
-      if (EQ (tty, Qnil))
-        tty = Fassq (Qtty, XFRAME (selected_frame)->param_alist);
-      if (EQ (tty, Qnil) && FRAME_TERMCAP_P (XFRAME (selected_frame))
-          && FRAME_TTY (XFRAME (selected_frame))->name)
-        tty = build_string (FRAME_TTY (XFRAME (selected_frame))->name);
-      if (EQ (tty, Qnil))
-        tty = Fassq (Qtty, Vdefault_frame_alist);
-      if (! EQ (tty, Qnil) && ! STRINGP (tty))
-        tty = XCDR (tty);
-      if (EQ (tty, Qnil) || !STRINGP (tty))
-        tty = Qnil;
-
-      tty_type = Fassq (Qtty_type, parms);
-      if (EQ (tty_type, Qnil))
-        tty_type = Fassq (Qtty_type, XFRAME (selected_frame)->param_alist);
-      if (EQ (tty_type, Qnil) && FRAME_TERMCAP_P (XFRAME (selected_frame))
-          && FRAME_TTY (XFRAME (selected_frame))->type)
-        tty_type = build_string (FRAME_TTY (XFRAME (selected_frame))->type);
-      if (EQ (tty_type, Qnil))
-        tty_type = Fassq (Qtty_type, Vdefault_frame_alist);
-      if (! EQ (tty_type, Qnil) && ! STRINGP (tty_type))
-        tty_type = XCDR (tty_type);
-      if (EQ (tty_type, Qnil) || !STRINGP (tty_type))
-        tty_type = Qnil;
-
-      if (! EQ (tty, Qnil))
+      tty = get_future_frame_param
+        (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
+                       ? FRAME_TTY (XFRAME (selected_frame))->name
+                       : NULL));
+      if (!NILP (tty))
         {
           name = (char *) alloca (SBYTES (tty) + 1);
           strncpy (name, SDATA (tty), SBYTES (tty));
           name[SBYTES (tty)] = 0;
         }
       
-      if (! EQ (tty_type, Qnil))
+      tty_type = get_future_frame_param
+        (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
+                            ? FRAME_TTY (XFRAME (selected_frame))->type
+                            : NULL));
+      if (!NILP (tty_type))
         {
           type = (char *) alloca (SBYTES (tty_type) + 1);
           strncpy (type, SDATA (tty_type), SBYTES (tty_type));
@@ -751,13 +760,15 @@ affects all frames on the same terminal device.  */)
   adjust_glyphs (f);
   calculate_costs (f);
   XSETFRAME (frame, f);
-  GCPRO2 (tty_type, tty);
   Fmodify_frame_parameters (frame, Vdefault_frame_alist);
   Fmodify_frame_parameters (frame, parms);
   Fmodify_frame_parameters (frame, Fcons (Fcons (Qwindow_system, Qnil), Qnil));
-  Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty_type, tty_type), Qnil));
-  Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty, tty), Qnil));
-  UNGCPRO;
+  Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty_type,
+                                                 build_string (d->display_info.tty->type)),
+                                          Qnil));
+  Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty,
+                                                 build_string (d->display_info.tty->name)),
+                                          Qnil));
   
   /* Make the frame face alist be frame-specific, so that each
      frame could change its face definitions independently.  */
@@ -2134,7 +2145,7 @@ set_frame_buffer_list (frame, list)
   XFRAME (frame)->buffer_list = list;
 }
 
-/* Discard BUFFER from the buffer-list of each frame.  */
+/* Discard BUFFER from the buffer-list and buried-buffer-list of each frame.  */
 
 void
 frames_discard_buffer (buffer)
@@ -2146,6 +2157,8 @@ frames_discard_buffer (buffer)
     {
       XFRAME (frame)->buffer_list
        = Fdelq (buffer, XFRAME (frame)->buffer_list);
+      XFRAME (frame)->buried_buffer_list
+        = Fdelq (buffer, XFRAME (frame)->buried_buffer_list);
     }
 }
 
@@ -2233,13 +2246,18 @@ store_frame_param (f, prop, val)
 {
   register Lisp_Object old_alist_elt;
 
-  /* The buffer-alist parameter is stored in a special place and is
-     not in the alist.  */
+  /* The buffer-list parameters are stored in a special place and not
+     in the alist.  */
   if (EQ (prop, Qbuffer_list))
     {
       f->buffer_list = val;
       return;
     }
+  if (EQ (prop, Qburied_buffer_list))
+    {
+      f->buried_buffer_list = val;
+      return;
+    }
 
   /* 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
@@ -2379,6 +2397,7 @@ If FRAME is omitted, return information on the currently selected frame.  */)
                   : 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 (frame));
+  store_in_alist (&alist, Qburied_buffer_list, XFRAME (frame)->buried_buffer_list);
 
   /* I think this should be done with a hook.  */
 #ifdef HAVE_WINDOW_SYSTEM
@@ -4199,6 +4218,8 @@ syms_of_frame ()
   staticpro (&Qbuffer_predicate);
   Qbuffer_list = intern ("buffer-list");
   staticpro (&Qbuffer_list);
+  Qburied_buffer_list = intern ("buried-buffer-list");
+  staticpro (&Qburied_buffer_list);
   Qdisplay_type = intern ("display-type");
   staticpro (&Qdisplay_type);
   Qbackground_mode = intern ("background-mode");