Working with Frames

By now you know that Emacs calls GUI windows "frames." In this section, we'll cover how to create frames, navigate between frames, and delete frames.

Creating a New Frame

To open a new frame, type C-x 5 2 (for make-frame). Emacs makes a new frame containing the current buffer and puts it on top of the current frame.

If your new frame completely overlaps your current frame, you may need to size the new frame to tell them apart. For a more convenient solution, add these lines to your .emacs file:

(setq initial-frame-alist '((top . 10) (left . 30)
                            (width . 90) (height . 50)))
(setq default-frame-alist '((width . 80) (height . 45)))

These lines set up sizes for the width and height of Emacs frames. The first frame is the size set in initial-frame-alist (in this example, 90 characters wide by 50 lines high with top and left defining an inset), and subsequent frames, specified by default-frame-alist, will be 80 characters wide and 45 lines high. Depending on your display, you can make these numbers smaller or larger.

Here we edit a bit of Henry James.

Type: C-x 5 2

image with no caption

Emacs opens a new frame titled james

Let's say we want to open a frame on our dickens buffer.

Type: C-x 5 f dickens Enter

image with no caption

Emacs opens a new frame on dickens.

If you type C-x b to move to another buffer, the name at the top of the frame changes to the new buffer's name (and on Linux, it shows the path as well). To move to a buffer and put it in a new frame, type C-x 5 b. You might have guessed that one.

Moving Between Frames

You can move between frames in several ways. You can use the mouse to select a frame or press C-x 5 o to go to another frame. To see a list of current frames, select Frames from the Buffers menu. (If you have only one frame, the Frames option does not appear on this menu.)

Deleting and Minimizing Frames

To get rid of a frame, press C-x 5 0. Emacs deletes the frame you are in. Deleting a frame, like deleting a window, affects only the display. The underlying buffer is still active, and you can move to it by typing C-x b.

If you try to use C-x 5 0 to delete the only frame that is left, Emacs won't do it. To exit Emacs, type C-x C-c or close the frame as you would any other GUI window using the mouse.

To minimize a frame, either minimize it in the usual way or press C-z. Table 4-1 summarizes the frame commands.

Table 4-1. Frame commands

Keystrokes

Command name

Action

C-x 5 o Buffers → Frames

other-frame

Move to other frame.

C-x 5 0 File → Delete Frame

delete-frame

Delete current frame.

C-x 5 2 File → New Frame

make-frame

Create a new frame on the current buffer.

C-x 5 f

find-file-other-frame

Find file in a new frame.

C-x 5 r

find-file-read-only-other-frame

Finds a file in a new frame, but it is read-only.

C-x 5 b

switch-to-buffer-other-frame

Make frame and display other buffer in it.

Get Learning GNU Emacs, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.