Remember Emacs window and frame customizations
In the fifth installment of this series (see Resources), you learned how to manipulate Emacs frames and split them into multiple windows, both horizontally and vertically. You can also save your window customizations and recall them later in your session, even after you've made many changes to the layout of the screen; you do this with Winner mode.
Winner mode is a minor mode that records and remembers your changes to windows and frames. Each time you change the window configuration, it's remembered; you can undo your change to revert to the last configuration. You can also redo your changes to go back to the way you had them. It's especially handy if you're trying an unusual or complex configuration, or if you tend to do different kinds of tasks involving different window setups.
Two functions work in Winner mode:
(which you type by pressing and holding Ctrl, pressing X, releasing both keys,
and then pressing the left arrow key) runs the
winner-undo function and undoes the last change to
the windows. Its counterpart is
C-x ->, which
winner-redo, returning the last change to the
windows that you previously undid.
To get started with Winner mode, set up a custom Emacs frame:
Exit Emacs (if it's currently running), and then restart it with no arguments:
C-x 2to split the Emacs window vertically, and then type
C-x o C-x C-f .emacs Enterto open your .emacs file in the lower window.
M-x winner-modeto turn on Winner mode.
When you do this, notice that
Win is added to the
mode listing given in parentheses on the mode lines of both visible buffers.
This means that Winner mode is on and that it works in all buffers. (It even
works in other Emacs frames, should you create them.)
Your Emacs session should now look like Figure 4. Notice that the Emacs frame no longer has a menu bar or toolbar—these were turned off in the .emacs file.
Figure 4. Winner mode enabled in an Emacs session
Now, make some new window configurations:
Use the mouse to click B1 in the top window so that it becomes the active window, and then type
C-x 3to split the window horizontally once.
Split the upper-left window vertically by typing
C-x 2, and then split the new, upper-left window horizontally again by typing
C-x b .emacs Enterto switch to the .emacs buffer in this new window.
Your Emacs frame should now look like Figure 5. Notice that Win appears in the mode line of every window in the frame.
Figure 5. Reconfigure an Emacs frame with Winner mode enabled
Now you can go back to your old configurations and cycle through them—type
C-x <- to undo your last window change.
C-x <- again to undo another change.
Keep going until the minibuffer reports that no further undoes are possible. At
this point, your Emacs frame should look like Figure 4,
which was how it looked when you first enabled Winner mode.
C-x -> to run the
winner-redo function and undo your last change. You
can cycle between
C-x <- and
C-x -> to move through all your window
winner-mode function is a toggle: Type
M-x winner-mode again to turn it off. When you do,
winner-undo functions no longer work, and window
changes aren't remembered—but once it's enabled again, you can undo and redo
any changes you've made to the windows.