(syms_of_window): Fix missing \n\.
[bpt/emacs.git] / src / window.c
index 4cc0356..f9c8fe9 100644 (file)
@@ -88,6 +88,15 @@ Lisp_Object Vspecial_display_regexps;
 /* Function to pop up a special frame.  */
 Lisp_Object Vspecial_display_function;
 
+/* List of buffer *names* for buffers to appear in selected window.  */
+Lisp_Object Vsame_window_buffer_names;
+
+/* List of regexps for buffer names to appear in selected window.  */
+Lisp_Object Vsame_window_regexps;
+
+/* Hook run at end of temp_output_buffer_show.  */
+Lisp_Object Qtemp_buffer_show_hook;
+
 /* Fdisplay_buffer always splits the largest window 
    if that window is more than this high.  */
 int split_height_threshold;
@@ -119,29 +128,31 @@ DEFUN ("window-live-p", Fwindow_live_p, Swindow_live_p, 1, 1, 0,
 Lisp_Object
 make_window ()
 {
-  register Lisp_Object val;
+  Lisp_Object val;
   register struct window *p;
-
-  /* Add sizeof (Lisp_Object) here because sizeof (struct Lisp_Vector)
-     includes the first element.  */
-  val = Fmake_vector (
-    make_number ((sizeof (struct window) - sizeof (struct Lisp_Vector)
-                 + sizeof (Lisp_Object))
-                / sizeof (Lisp_Object)),
-    Qnil);
-  XSETTYPE (val, Lisp_Window);
-  p = XWINDOW (val);
-  XFASTINT (p->sequence_number) = ++sequence_number;
-  XFASTINT (p->left) = XFASTINT (p->top)
-    = XFASTINT (p->height) = XFASTINT (p->width)
-      = XFASTINT (p->hscroll) = 0;
-  XFASTINT (p->last_point_x) = XFASTINT (p->last_point_y) = 0;
+  register struct Lisp_Vector *vec;
+  int i;
+
+  vec = allocate_vectorlike ((EMACS_INT) VECSIZE (struct window));
+  for (i = 0; i < VECSIZE (struct window); i++)
+    vec->contents[i] = Qnil;
+  vec->size = VECSIZE (struct window);
+  p = (struct window *)vec;
+  XSETFASTINT (p->sequence_number, ++sequence_number);
+  XSETFASTINT (p->left, 0);
+  XSETFASTINT (p->top, 0);
+  XSETFASTINT (p->height, 0);
+  XSETFASTINT (p->width, 0);
+  XSETFASTINT (p->hscroll, 0);
+  XSETFASTINT (p->last_point_x, 0);
+  XSETFASTINT (p->last_point_y, 0);
   p->start = Fmake_marker ();
   p->pointm = Fmake_marker ();
-  XFASTINT (p->use_time) = 0;
+  XSETFASTINT (p->use_time, 0);
   p->frame = Qnil;
   p->display_table = Qnil;
   p->dedicated = Qnil;
+  XSETWINDOW (val, p);
   return val;
 }
 
@@ -295,7 +306,7 @@ NCOL should be zero or positive.")
   register struct window *w;
 
   CHECK_NUMBER (ncol, 1);
-  if (XINT (ncol) < 0) XFASTINT (ncol) = 0;
+  if (XINT (ncol) < 0) XSETFASTINT (ncol, 0);
   if (XFASTINT (ncol) >= (1 << (SHORTBITS - 1)))
     args_out_of_range (ncol, Qnil);
   w = decode_window (window);
@@ -560,7 +571,7 @@ from overriding motion of point in order to display at this exact start.")
   if (NILP (noforce))
     w->force_start = Qt;
   w->update_mode_line = Qt;
-  XFASTINT (w->last_modified) = 0;
+  XSETFASTINT (w->last_modified, 0);
   if (!EQ (window, selected_window))
     windows_or_buffers_changed++;
   return pos;
@@ -748,6 +759,7 @@ DEFUN ("delete-window", Fdelete_window, Sdelete_window, 0, 1, "",
   par = XWINDOW (parent);
 
   windows_or_buffers_changed++;
+  FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (p))) = 1;
 
   /* Are we trying to delete any frame's selected window?  */
   {
@@ -1285,21 +1297,51 @@ window_loop (type, obj, mini, frames)
          case DELETE_BUFFER_WINDOWS:
            if (EQ (XWINDOW (w)->buffer, obj))
              {
-               /* If we're deleting the buffer displayed in the only window
-                  on the frame, find a new buffer to display there.  */
-               if (NILP (XWINDOW (w)->parent))
+#ifdef MULTI_FRAME
+               FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (w)));
+
+               /* If this window is dedicated, and in a frame of its own,
+                  kill the frame.  */
+               if (EQ (w, FRAME_ROOT_WINDOW (f))
+                   && !NILP (XWINDOW (w)->dedicated)
+                   && other_visible_frames (f))
                  {
-                   Lisp_Object new_buffer;
-                   new_buffer = Fother_buffer (obj, Qnil);
-                   if (NILP (new_buffer))
-                     new_buffer
-                       = Fget_buffer_create (build_string ("*scratch*"));
-                   Fset_window_buffer (w, new_buffer);
-                   if (EQ (w, selected_window))
-                     Fset_buffer (XWINDOW (w)->buffer);
+                   /* Skip the other windows on this frame.
+                      There might be one, the minibuffer!  */
+                   if (! EQ (w, last_window))
+                     while (f == XFRAME (WINDOW_FRAME (XWINDOW (next_window))))
+                       {
+                         /* As we go, check for the end of the loop.
+                            We mustn't start going around a second time.  */
+                         if (EQ (next_window, last_window))
+                           {
+                             last_window = w;
+                             break;
+                           }
+                         next_window = Fnext_window (next_window,
+                                                     mini ? Qt : Qnil,
+                                                     frame_arg);
+                       }
+                   /* Now we can safely delete the frame.  */
+                   Fdelete_frame (WINDOW_FRAME (XWINDOW (w)), Qnil);
                  }
                else
