ErgoEmacsEmacsLispBlogEmacsLispBuy Tutorial
Web Hosting by 1&1

28.19 Window Configurations

A window configuration records the entire layout of one frame—all windows, their sizes, which buffers they contain, how those buffers are scrolled, and their values of point and the mark; also their fringes, margins, and scroll bar settings. It also includes the value of minibuffer-scroll-window. As a special exception, the window configuration does not record the value of point in the selected window for the current buffer. Also, the window configuration does not record the values of window parameters; see Window Parameters.

You can bring back an entire frame layout by restoring a previously saved window configuration. If you want to record the layout of all frames instead of just one, use a frame configuration instead of a window configuration; see Frame Configurations.

— Function: current-window-configuration &optional frame

This function returns a new object representing frame's current window configuration. The default for frame is the selected frame.

— Function: set-window-configuration configuration

This function restores the configuration of windows and buffers as specified by configuration, for the frame that configuration was created for.

The argument configuration must be a value that was previously returned by current-window-configuration. The configuration is restored in the frame from which configuration was made, whether that frame is selected or not. This always counts as a window size change and triggers execution of the window-size-change-functions (see Window Hooks), because set-window-configuration doesn't know how to tell whether the new configuration actually differs from the old one.

If the frame which configuration was saved from is dead, all this function does is restore the three variables window-min-height, window-min-width and minibuffer-scroll-window. In this case, the function returns nil. Otherwise, it returns t.

Here is a way of using this function to get the same effect as save-window-excursion:

          (let ((config (current-window-configuration)))
            (unwind-protect
                (progn (split-window-vertically nil)
                       ...)
              (set-window-configuration config)))
— Special Form: save-window-excursion forms…

This special form records the window configuration, executes forms in sequence, then restores the earlier window configuration. The window configuration includes, for each window, the value of point and the portion of the buffer that is visible. It also includes the choice of selected window. However, it does not include the value of point in the current buffer; use save-excursion also, if you wish to preserve that.

Don't use this construct when save-selected-window is sufficient.

Exit from save-window-excursion always triggers execution of window-size-change-functions. (It doesn't know how to tell whether the restored configuration actually differs from the one in effect at the end of the forms.)

The return value is the value of the final form in forms. For example:

          (split-window)
               ⇒ #<window 25 on control.texi>
          (setq w (selected-window))
               ⇒ #<window 19 on control.texi>
          (save-window-excursion
            (delete-other-windows w)
            (switch-to-buffer "foo")
            'do-something)
               ⇒ do-something
               ;; The screen is now split again.
— Function: window-configuration-p object

This function returns t if object is a window configuration.

— Function: compare-window-configurations config1 config2

This function compares two window configurations as regards the structure of windows, but ignores the values of point and mark and the saved scrolling positions—it can return t even if those aspects differ.

The function equal can also compare two window configurations; it regards configurations as unequal if they differ in any respect, even a saved point or mark.

— Function: window-configuration-frame config

This function returns the frame for which the window configuration config was made.

Other primitives to look inside of window configurations would make sense, but are not implemented because we did not need them. See the file winner.el for some more operations on windows configurations.

blog comments powered by Disqus