Emacs: Saving and restoring original frame layout (e.g. when working with ediff)
emacs
Solution
You can set up functions on the entrance/exit hooks for ediff to save/restore the window configuration, as well as create a new frame. This seemed to do the trick in Emacs 24.3 - I don't see why it wouldn't work in older versions:
(defvar pre-ediff-window-configuration nil
"window configuration to use")
(defvar new-ediff-frame-to-use nil
"new frame for ediff to use")
(defun save-my-window-configuration ()
(interactive)
(setq pre-ediff-window-configuration (current-window-configuration))
(select-frame-set-input-focus (setq new-ediff-frame-to-use (new-frame))))
(add-hook 'ediff-before-setup-hook 'save-my-window-configuration)
(defun restore-my-window-configuration ()
(interactive)
(when (framep new-ediff-frame-to-use)
(delete-frame new-ediff-frame-to-use)
(setq new-ediff-frame-to-use nil))
(when (window-configuration-p pre-ediff-window-configuration)
(set-window-configuration pre-ediff-window-configuration)))
(add-hook 'ediff-after-quit-hook-internal 'restore-my-window-configuration)
Problem
In a typical Emacs session I often have only one frame open, and I have it divided into 4 windows forming a 2x2 grid with some specific buffers (files) in each window. Every time I use `ediff-buffers` to compare two buffers, Emacs takes my existing frame, and re-splits it into two windows vertically (which I can choose to hortizontal by subsequentially pressing `-`). However, when I quit the `ediff` session, Emacs does not automatically restore the original layout of windows in my frame. With this my questions are: - Is there any way to automatically restore my original layout?' - Even better, how can I have `ediff-buffers` use a new separate frame just for the `ediff` session and close it automatically when I quit the `ediff` session?