-                 Fdelete_window (w);
+#endif
+                 /* If we're deleting the buffer displayed in the only window
+                    on the frame, find a new buffer to display there.  */
+                 if (NILP (XWINDOW (w)->parent))
+                   {
+                     Lisp_Object new_buffer;
+                     new_buffer = Fother_buffer (obj, Qnil);
+                     if (NILP (new_buffer))
+                       new_buffer
+                         = Fget_buffer_create (build_string ("*scratch*"));
+                     Fset_window_buffer (w, new_buffer);
+                     if (EQ (w, selected_window))
+                       Fset_buffer (XWINDOW (w)->buffer);
+                   }
+                 else
+                   Fdelete_window (w);
              }
            break;
 
@@ -1599,9 +1641,11 @@ set_window_height (window, height, nodelete)
       return;
     }
 
-  XFASTINT (w->last_modified) = 0;
+  XSETFASTINT (w->last_modified, 0);
   windows_or_buffers_changed++;
-  XFASTINT (w->height) = height;
+  FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w))) = 1;
+
+  XSETFASTINT (w->height, height);
   if (!NILP (w->hchild))
     {
       for (child = w->hchild; !NILP (child); child = XWINDOW (child)->next)
@@ -1620,7 +1664,7 @@ set_window_height (window, height, nodelete)
 
          opos = lastobot + XFASTINT (c->height);
 
-         XFASTINT (c->top) = lastbot;
+         XSETFASTINT (c->top, lastbot);
 
          pos = (((opos * height) << 1) + oheight) / (oheight << 1);
 
@@ -1660,9 +1704,11 @@ set_window_width (window, width, nodelete)
       return;
     }
 
-  XFASTINT (w->last_modified) = 0;
+  XSETFASTINT (w->last_modified, 0);
   windows_or_buffers_changed++;
-  XFASTINT (w->width) = width;
+  FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w))) = 1;
+
+  XSETFASTINT (w->width, width);
   if (!NILP (w->vchild))
     {
       for (child = w->vchild; !NILP (child); child = XWINDOW (child)->next)
@@ -1681,7 +1727,7 @@ set_window_width (window, width, nodelete)
 
          opos = lastoright + XFASTINT (c->width);
 
-         XFASTINT (c->left) = lastright;
+         XSETFASTINT (c->left, lastright);
 
          pos = (((opos * width) << 1) + owidth) / (owidth << 1);
 
@@ -1732,9 +1778,9 @@ BUFFER can be a buffer or buffer name.")
     }
 
   w->buffer = buffer;
-  XFASTINT (w->window_end_pos) = 0;
+  XSETFASTINT (w->window_end_pos, 0);
   w->window_end_valid = Qnil;
