elisp: Preserving Window Sizes

 
 27.5 Preserving Window Sizes
 ============================
 
 A window can get resized explicitly by using one of the functions from
 the preceding section or implicitly, for example, when resizing an
 adjacent window, when splitting or deleting a window (SeeSplitting
 Windows, SeeDeleting Windows) or when resizing the window’s frame
 (SeeSize and Position).
 
    It is possible to avoid implicit resizing of a specific window when
 there are one or more other resizable windows on the same frame.  For
 this purpose, Emacs must be advised to “preserve” the size of that
 window.  There are two basic ways to do that.
 
  -- Variable: window-size-fixed
      If this buffer-local variable is non-‘nil’, the size of any window
      displaying the buffer cannot normally be changed.  Deleting a
      window or changing the frame’s size may still change the window’s
      size, if there is no choice.
 
      If the value is ‘height’, then only the window’s height is fixed;
      if the value is ‘width’, then only the window’s width is fixed.
      Any other non-‘nil’ value fixes both the width and the height.
 
      If this variable is ‘nil’, this does not necessarily mean that any
      window showing the buffer can be resized in the desired direction.
      To determine that, use the function ‘window-resizable’.  See
      Resizing Windows.
 
    Often ‘window-size-fixed’ is overly aggressive because it inhibits
 any attempt to explicitly resize or split an affected window as well.
 This may even happen after the window has been resized implicitly, for
 example, when deleting an adjacent window or resizing the window’s
 frame.  The following function tries hard to never disallow resizing
 such a window explicitly:
 
  -- Function: window-preserve-size &optional window horizontal preserve
      This function (un-)marks the height of window WINDOW as preserved
      for future resize operations.  WINDOW must be a live window and
      defaults to the selected one.  If the optional argument HORIZONTAL
      is non-‘nil’, it (un-)marks the width of WINDOW as preserved.
 
      If the optional argument PRESERVE is ‘t’, this means to preserve
      the current height/width of WINDOW’s body.  The height/width of
      WINDOW will change only if Emacs has no better choice.  Resizing a
      window whose height/width is preserved by this function never
      throws an error.
 
      If PRESERVE is ‘nil’, this means to stop preserving the
      height/width of WINDOW, lifting any respective restraint induced by
      a previous call of this function for WINDOW.  Calling
      ‘enlarge-window’, ‘shrink-window’ or ‘fit-window-to-buffer’ with
      WINDOW as argument may also remove the respective restraint.
 
    ‘window-preserve-size’ is currently invoked by the following
 functions:
 
 ‘fit-window-to-buffer’
      If the optional argument PRESERVE-SIZE of that function (See
      Resizing Windows) is non-‘nil’, the size established by that
      function is preserved.
 
 ‘display-buffer’
      If the ALIST argument of that function (SeeChoosing Window)
      contains a ‘preserve-size’ entry, the size of the window produced
      by that function is preserved.
 
 Parameters::) called ‘preserved-size’ which is consulted by the window
 resizing functions.  This parameter will not prevent resizing the window
 when the window shows another buffer than the one when
 ‘window-preserve-size’ was invoked or if its size has changed since
 then.
 
    The following function can be used to check whether the height of a
 particular window is preserved:
 
  -- Function: window-preserved-size &optional window horizontal
      This function returns the preserved height of window WINDOW in
      pixels.  WINDOW must be a live window and defaults to the selected
      one.  If the optional argument HORIZONTAL is non-‘nil’, it returns
      the preserved width of WINDOW.  It returns ‘nil’ if the size of
      WINDOW is not preserved.