The unfortunate thing about the function window-configuration-to-register
is that it returns an opaque #<window-configuration>
data structure that is not easily serialized. Instead, one should use the function window-state-get
which will return a window configuration as an elisp data structure. Calling it with the following parameters will return a data structure that is amenable to being saved in an elisp source file.
(window-state-get (frame-root-window) t)
The return value of the above function can be passed to window-state-put
to restore the window configuration later. To make this more generally usable, I came up with the following interactive functions.
(defvar w/configs (make-hash-table :test #'equal)
"This is a hash-table where window configurations used by w/save and w/load are stored.")
(defun w/save (key)
"Save the current window configuration to w/configs."
(interactive "sName for window configuration: ")
(puthash key
(window-state-get (frame-root-window) t)
w/configs))
(defun w/load (key)
"Load a named window configuration from w/configs."
(interactive
(let* ((completion-ignore-case t)
(completions '())
(nothing (maphash (lambda (k v) (push k completions)) w/configs)))
(list (completing-read "Choose: " completions nil t))))
(window-state-put (gethash key w/configs)))
These two functions can be used to save and load window configurations into the hash-table w/configs
. If there are window configurations you use often, you can preload w/configs
with those settings. Binding these functions to keys is left as an exercise for the reader.
This solution doesn't use registers, but that's OK. It does solve the higher-level problem of saving and loading window configurations in elisp data structures. Whether the register system is used or a hash-table is used is an implementation detail.