-  XFASTINT(w->hscroll) = 0;
+  XSETFASTINT(w->hscroll, 0);
   Fset_marker (w->pointm,
               make_number (BUF_PT (XBUFFER (buffer))),
               buffer);
@@ -1743,7 +1789,7 @@ BUFFER can be a buffer or buffer name.")
                         buffer);
   w->start_at_line_beg = Qnil;
   w->force_start = Qnil;
-  XFASTINT (w->last_modified) = 0;
+  XSETFASTINT (w->last_modified, 0);
   windows_or_buffers_changed++;
   if (EQ (window, selected_window))
     Fset_buffer (buffer);
@@ -1768,7 +1814,7 @@ before each command.")
   if (NILP (w->buffer))
     error ("Trying to select deleted window or non-leaf window");
 
-  XFASTINT (w->use_time) = ++window_select_count;
+  XSETFASTINT (w->use_time, ++window_select_count);
   if (EQ (window, selected_window))
     return window;
 
@@ -1813,7 +1859,7 @@ before each command.")
 }
 
 DEFUN ("display-buffer", Fdisplay_buffer, Sdisplay_buffer, 1, 2,
-       "BDisplay buffer: \nP",
+       "bDisplay buffer: \nP",
   "Make BUFFER appear in some window but don't select it.\n\
 BUFFER can be a buffer or a buffer name.\n\
 If BUFFER is shown already in some window, just use that one,\n\
@@ -1836,6 +1882,44 @@ Returns the window displaying BUFFER.")
       && XBUFFER (XWINDOW (selected_window)->buffer) == XBUFFER (buffer))
     return selected_window;
 
+  /* See if the user has specified this buffer should appear
+     in the selected window.  */
+  if (NILP (not_this_window))
+    {
+      tem = Fmember (XBUFFER (buffer)->name, Vsame_window_buffer_names);
+      if (!NILP (tem))
+       {
+         Fswitch_to_buffer (buffer, Qnil);
+         return selected_window;
+       }
+
+      tem = Fassoc (XBUFFER (buffer)->name, Vsame_window_buffer_names);
+      if (!NILP (tem))
+       {
+         Fswitch_to_buffer (buffer, Qnil);
+         return selected_window;
+       }
+
+      for (tem = Vsame_window_regexps; CONSP (tem); tem = XCONS (tem)->cdr)
+       {
+         Lisp_Object car = XCONS (tem)->car;
+         if (STRINGP (car)
+             && fast_string_match (car, XBUFFER (buffer)->name) >= 0)
+           {
+             Fswitch_to_buffer (buffer, Qnil);
+             return selected_window;
+           }
+         else if (CONSP (car)
+                  && STRINGP (XCONS (car)->car)
+                  && fast_string_match (XCONS (car)->car,
+                                        XBUFFER (buffer)->name) >= 0)
+           {
+             Fswitch_to_buffer (buffer, Qnil);
+             return selected_window;
+           }
+       }
+    }
+
 #ifdef MULTI_FRAME
   /* If pop_up_frames,
      look for a window showing BUFFER on any visible or iconified frame.  */
@@ -1933,17 +2017,23 @@ Returns the window displaying BUFFER.")
 #endif
        window = Fget_largest_window (frames);
 
-      /* If we got a tall enough full-width window, split it.  */
+      /* If we got a tall enough full-width window that can be split,
+        split it.  */
       if (!NILP (window)
+         && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window)->frame))
          && window_height (window) >= split_height_threshold
          && (XFASTINT (XWINDOW (window)->width)
              == FRAME_WIDTH (XFRAME (WINDOW_FRAME (XWINDOW (window))))))
        window = Fsplit_window (window, Qnil, Qnil);
       else
        {
+         Lisp_Object upper, lower, other;
+
          window = Fget_lru_window (frames);
-         /* If the LRU window is selected, and big enough, split it.  */
+         /* If the LRU window is selected, and big enough,
+            and can be split, split it.  */
          if (!NILP (window)
+             && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window)->frame))
              && (EQ (window, selected_window)
                  || EQ (XWINDOW (window)->parent, Qnil))
              && window_height (window) >= window_min_height << 1)
@@ -1967,6 +2057,25 @@ Returns the window displaying BUFFER.")
          if (NILP (window))
            window = Fframe_first_window (Fselected_frame ());
 #endif
