Move and manipulate Emacs frames
In X, an application running in an X client window of its own is normally called a window. But because Emacs has its own definition of the word window, as described in the previous section, Emacs uses another term for the whole Emacs X client window: It's called a frame.
Emacs supports multiple frames open from the same Emacs session. When you have
a buffer open in more than one frame, changes appear in the buffer across all
frames. Killing a frame doesn't affect other frames, but exiting a frame with
C-x C-c) saves buffers across all frames and exits
If you're in a console window, these commands still work, even though a console can display only one frame at a time. In the console, frames are differentiated by being given a frame number, which appears in the mode line preceded by an F character to distinguish each frame from any other.
C-x 5 2, makes a new frame and makes it active:
Exit Emacs by typing
C-x C-c, and then start it up with a single file (the new file you created):
$ emacs new.experience
C-x 5 2to make a new frame. (Where exactly it appears on your desktop depends on your window manager.) It, too, contains a copy of the new.experience buffer.
Edit a line: Type
C-u 381 C-n M-f M-f M-f M-t. The asterisks appear in the mode line for this buffer in both frames.
C-x 4 commands work on Emacs windows, the
C-x 5 commands work on Emacs frames. All of the
C-x 4 commands for making new windows as described in
the Split a window
vertically section have
C-x 5 equivalents: The
switch-to-buffer-other-frame function, for instance,
C-x 5 b.
C-x C-f experience Enterto open a copy of the experience file in a new buffer.
C-x 5 b experience Enterto open a copy of this buffer in a new frame.
find-file-other-frame function, which is bound to
C-x 5 f, prompts for a filename and opens that given
file in a new frame. Likewise,
find-file-read-only-other-frame, which is bound to
C-x 5 r, opens the given file as a read-only buffer
in a new frame.
Try finding a file and opening it in a new frame with a single step: Type
C-x 5 f innocence
Now your Emacs session should look like Figure 6, with four distinct X client windows.
Figure 6. Running multiple Emacs frames
C-x 5 o, to move between frames.
Like its Emacs window equivalent,
C-x o, this
function cycles between all the current Emacs frames, raising each frame
so it's in focus and above any other windows and selecting it as the current
Try cycling between the four frames you have open:
C-x 5 o C-x 5 o C-x 5 o C-x 5 o C-x 5 o.
If you use the X controls to kill a frame or the
C-x C-c command to exit Emacs, you exit all the
frames you've made. The X control to destroy a frame, however, destroys
just that particular frame; it doesn't kill any of the buffers open in that
frame, nor does it destroy other Emacs frames.
You can also delete frames from Emacs. To delete the current frame, use the
C-x 5 0. After deleting the current frame, it makes
the next frame the active and current frame. If you try running this on the only
frame in your session, Emacs beeps and reports an error. Try it now to delete
the frame you're in.
To delete all frames except the current frame, use the
C-x 5 1. All frames but the current frame, if they
exist, are deleted. Try it now to delete the remaining two frames so that you're
back to a single Emacs frame.
Note that these commands don't kill buffers—any buffers that were displayed in windows in deleted frames remain available in the current frame after the deletion.
In a console,
C-z normally suspends Emacs in the
background; in X, it runs the
iconify-or-deiconify-frame function. This iconifies
the current frame; but if the current frame is already iconified, it deiconifies
Try it: Type
C-z in the current frame you have open.
Depending on the version of X you're running and the window manager and desktop
software on your system, the Emacs window should iconify. Then, press
C-z again with the iconified frame in focus to
deiconify it and bring the frame back into focus.
Table 3 contains a list of common Emacs commands for manipulating frames, giving their function names and their default key bindings, if applicable, and describing their function.
Table 3. Common Emacs frame-manipulation commands
||Make a new Emacs frame, and make it the active frame.|
||Open a specified buffer in another frame. If no other frame exists, create a new frame.|
||Open a specified file in another frame. If no other frame exists, create a new frame.|
||Open a specified file in a read-only buffer in another frame. Create a new frame if no other frame exists.|
||Move to the next frame, and make it the active frame.|
||Delete the current frame, and make the next frame the active frame.|
||Delete all frames but the current frame.|
||Iconify the current frame. If the frame is already iconified, then deiconify it. (In a console, this binding suspends Emacs.)|