]> code.delx.au - gnu-emacs/blobdiff - src/window.c
Add #pragma alloca.
[gnu-emacs] / src / window.c
index 7efff3c9dccdc87ffb9fb0501f6e98bf8f6eebc3..be1722ae3e4e67772687b9853fb249ae335d7ec9 100644 (file)
@@ -328,10 +328,10 @@ DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger,
        Sset_window_redisplay_end_trigger, 2, 2, 0,
   "Set WINDOW's redisplay end trigger value to VALUE.\n\
 VALUE should be a buffer position (typically a marker) or nil.\n\
-If it is a buffer position, then if redisplay in WINDOW\n\
-reaches a position beyond VALUE, the normal hook\n\
-`redisplay-end-trigger-hook' is run (and then the end-trigger value\n\
-is reset to nil.")
+If it is a buffer position, then if redisplay in WINDOW reaches a position\n\
+beyond VALUE, the functions in `redisplay-end-trigger-functions' are called\n\
+with two arguments: WINDOW, and the end trigger value.\n\
+Afterwards the end-trigger value is reset to nil.")
   (window, value)
      register Lisp_Object window, value;
 {
@@ -1911,6 +1911,21 @@ before each command.")
   return window;
 }
 
+/* Deiconify the frame containing the window WINDOW, then return WINDOW.  */
+
+static Lisp_Object
+display_buffer_1 (window)
+     Lisp_Object window;
+{
+#ifdef MULTI_FRAME
+  FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (window)));
+  FRAME_SAMPLE_VISIBILITY (f);
+  if (FRAME_ICONIFIED_P (f))
+    Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window)));
+#endif
+  return window;
+}
+
 DEFUN ("display-buffer", Fdisplay_buffer, Sdisplay_buffer, 1, 2,
        "bDisplay buffer: \nP",
   "Make BUFFER appear in some window but don't select it.\n\
@@ -1933,7 +1948,7 @@ Returns the window displaying BUFFER.")
 
   if (NILP (not_this_window)
       && XBUFFER (XWINDOW (selected_window)->buffer) == XBUFFER (buffer))
-    return selected_window;
+    return display_buffer_1 (selected_window);
 
   /* See if the user has specified this buffer should appear
      in the selected window.  */
@@ -1943,14 +1958,14 @@ Returns the window displaying BUFFER.")
       if (!NILP (tem))
        {
          Fswitch_to_buffer (buffer, Qnil);
-         return selected_window;
+         return display_buffer_1 (selected_window);
        }
 
       tem = Fassoc (XBUFFER (buffer)->name, Vsame_window_buffer_names);
       if (!NILP (tem))
        {
          Fswitch_to_buffer (buffer, Qnil);
-         return selected_window;
+         return display_buffer_1 (selected_window);
        }
 
       for (tem = Vsame_window_regexps; CONSP (tem); tem = XCONS (tem)->cdr)
@@ -1960,7 +1975,7 @@ Returns the window displaying BUFFER.")
              && fast_string_match (car, XBUFFER (buffer)->name) >= 0)
            {
              Fswitch_to_buffer (buffer, Qnil);
-             return selected_window;
+             return display_buffer_1 (selected_window);
            }
          else if (CONSP (car)
                   && STRINGP (XCONS (car)->car)
@@ -1968,7 +1983,7 @@ Returns the window displaying BUFFER.")
                                         XBUFFER (buffer)->name) >= 0)
            {
              Fswitch_to_buffer (buffer, Qnil);
-             return selected_window;
+             return display_buffer_1 (selected_window);
            }
        }
     }
@@ -1986,11 +2001,7 @@ Returns the window displaying BUFFER.")
   if (!NILP (window)
       && (NILP (not_this_window) || !EQ (window, selected_window)))
     {
-#ifdef MULTI_FRAME
-      if (FRAME_ICONIFIED_P (XFRAME (WINDOW_FRAME (XWINDOW (window)))))
-       Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window)));
-#endif
-      return window;
+      return display_buffer_1 (window);
     }
 
   /* Certain buffer names get special handling.  */
@@ -2027,7 +2038,7 @@ Returns the window displaying BUFFER.")
     {
       window = Fframe_selected_window (call0 (Vpop_up_frame_function));
       Fset_window_buffer (window, buffer);
-      return window;
+      return display_buffer_1 (window);
     }
 #endif /* MULTI_FRAME */
 
@@ -2139,7 +2150,7 @@ Returns the window displaying BUFFER.")
     window = Fget_lru_window (Qnil);
 
   Fset_window_buffer (window, buffer);
-  return window;
+  return display_buffer_1 (window);
 }
 
 void
@@ -2235,14 +2246,17 @@ make_dummy_parent (window)
 DEFUN ("split-window", Fsplit_window, Ssplit_window, 0, 3, "",
   "Split WINDOW, putting SIZE lines in the first of the pair.\n\
 WINDOW defaults to selected one and SIZE to half its size.\n\
-If optional third arg HOR-FLAG is non-nil, split side by side\n\
+If optional third arg HORFLAG is non-nil, split side by side\n\
 and put SIZE columns in the first of the pair.")
-  (window, chsize, horflag)
-     Lisp_Object window, chsize, horflag;
+  (window, size, horflag)
+     Lisp_Object window, size, horflag;
 {
   register Lisp_Object new;
   register struct window *o, *p;
-  register int size;
+  FRAME_PTR fo;
+  register int size_int;
+  int internal_width;
+  int separator_width = 1;
 
   if (NILP (window))
     window = selected_window;
@@ -2250,36 +2264,40 @@ and put SIZE columns in the first of the pair.")
     CHECK_LIVE_WINDOW (window, 0);
 
   o = XWINDOW (window);
+  fo = XFRAME (WINDOW_FRAME (o));
+  if (FRAME_HAS_VERTICAL_SCROLL_BARS (fo))
+    separator_width = FRAME_SCROLL_BAR_COLS (fo);
+  internal_width = window_internal_width (o);
 
-  if (NILP (chsize))
+  if (NILP (size))
     {
       if (!NILP (horflag))
-       /* Round odd size up, since this is for the left-hand window,
-          and it will lose a column for the separators.  */
-       size = ((XFASTINT (o->width) + 1) & -2) >> 1;
+       /* Calculate the size of the left-hand window, by dividing
+          the usable space in columns by two. */
+       size_int = (internal_width - separator_width) >> 1;
       else
-       size = XFASTINT (o->height) >> 1;
+       size_int = XFASTINT (o->height) >> 1;
     }
   else
     {
-      CHECK_NUMBER (chsize, 1);
-      size = XINT (chsize);
+      CHECK_NUMBER (size, 1);
+      size_int = XINT (size);
     }
 
   if (MINI_WINDOW_P (o))
     error ("Attempt to split minibuffer window");
-  else if (FRAME_NO_SPLIT_P (XFRAME (WINDOW_FRAME (o))))
+  else if (FRAME_NO_SPLIT_P (fo))
     error ("Attempt to split unsplittable frame");
 
   check_min_window_sizes ();
 
   if (NILP (horflag))
     {
-      if (size < window_min_height)
-       error ("Window height %d too small (after splitting)", size);
-      if (size + window_min_height > XFASTINT (o->height))
+      if (size_int < window_min_height)
+       error ("Window height %d too small (after splitting)", size_int);
+      if (size_int + window_min_height > XFASTINT (o->height))
        error ("Window height %d too small (after splitting)", 
-              XFASTINT (o->height) - size);
+              XFASTINT (o->height) - size_int);
       if (NILP (o->parent)
          || NILP (XWINDOW (o->parent)->vchild))
        {
@@ -2290,11 +2308,11 @@ and put SIZE columns in the first of the pair.")
     }
   else
     {
-      if (size < window_min_width)
-       error ("Window width %d too small (after splitting)", size);
-      if (size + window_min_width > XFASTINT (o->width))
+      if (size_int < window_min_width)
+       error ("Window width %d too small (after splitting)", size_int);
+      if (internal_width - size_int - separator_width < window_min_width)
        error ("Window width %d too small (after splitting)", 
-              XFASTINT (o->width) - size);
+              internal_width - size_int - separator_width);
       if (NILP (o->parent)
          || NILP (XWINDOW (o->parent)->hchild))
        {
@@ -2309,7 +2327,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;
+  FRAME_WINDOW_SIZES_CHANGED (fo) = 1;
   new = make_window ();
   p = XWINDOW (new);
 
@@ -2330,17 +2348,18 @@ and put SIZE columns in the first of the pair.")
     {
       p->height = o->height;
       p->top = o->top;
-      XSETFASTINT (p->width, XFASTINT (o->width) - size);
-      XSETFASTINT (o->width, size);
-      XSETFASTINT (p->left, XFASTINT (o->left) + size);
+      size_int += separator_width;
+      XSETFASTINT (p->width, internal_width - size_int);
+      XSETFASTINT (o->width, size_int);
+      XSETFASTINT (p->left, XFASTINT (o->left) + size_int);
     }
   else
     {
       p->left = o->left;
       p->width = o->width;
-      XSETFASTINT (p->height, XFASTINT (o->height) - size);
-      XSETFASTINT (o->height, size);
-      XSETFASTINT (p->top, XFASTINT (o->top) + size);
+      XSETFASTINT (p->height, XFASTINT (o->height) - size_int);
+      XSETFASTINT (o->height, size_int);
+      XSETFASTINT (p->top, XFASTINT (o->top) + size_int);
     }
 
   return new;