elisp: Quitting Windows

 
 27.18 Quitting Windows
 ======================
 
 When you want to get rid of a window used for displaying a buffer, you
 can call ‘delete-window’ or ‘delete-windows-on’ (SeeDeleting
 Windows) to remove that window from its frame.  If the buffer is shown
 on a separate frame, you might want to call ‘delete-frame’ (See
 Deleting Frames) instead.  If, on the other hand, a window has been
 reused for displaying the buffer, you might prefer showing the buffer
 previously shown in that window, by calling the function
 ‘switch-to-prev-buffer’ (SeeWindow History).  Finally, you might
DONTPRINTYET  want to either bury (SeeBuffer List) or kill (*noteKilling
DONTPRINTYET  want to either bury (SeeBuffer List) or kill (SeeKilling

 Buffers) the window’s buffer.
 
    The following command uses information on how the window for
 displaying the buffer was obtained in the first place, thus attempting
 to automate the above decisions for you.
 
  -- Command: quit-window &optional kill window
      This command quits WINDOW and buries its buffer.  The argument
      WINDOW must be a live window and defaults to the selected one.
      With prefix argument KILL non-‘nil’, it kills the buffer instead of
      burying it.  It calls the function ‘quit-restore-window’ described
      next to deal with the window and its buffer.
 
  -- Function: quit-restore-window &optional window bury-or-kill
      This function handles WINDOW and its buffer after quitting.  The
      optional argument WINDOW must be a live window and defaults to the
      selected one.  The function’s behavior is determined by the four
      elements of the ‘quit-restore’ window parameter (SeeWindow
      Parameters), which is set to nil afterwards.
 
      The window is deleted entirely if: 1) the first element of the
      ‘quit-restore’ parameter is one of ’window or ’frame, 2) the window
      has no history of previously-displayed buffers, and 3) the
      displayed buffer matches the one in the fourth element of the
      ‘quit-restore’ parameter.  If WINDOW is the only window on its
      frame and there are other frames on the frame’s terminal, the value
      of the optional argument BURY-OR-KILL determines how to proceed
      with the window.  If BURY-OR-KILL equals ‘kill’, the frame is
      deleted unconditionally.  Otherwise, the fate of the frame is
      determined by calling ‘frame-auto-hide-function’ (see below) with
      that frame as sole argument.
 
      If the third element of the ‘quit-restore’ parameter is a list of
      buffer, window start (SeeWindow Start and End), and point
      (SeeWindow Point), and that buffer is still live, the buffer
      will be displayed, and start and point set accordingly.  If, in
      addition, WINDOW’s buffer was temporarily resized, this function
      will also try to restore the original height of WINDOW.
 
      Otherwise, if WINDOW was previously used for displaying other
      buffers (SeeWindow History), the most recent buffer in that
      history will be displayed.
 
      The optional argument BURY-OR-KILL specifies how to deal with
      WINDOW’s buffer.  The following values are handled:
 
      ‘nil’
           This means to not deal with the buffer in any particular way.
           As a consequence, if WINDOW is not deleted, invoking
           ‘switch-to-prev-buffer’ will usually show the buffer again.
 
      ‘append’
           This means that if WINDOW is not deleted, its buffer is moved
           to the end of WINDOW’s list of previous buffers, so it’s less
           likely that a future invocation of ‘switch-to-prev-buffer’
           will switch to it.  Also, it moves the buffer to the end of
           the frame’s buffer list.
 
      ‘bury’
           This means that if WINDOW is not deleted, its buffer is
           removed from WINDOW’s list of previous buffers.  Also, it
           moves the buffer to the end of the frame’s buffer list.  This
           value provides the most reliable remedy to not have
           ‘switch-to-prev-buffer’ switch to this buffer again without
           killing the buffer.
 
      ‘kill’
           This means to kill WINDOW’s buffer.
 
      Typically, the display routines run by ‘display-buffer’ will set
      the ‘quit-restore’ window parameter correctly.  It’s also possible
      to set it manually, using the following code for displaying BUFFER
      in WINDOW:
 
           (display-buffer-record-window type window buffer)
 
           (set-window-buffer window buffer)
 
           (set-window-prev-buffers window nil)
 
      Setting the window history to nil ensures that a future call to
      ‘quit-window’ can delete the window altogether.
 
    The following option specifies how to deal with a frame containing
 just one window that should be either quit, or whose buffer should be
 buried.
 
  -- User Option: frame-auto-hide-function
      The function specified by this option is called to automatically
      hide frames.  This function is called with one argument—a frame.
 
      Buffer List::) when the selected window is dedicated and shows the
      buffer to bury.  It is also called by ‘quit-restore-window’ (see
      above) when the frame of the window to quit has been specially
      created for displaying that window’s buffer and the buffer is not
      killed.
 
      The default is to call ‘iconify-frame’ (SeeVisibility of
      Frames).  Alternatively, you may specify either ‘delete-frame’
      (SeeDeleting Frames) to remove the frame from its display,
      ‘ignore’ to leave the frame unchanged, or any other function that
      can take a frame as its sole argument.
 
      Note that the function specified by this option is called only if
      the specified frame contains just one live window and there is at
      least one other frame on the same terminal.