+         /* If window appears above or below another,
+            even out their heights.  */
+         if (!NILP (XWINDOW (window)->prev))
+           other = upper = XWINDOW (window)->prev, lower = window;
+         if (!NILP (XWINDOW (window)->next))
+           other = lower = XWINDOW (window)->next, upper = window;
+         if (!NILP (other)
+             /* Check that OTHER and WINDOW are vertically arrayed.  */
+             && XWINDOW (other)->top != XWINDOW (window)->top
+             && XWINDOW (other)->height > XWINDOW (window)->height)
+           {
+             int total = XWINDOW (other)->height + XWINDOW (window)->height;
+             Lisp_Object old_selected_window;
+             old_selected_window = selected_window;
+
+             selected_window = upper;
+             change_window_height (total / 2 - XWINDOW (upper)->height, 0);
+             selected_window = old_selected_window;
+           }
        }
     }
   else
@@ -1985,7 +2094,7 @@ temp_output_buffer_show (buf)
   register struct window *w;
 
   Fset_buffer (buf);
-  XBUFFER (buf)->save_modified = MODIFF;
+  BUF_SAVE_MODIFF (XBUFFER (buf)) = MODIFF;
   BEGV = BEG;
   ZV = Z;
   SET_PT (BEG);
@@ -2004,27 +2113,33 @@ temp_output_buffer_show (buf)
 #endif /* MULTI_FRAME */
       Vminibuf_scroll_window = window;
       w = XWINDOW (window);
-      XFASTINT (w->hscroll) = 0;
+      XSETFASTINT (w->hscroll, 0);
       set_marker_restricted (w->start, make_number (1), buf);
       set_marker_restricted (w->pointm, make_number (1), buf);
     }
+
+  if (!NILP (Vrun_hooks))
+    call1 (Vrun_hooks, Qtemp_buffer_show_hook);
 }
 \f
 static
 make_dummy_parent (window)
      Lisp_Object window;
 {
-  register Lisp_Object old, new;
+  Lisp_Object new;
   register struct window *o, *p;
+  register struct Lisp_Vector *vec;
+  int i;
 
-  old = window;
-  XSETTYPE (old, Lisp_Vector);
-  new = Fcopy_sequence (old);
-  XSETTYPE (new, Lisp_Window);
+  o = XWINDOW (window);
+  vec = allocate_vectorlike ((EMACS_INT)VECSIZE (struct window));
+  for (i = 0; i < VECSIZE (struct window); ++i)
+    vec->contents[i] = ((struct Lisp_Vector *)o)->contents[i];
+  vec->size = VECSIZE (struct window);
+  p = (struct window *)vec;
+  XSETWINDOW (new, p);
 
-  o = XWINDOW (old);
-  p = XWINDOW (new);
-  XFASTINT (p->sequence_number) = ++sequence_number;
+  XSETFASTINT (p->sequence_number, ++sequence_number);
 
   /* Put new into window structure in place of window */
   replace_window (window, new);
@@ -2113,6 +2228,7 @@ and put SIZE columns in the first of the pair.")
      if we are making side-by-side windows */
 
   windows_or_buffers_changed++;
+  FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (o))) = 1;
   new = make_window ();
   p = XWINDOW (new);
 
@@ -2133,17 +2249,17 @@ and put SIZE columns in the first of the pair.")
     {
       p->height = o->height;
       p->top = o->top;
-      XFASTINT (p->width) = XFASTINT (o->width) - size;
-      XFASTINT (o->width) = size;
-      XFASTINT (p->left) = XFASTINT (o->left) + size;
+      XSETFASTINT (p->width, XFASTINT (o->width) - size);
+      XSETFASTINT (o->width, size);
+      XSETFASTINT (p->left, XFASTINT (o->left) + size);
     }
   else
     {
       p->left = o->left;
       p->width = o->width;
-      XFASTINT (p->height) = XFASTINT (o->height) - size;
-      XFASTINT (o->height) = size;
-      XFASTINT (p->top) = XFASTINT (o->top) + size;
+      XSETFASTINT (p->height, XFASTINT (o->height) - size);
+      XSETFASTINT (o->height, size);
+      XSETFASTINT (p->top, XFASTINT (o->top) + size);
     }
 
   return new;
@@ -2309,7 +2425,7 @@ change_window_height (delta, widthflag)
       (*setsizefun) (parent, opht, 0);
     }
 
-  XFASTINT (p->last_modified) = 0;
+  XSETFASTINT (p->last_modified, 0);
 }
 #undef MINSIZE
 #undef CURBEG
