Tassilo’s Blog

The personal blog of Tassilo Horn

Conveniently save and restore frame configurations

with 6 comments

In emacs you can split each frame in several windows. Such a configuration is called window configuration. The window configurations of all frames make a frame configuration. Here are some functions which let you save and restore such a frame configuration with only one key.
First we define a register which will be used by default for saving the frame configuration:

(defparameter th-frame-config-register ?°
  "The register which is used for storing and restoring frame
configurations by `th-save-frame-configuration' and
`th-jump-to-register'.")

The next thing is the saving function. If you call it with a prefix arg you can choose a different register:

(defun th-save-frame-configuration (arg)
  "Stores the current frame configuration in register
`th-frame-config-register'. If a prefix argument is given, you
can choose which register to use."
  (interactive "P")
  (let ((register (if arg
                      (read-char "Which register? ")
                    th-frame-config-register)))
    (frame-configuration-to-register register)
    (message "Frame configuration saved in register '%c'."
             register)))

Now we need a function to restore a frame configuration. By default it uses th-frame-config-register, but with a prefix arg you can choose any register. (You can use this function not only for restoring frame configs, but for everything you can do with jump-to-register…)

(defun th-jump-to-register (arg)
  "Jumps to register `th-frame-config-register'. If a prefix
argument is given, you can choose which register to jump to."
  (interactive "P")
  (let ((register (if arg
                      (read-char "Which register? ")
                    th-frame-config-register)))
    (jump-to-register register)
    (message "Jumped to register '%c'."
             register)))

Ok, the last thing we gotta do is create some key bindings. I chose F5 and F6:

(global-set-key (kbd "<F5>")
                'th-save-frame-configuration)
(global-set-key (kbd "<F6>")
                'th-jump-to-register)

Now whenever you have a complex window/frame config press F5 to save it and press F6 to restore it.

Written by Tassilo Horn

November 26, 2006 at 5:47 pm

Posted in Emacs

6 Responses

Subscribe to comments with RSS.

  1. [...] blog entry Gonveniently save and restore frame configurations is related. Filed under: Emacs [...]

  2. have you looked tried winner-mode ? [activate it with the usual M-x winner-mode]. it does what you have mentioned, but the difference being, that once it is active, you can go forwards/backwards in window-configuration history. i am not sure how “deep” the history buffer is though.

    Anupam

    January 30, 2007 at 5:37 pm

  3. Hi Anupam,

    yes, I know winner-mode, but I like my functions better, because most of the time I use a quite complex layout (gnus on the left and 3 or 4 irc buffers on the right).

    Bye,
    Tassilo

    Tassilo Horn

    February 5, 2007 at 9:26 pm

  4. [...] I saved the layout and can quickly restore it. See my blog entry Conveniently save and restore frame configurations [...]

  5. What’s wrong with C-x r w / C-x r j ?

    Zoran Rilak

    May 22, 2009 at 3:41 pm

    • Nothing’s wrong with them. It’s just that in most cases I use only one window/frame configuration, and in that case it’s one against four keys.

      Tassilo Horn

      May 22, 2009 at 6:23 pm


Leave a Reply