Conveniently save and restore frame configurations
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.
[...] blog entry Gonveniently save and restore frame configurations is related. Filed under: Emacs [...]
Open all marked buffers in Ibuffer « Tassilo’s Blog
January 19, 2007 at 9:49 pm
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
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
[...] I saved the layout and can quickly restore it. See my blog entry Conveniently save and restore frame configurations [...]
Deleting windows vertically or horizontally « Tassilo’s Blog
March 28, 2007 at 9:36 am
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