@@ -2381,13 +2497,13 @@ window_scroll (window, n, noerror)
   int lose;
   Lisp_Object bolp, nmoved;
 
-  XFASTINT (tem) = PT;
+  XSETFASTINT (tem, PT);
   tem = Fpos_visible_in_window_p (tem, window);
 
   if (NILP (tem))
     {
       Fvertical_motion (make_number (- (ht / 2)), window);
-      XFASTINT (tem) = PT;
+      XSETFASTINT (tem, PT);
       Fset_marker (w->start, tem, w->buffer);
       w->force_start = Qt;
     }
@@ -2412,7 +2528,7 @@ window_scroll (window, n, noerror)
       set_marker_restricted (w->start, make_number (pos), w->buffer);
       w->start_at_line_beg = bolp;
       w->update_mode_line = Qt;
-      XFASTINT (w->last_modified) = 0;
+      XSETFASTINT (w->last_modified, 0);
       if (pos > opoint)
        SET_PT (pos);
       if (n < 0)
@@ -2550,14 +2666,15 @@ showing that buffer, popping the buffer up if necessary.")
      register Lisp_Object n;
 {
   register Lisp_Object window;
-  register int ht;
+  register int defalt;
   register struct window *w;
   register int count = specpdl_ptr - specpdl;
 
   window = Fother_window_for_scrolling ();
 
   w = XWINDOW (window);
-  ht = window_internal_height (w);
+  defalt = window_internal_height (w) - next_screen_context_lines;
+  if (defalt < 1) defalt = 1;
 
   /* Don't screw up if window_scroll gets an error.  */
   record_unwind_protect (save_excursion_restore, save_excursion_save ());
@@ -2566,9 +2683,9 @@ showing that buffer, popping the buffer up if necessary.")
   SET_PT (marker_position (w->pointm));
 
   if (NILP (n))
-    window_scroll (window, ht - next_screen_context_lines, 1);
+    window_scroll (window, defalt, 1);
   else if (EQ (n, Qminus))
-    window_scroll (window, next_screen_context_lines - ht, 1);
+    window_scroll (window, -defalt, 1);
   else
     {
       if (CONSP (n))
@@ -2591,7 +2708,7 @@ Default for ARG is window width minus 2.")
 {
 
   if (NILP (arg))
-    XFASTINT (arg) = window_internal_width (XWINDOW (selected_window)) - 2;
+    XSETFASTINT (arg, window_internal_width (XWINDOW (selected_window)) - 2);
   else
     arg = Fprefix_numeric_value (arg);
 
@@ -2608,7 +2725,7 @@ Default for ARG is window width minus 2.")
      register Lisp_Object arg;
 {
   if (NILP (arg))
-    XFASTINT (arg) = window_internal_width (XWINDOW (selected_window)) - 2;
+    XSETFASTINT (arg, window_internal_width (XWINDOW (selected_window)) - 2);
   else
     arg = Fprefix_numeric_value (arg);
 
@@ -2637,11 +2754,11 @@ redraws with point in the center of the current window.")
       extern int frame_garbaged;
 
       SET_FRAME_GARBAGED (XFRAME (WINDOW_FRAME (w)));
-      XFASTINT (n) = ht / 2;
+      XSETFASTINT (n, ht / 2);
     }
   else if (CONSP (n)) /* Just C-u. */
     {
-      XFASTINT (n) = ht / 2;
+      XSETFASTINT (n, ht / 2);
     }
   else
     {
@@ -2680,7 +2797,7 @@ negative means relative to bottom of window.")
   Lisp_Object window;
 
   if (NILP (arg))
-    XFASTINT (arg) = height / 2;
+    XSETFASTINT (arg, height / 2);
   else
     {
       arg = Fprefix_numeric_value (arg);
@@ -2721,14 +2838,6 @@ struct save_window_data
     Lisp_Object saved_windows;
   };
 
-/* Arg to Fmake_vector */
-#define SAVE_WINDOW_DATA_SIZE                                          \
-  ((sizeof (struct save_window_data)                                   \
-    - (sizeof (struct Lisp_Vector)                                     \
-       /* Don't count the contents member of the struct Lisp_Vector */ \
-       - sizeof (Lisp_Object)))                                                \
-   / sizeof (Lisp_Object))
-
 /* This is saved as a Lisp_Vector */
 struct saved_window
   {
@@ -2815,6 +2924,7 @@ by `current-window-configuration' (which see).")
 #endif
 
       windows_or_buffers_changed++;
+      FRAME_WINDOW_SIZES_CHANGED (f) = 1;
 
       /* Temporarily avoid any problems with windows that are smaller
         than they are supposed to be.  */
@@ -2876,7 +2986,7 @@ by `current-window-configuration' (which see).")
          w->height = p->height;
          w->hscroll = p->hscroll;
          w->display_table = p->display_table;
-         XFASTINT (w->last_modified) = 0;
+         XSETFASTINT (w->last_modified, 0);
 
          /* Reinstall the saved buffer and pointers into it.  */
          if (NILP (p->buffer))
@@ -3036,7 +3146,7 @@ save_window_save (window, vector, i)
       p = SAVED_WINDOW_N (vector, i);
       w = XWINDOW (window);
 
-      XFASTINT (w->temslot) = i++;
+      XSETFASTINT (w->temslot, i++);
       p->window = window;
       p->buffer = w->buffer;
       p->left = w->left;
@@ -3108,6 +3218,7 @@ redirection (see `redirect-frame-focus').")
   register Lisp_Object tem;
   register int n_windows;
   register struct save_window_data *data;
+  register struct Lisp_Vector *vec;
   register int i;
   FRAME_PTR f;
 
@@ -3120,12 +3231,15 @@ redirection (see `redirect-frame-focus').")
     }
 
   n_windows = count_windows (XWINDOW (FRAME_ROOT_WINDOW (f)));
-  data = (struct save_window_data *)
-           XVECTOR (Fmake_vector (make_number (SAVE_WINDOW_DATA_SIZE),
-                                 Qnil));
-  XFASTINT (data->frame_width) = FRAME_WIDTH (f);
-  XFASTINT (data->frame_height) = FRAME_HEIGHT (f);
-  XFASTINT (data->frame_menu_bar_lines) = FRAME_MENU_BAR_LINES (f);
+  vec = allocate_vectorlike (VECSIZE (struct save_window_data));
+  for (i = 0; i < VECSIZE (struct save_window_data); i++)
+    vec->contents[i] = Qnil;
+  vec->size = VECSIZE (struct save_window_data);
+  data = (struct save_window_data *)vec;
+
+  XSETFASTINT (data->frame_width, FRAME_WIDTH (f));
+  XSETFASTINT (data->frame_height, FRAME_HEIGHT (f));
+  XSETFASTINT (data->frame_menu_bar_lines, FRAME_MENU_BAR_LINES (f));
 #ifdef MULTI_FRAME
   XSETFRAME (data->selected_frame, selected_frame);
 #endif
@@ -3177,6 +3291,8 @@ init_window_once ()
 #else /* not MULTI_FRAME */
   extern Lisp_Object get_minibuffer ();
 
+  selected_frame = last_nonminibuf_frame = &the_only_frame;
+
   minibuf_window = make_window ();
   FRAME_ROOT_WINDOW (selected_frame) = make_window ();
 
@@ -3188,12 +3304,12 @@ init_window_once ()
      just so that there is "something there."
      Correct values are put in in init_xdisp */
 
-  XFASTINT (XWINDOW (FRAME_ROOT_WINDOW (selected_frame))->width) = 10;
-  XFASTINT (XWINDOW (minibuf_window)->width) = 10;
+  XSETFASTINT (XWINDOW (FRAME_ROOT_WINDOW (selected_frame))->width, 10);
+  XSETFASTINT (XWINDOW (minibuf_window)->width, 10);
 
-  XFASTINT (XWINDOW (FRAME_ROOT_WINDOW (selected_frame))->height) = 9;
-  XFASTINT (XWINDOW (minibuf_window)->top) = 9;
-  XFASTINT (XWINDOW (minibuf_window)->height) = 1;
+  XSETFASTINT (XWINDOW (FRAME_ROOT_WINDOW (selected_frame))->height, 9);
+  XSETFASTINT (XWINDOW (minibuf_window)->top, 9);
+  XSETFASTINT (XWINDOW (minibuf_window)->height, 1);
 
   /* Prevent error in Fset_window_buffer.  */
   XWINDOW (FRAME_ROOT_WINDOW (selected_frame))->buffer = Qt;
@@ -3209,7 +3325,7 @@ init_window_once ()
      a newly-created, never-selected window.  Increment
      window_select_count so the first selection ever will get
      something newer than this.  */
-  XFASTINT (XWINDOW (selected_window)->use_time) = ++window_select_count;
+  XSETFASTINT (XWINDOW (selected_window)->use_time, ++window_select_count);
 #endif /* not MULTI_FRAME */
 }
 
@@ -3221,6 +3337,9 @@ syms_of_window ()
   Qwindow_live_p = intern ("window-live-p");
   staticpro (&Qwindow_live_p);
 
+  Qtemp_buffer_show_hook = intern ("Qtemp-buffer-show-hook");
+  staticpro (&Qtemp_buffer_show_hook);
+
 #ifndef MULTI_FRAME
   /* Make sure all windows get marked */
   staticpro (&minibuf_window);
@@ -3228,6 +3347,7 @@ syms_of_window ()
 
   DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function,
     "Non-nil means call as function to display a help buffer.\n\
+The function is called with one argument, the buffer to be displayed.\n\
 Used by `with-output-to-temp-buffer'.");
   Vtemp_buffer_show_function = Qnil;
 
@@ -3263,9 +3383,12 @@ where `pop-up-frame-alist' would hold the default frame parameters.");
     "*List of buffer names that should have their own special frames.\n\
 Displaying a buffer whose name is in this list makes a special frame for it\n\
 using `special-display-function'.\n\
-Instead of a buffer name, the list entries can be cons cells.  In that\n\
-case the car should be a buffer name, and the cdr data to be passed as a 
-second argument to `special-display-function'.\n\
+\n\
+An element of the list can be a cons cell instead of just a string.\n\
+Then the car should be a buffer name, and the cdr specifies frame\n\
+parameters for creating the frame for that buffer.\n\
+More precisely, the cdr is passed as the second argument to\n\
+the function found in `special-display-function', when making that frame.\n\
 See also `special-display-regexps'.");
   Vspecial_display_buffer_names = Qnil;
 
@@ -3274,9 +3397,12 @@ See also `special-display-regexps'.");
 If a buffer name matches one of these regexps, it gets its own frame.\n\
 Displaying a buffer whose name is in this list makes a special frame for it\n\
 using `special-display-function'.\n\
-Instead of a buffer name, the list entries can be cons cells.  In that\n\
-case the car should be the regexp, and the cdr data to be passed as a 
-second argument to `special-display-function'.\n\
+\n\
+An element of the list can be a cons cell instead of just a string.\n\
+Then the car should be the regexp, and the cdr specifies frame\n\
+parameters for creating the frame for buffers that match.\n\
+More precisely, the cdr is passed as the second argument to\n\
+the function found in `special-display-function', when making that frame.\n\
 See also `special-display-buffer-names'.");
   Vspecial_display_regexps = Qnil;
 
@@ -3291,6 +3417,34 @@ A buffer is special if its is listed in `special-display-buffer-names'\n\
 or matches a regexp in `special-display-regexps'.");
   Vspecial_display_function = Qnil;
 
+  DEFVAR_LISP ("same-window-buffer-names", &Vsame_window_buffer_names,
+    "*List of buffer names that should appear in the selected window.\n\
+Displaying one of these buffers using `display-buffer' or `pop-to-buffer'\n\
+switches to it in the selected window, rather than making it appear\n\
+in some other window.\n\
+\n\
+An element of the list can be a cons cell instead of just a string.\n\
+Then the car must be a string, which specifies the buffer name.\n\
+This is for compatibility with `special-display-buffer-names';\n\
+the cdr of the cons cell is ignored.\n\
+\n\
+See also `same-window-regexps'.");
+  Vsame_window_buffer_names = Qnil;
+
+  DEFVAR_LISP ("same-window-regexps", &Vsame_window_regexps,
+    "*List of regexps saying which buffers should appear in the selected window.\n\
+If a buffer name matches one of these regexps, then displaying it\n\
+using `display-buffer' or `pop-to-buffer' switches to it\n\
+in the selected window, rather than making it appear in some other window.\n\
+\n\
+An element of the list can be a cons cell instead of just a string.\n\
+Then the car must be a string, which specifies the buffer name.\n\
+This is for compatibility with `special-display-buffer-names';\n\
+the cdr of the cons cell is ignored.\n\
+\n\
+See also `same-window-buffer-names'.");
+  Vsame_window_regexps = Qnil;
+
   DEFVAR_BOOL ("pop-up-windows", &pop_up_windows,
     "*Non-nil means display-buffer should make new windows.");
   pop_up_windows = 1;